Ubiquity  2.0.0
php rapid development framework
RestCacheTrait.php
Go to the documentation of this file.
1 <?php
2 namespace Ubiquity\cache\traits;
3 
8 
15 
16  private static function initRestCache(&$config,$silent=false) {
17  $restCache=[];
18  $files=self::getControllersFiles($config);
19  foreach ( $files as $file ) {
20  if (is_file($file)) {
21  $controller=ClassUtils::getClassFullNameFromFile($file);
22  $parser=new RestControllerParser();
23  $parser->parse($controller,$config);
24  if($parser->isRest())
25  $restCache=\array_merge($restCache,$parser->asArray());
26  }
27  }
28  self::$cache->store("controllers/rest", "return " . UArray::asPhpArray($restCache, "array") . ";",'controllers');
29  if(!$silent){
30  echo "Rest cache reset\n";
31  }
32  }
33 
34  public static function getRestRoutes() {
35  $result=[];
36  $restCache=self::getRestCache();
37  foreach ($restCache as $controllerClass=>$restAttributes){
38  if(isset($restCache[$controllerClass])){
39  $result[$controllerClass]=["restAttributes"=>$restAttributes,"routes"=>self::getControllerRoutes($controllerClass,true)];
40  }
41  }
42  return $result;
43  }
44 
45  public static function getRestCache() {
46  if (self::$cache->exists("controllers/rest"))
47  return self::$cache->fetch("controllers/rest");
48  throw new RestException("Rest cache entry `".self::$cache->getEntryKey("controllers/rest")."` is missing.\nTry to Re-init Rest cache.");
49  }
50 
51  public static function getRestResource($controllerClass){
52  $cacheControllerClass=self::getRestCacheController($controllerClass);
53  if(isset($cacheControllerClass))
54  return $cacheControllerClass["resource"];
55  return null;
56  }
57 
58  public static function getRestCacheController($controllerClass){
59  $cache=self::getRestCache();
60  if(isset($cache[$controllerClass])){
61  return $cache[$controllerClass];
62  }
63  return null;
64  }
65 }
static getClassFullNameFromFile($filePathName)
get the full name (name \ namespace) of a class from its file path result example: (string) "I\Am\The...
Definition: ClassUtils.php:15
static getRestResource($controllerClass)
Exceptions for Rest service.
static asPhpArray($array, $prefix="")
Definition: UArray.php:27
static getRestCacheController($controllerClass)
static initRestCache(&$config, $silent=false)