20 abstract protected static function _getFiles(&$config, $type, $silent=
false);
26 $parser->parse($classname);
27 return $parser->asArray();
28 }
catch ( \Exception $e ) {
35 $routes=[
"rest" => [ ],
"default" => [ ] ];
36 $files=self::getControllersFiles($config);
37 foreach ( $files as $file ) {
42 $parser->parse($controller);
43 $ret=$parser->asArray();
44 $key=($parser->isRest()) ?
"rest" :
"default";
45 $routes[$key]=\array_merge($routes[$key], $ret);
46 }
catch ( \Exception $e ) {
51 self::$cache->store(
"controllers/routes.default",
"return " .
UArray::asPhpArray($routes[
"default"],
"array") .
";",
'controllers');
52 self::$cache->store(
"controllers/routes.rest",
"return " .
UArray::asPhpArray($routes[
"rest"],
"array") .
";",
'controllers');
54 echo
"Router cache reset\n";
59 self::setKeyExpired($key,
false);
60 self::$cache->store(
"controllers/" . $key, $response,
'controllers',
false);
65 return "path" . \md5(\implode(
"", $routePath));
70 self::$expiredRoutes[$key]=
true;
72 unset(self::$expiredRoutes[$key]);
77 $key=($isRest) ?
"rest" :
"default";
78 if (self::$cache->exists(
"controllers/routes." . $key))
79 return self::$cache->fetch(
"controllers/routes." . $key);
84 $key=self::getRouteKey($routePath);
86 if (self::$cache->exists(
"controllers/" . $key) && !self::expired($key, $duration)) {
87 $response=self::$cache->file_get_contents(
"controllers/" . $key);
91 return self::storeRouteResponse($key, $response);
95 public static function expired($key, $duration) {
96 return self::$cache->expired(
"controllers/" . $key, $duration) ===
true || \array_key_exists($key, self::$expiredRoutes);
99 public static function isExpired($path, $duration) {
101 if ($route !==
false && \is_array($route)) {
102 return self::expired(self::getRouteKey($route), $duration);
107 public static function setExpired($routePath, $expired=
true) {
108 $key=self::getRouteKey($routePath);
109 self::setKeyExpired($key, $expired);
113 $key=self::getRouteKey($routePath);
115 return self::storeRouteResponse($key, $response);
119 self::addControllerCache(
"Ubiquity\controllers\Admin");
123 $result=self::getControllerCache();
129 $ctrlCache=self::getControllerCache($isRest);
130 foreach ( $ctrlCache as $path => $routeAttributes ) {
131 if (isset($routeAttributes[
"controller"])) {
132 if ($routeAttributes[
"controller"] === $controllerClass) {
133 $result[$path]=$routeAttributes;
136 $firstValue=reset($routeAttributes);
137 if (isset($firstValue) && isset($firstValue[
"controller"])) {
138 if ($firstValue[
"controller"] === $controllerClass) {
139 $result[$path]=$routeAttributes;
147 public static function addRoute($path, $controller, $action=
"index", $methods=null, $name=
"") {
148 $controllerCache=self::getControllerCache();
150 self::$cache->store(
"controllers/routes",
"return " .
UArray::asPhpArray($controllerCache,
"array") .
";",
'controllers');
154 return self::_getFiles($config,
"controllers", $silent);
157 public static function getControllers($subClass=
"\\Ubiquity\\controllers\\Controller",$backslash=
false,$includeSubclass=
false) {
159 if($includeSubclass){
163 $files=self::getControllersFiles($config,
true);
166 }
catch ( \Exception $e ) {
169 foreach ( $files as $file ) {
170 if (is_file($file)) {
172 if (isset($restCtrls[$controllerClass]) ===
false) {
173 $r=new \ReflectionClass($controllerClass);
174 if($r->isSubclassOf($subClass) && !$r->isAbstract()){
175 $result[]=$controllerClass;
static initRouterCache(&$config, $silent=false)
static storeRouteResponse($key, $response)
static runAsString($u, $initialize=true, $finalize=true)
static expired($key, $duration)
static setExpired($routePath, $expired=true)
static getRouteKey($routePath)
static addRouteToRoutes(&$routesArray, $path, $controller, $action="index", $methods=null, $name="", $cache=false, $duration=null, $requirements=[])
static setKeyExpired($key, $expired=true)
static addControllerCache($classname)
static getRoute($path, $cachedResponse=true)
static getControllers($subClass="\biquity\ontrollers\ontroller", $backslash=false, $includeSubclass=false)
static setRouteCache($routePath)
static addRoute($path, $controller, $action="index", $methods=null, $name="")
static getRouteCache($routePath, $duration)
static getControllersFiles(&$config, $silent=false)
static isExpired($path, $duration)
static getControllerCache($isRest=false)
static getControllerRoutes($controllerClass, $isRest=false)
static _getFiles(&$config, $type, $silent=false)
static asPhpArray($array, $prefix="", $depth=1, $format=false)
static getClassFullNameFromFile($filePathName, $backSlash=false)
get the full name (name \ namespace) of a class from its file path result example: (string) "I\Am\The...