Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
CacheManager.php
Go to the documentation of this file.
1<?php
2
6namespace Ubiquity\cache;
7
14
18
29
34 public static $cache;
35
36 private static $cacheDirectory;
37
43 public static function startProd(array &$config): void {
44 self::$cacheDirectory = self::initialGetCacheDirectory($config);
46 self::getCacheInstance($config, $cacheDirectory, '.cache');
47 }
48
52 public static function startProdFromCtrl(): void {
53 $config = &Startup::$config;
54 $cacheD = \ROOT . \DS . ($config['cache']['directory'] ??= 'cache' . \DS);
55 $cacheSystem = $config['cache']['system'] ?? 'Ubiquity\\cache\\system\\ArrayCache';
56 self::$cache = new $cacheSystem($cacheD, '.cache', $config['cache']['params'] ?? []);
57 }
58
59 protected static function getCacheInstance(array &$config, string $cacheDirectory, string $postfix):AbstractDataCache {
60 if (! isset(self::$cache)) {
61 $cacheSystem = $config['cache']['system'] ?? 'Ubiquity\\cache\\system\\ArrayCache';
62 $cacheParams = $config['cache']['params'] ?? [];
63
64 self::$cache = new $cacheSystem($cacheDirectory, $postfix, $cacheParams);
65 }
66 return self::$cache;
67 }
68
69
75 public static function getCacheDirectory(): string {
76 return self::$cacheDirectory;
77 }
78
84 public static function getAbsoluteCacheDirectory(): string {
85 return \ROOT . \DS . self::$cacheDirectory;
86 }
87
94 public static function getCacheSubDirectory(string $subDirectory): string {
95 return \ROOT . \DS . self::$cacheDirectory . \DS . $subDirectory;
96 }
97
98
104 public static function getAllRoutes(): array {
105 $routes = self::getControllerCache();
106 return \array_merge($routes, self::getControllerCache(true));
107 }
108
118 protected static function _getFiles(array &$config, string $type, bool $silent = false,?string $domain=null): array {
119 if($domain==null){
120 $domainBase=Startup::getActiveDomainBase();
121 }else{
122 $domainBase=DDDManager::getDomainBase($domain);
123 }
124 $typeNS = $domainBase.($config['mvcNS'][$type])??$type;
125 $typeDir = \ROOT . \DS . \str_replace("\\", \DS, $typeNS);
126 if (! $silent) {
127 echo \ucfirst($type) . ' directory is ' . \realpath($typeDir) . "\n";
128 }
129 return UFileSystem::glob_recursive($typeDir . \DS . '*.php');
130 }
131
140 protected static function _getAllFiles(array &$config, string $type, bool $silent = false): array {
141 $domains=DDDManager::getDomains();
142 $result=[];
143 foreach ($domains as $domain){
144 $result=\array_merge($result,self::_getFiles($config,$type,$silent,$domain));
145 }
146 $result=\array_merge($result, self::_getFiles($config,$type,$silent,''));
147 return $result;
148 }
149}
Manager for caches (Router, Rest, models).
static getCacheInstance(array &$config, string $cacheDirectory, string $postfix)
static _getFiles(array &$config, string $type, bool $silent=false,?string $domain=null)
Returns an array of files from type $type.
static startProdFromCtrl()
Starts the cache from a controller.
static getCacheSubDirectory(string $subDirectory)
Returns an absolute cache subdirectory.
static startProd(array &$config)
Starts the cache for production.
static _getAllFiles(array &$config, string $type, bool $silent=false)
Returns an array of all files from type $type.
static getAllRoutes()
Returns an array of all defined routes, included REST routes.
static getCacheDirectory()
Returns the relative cache directory.
static getAbsoluteCacheDirectory()
Returns the absolute cache directory.
This class is responsible for storing Arrays in PHP files.
static initialGetCacheDirectory(array &$config)
Ubiquity\cache\traits$DevRouterCacheTrait This class is part of Ubiquity.
Ubiquity\cache\traits$ModelsCacheTrait This class is part of Ubiquity.
Starts the framework.
Definition Startup.php:19
Manager for a Domain Driven Design approach.
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
Cache managment.
Definition CacheFile.php:3