7use Ubiquity\config\Configuration;
26 abstract protected static function initRestCache(array &$config,
bool $silent =
false): void;
28 abstract protected static function initRouterCache(array &$config,
bool $silent =
false): void;
30 abstract public static function initModelsCache(array &$config,
bool $forChecking =
false,
bool $silent =
false): void;
33 if (\class_exists(
'Ubiquity\\attributes\\AttributesEngine', true)) {
34 return new \Ubiquity\attributes\AttributesEngine();
35 } elseif (\class_exists(
'Ubiquity\\annotations\\AnnotationsEngine',
true)) {
36 return new \Ubiquity\annotations\AnnotationsEngine();
41 return self::$annotationsEngine ??= self::_getAnnotationsEngineInstance();
45 return $config[
'cache'][
'directory'] ??=
'cache' . \DS;
54 public static function start(array &$config) {
55 self::$cacheDirectory = self::initialGetCacheDirectory($config);
56 $cacheDirectory = \ROOT . \DS . self::$cacheDirectory;
57 self::getAnnotationsEngineInstance()->start($cacheDirectory);
58 self::getCacheInstance($config, $cacheDirectory,
'.cache')->init();
67 self::getAnnotationsEngineInstance()->registerAnnotations($nameClasses);
78 public static function checkCache(array &$config,
bool $silent =
false): array {
79 $dirs = self::getCacheDirectories($config, $silent);
80 foreach ($dirs as $dir) {
81 self::safeMkdir($dir);
94 $cacheDirectory = self::initialGetCacheDirectory($config);
95 $rootDS = \ROOT . \DS;
97 echo
"cache directory is " . UFileSystem::cleanPathname($rootDS . $cacheDirectory) .
"\n";
99 $cacheDirectory = $rootDS . $cacheDirectory . \DS;
100 $modelsDir = \str_replace(
"\\", \DS, $config[
'mvcNS'][
'models']);
101 $controllersDir = \str_replace(
"\\", \DS, $config[
'mvcNS'][
'controllers']);
102 $annotationCacheDir = $cacheDirectory .
'annotations';
103 $modelsCacheDir = $cacheDirectory . $modelsDir;
104 $queriesCacheDir = $cacheDirectory .
'queries';
105 $controllersCacheDir = $cacheDirectory . $controllersDir;
106 $viewsCacheDir = $cacheDirectory .
'views';
107 $seoCacheDir = $cacheDirectory .
'seo';
108 $gitCacheDir = $cacheDirectory .
'git';
109 $contentsCacheDir = $cacheDirectory .
'contents';
110 $configCacheDir = $cacheDirectory .
'config';
112 'annotations' => $annotationCacheDir,
113 'models' => $modelsCacheDir,
114 'controllers' => $controllersCacheDir,
115 'queries' => $queriesCacheDir,
116 'views' => $viewsCacheDir,
117 'seo' => $seoCacheDir,
118 'git' => $gitCacheDir,
119 'contents' => $contentsCacheDir,
120 'config' => $configCacheDir
125 if (!\is_dir($dir)) {
126 return \mkdir($dir, 0777,
true);
137 public static function clearCache(array &$config,
string $type =
'all') {
138 $cacheDirectories = self::checkCache($config);
148 foreach ($cacheDirs as $typeRef) {
149 self::_clearCache($cacheDirectories, $type, $typeRef);
153 private static function _clearCache($cacheDirectories, $type, $typeRef) {
154 if ($type ===
'all' || $type === $typeRef) {
155 UFileSystem::deleteAllFilesFromFolder($cacheDirectories[$typeRef]);
165 public static function initCache(array &$config,
string $type =
'all',
bool $silent =
false): void {
166 self::checkCache($config, $silent);
167 self::start($config);
168 if ($type ===
'all' || $type ===
'models') {
169 self::initModelsCache($config,
false, $silent);
171 if ($type ===
'all' || $type ===
'controllers') {
172 if (\class_exists(
'\\Ubiquity\\security\\acl\\AclManager')) {
173 self::getAnnotationsEngineInstance()->registerAcls();
175 self::initRouterCache($config, $silent);
177 if ($type ===
'all' || $type ===
'acls') {
178 if (\class_exists(
'\\Ubiquity\\security\\acl\\AclManager')) {
179 \Ubiquity\security\acl\AclManager::initCache($config);
182 if ($type ===
'all' || $type ===
'rest') {
183 self::initRestCache($config, $silent);
185 if ($type ===
'all' || $type ===
'config') {
186 Configuration::generateCache($silent);
This class is responsible for storing Arrays in PHP files.
static getCacheInstance(array &$config, string $cacheDirectory, string $postfix)
static AnnotationsEngineInterface $annotationsEngine
static initRouterCache(array &$config, bool $silent=false)
static registerAnnotations(array $nameClasses)
static initRestCache(array &$config, bool $silent=false)
static getCacheDirectories(array &$config, bool $silent=false)
Returns an associative array of cache folders (annotations, models, controllers, queries,...
static getAnnotationsEngineInstance()
static initCache(array &$config, string $type='all', bool $silent=false)
static checkCache(array &$config, bool $silent=false)
Checks the existence of cache subdirectories and returns an array of cache folders.
static start(array &$config)
Starts the cache in dev mode, for generating the other caches Do not use in production.
static initialGetCacheDirectory(array &$config)
static clearCache(array &$config, string $type='all')
Deletes files from a cache type.
static initModelsCache(array &$config, bool $forChecking=false, bool $silent=false)
static safeMkdir(string $dir)
static _clearCache($cacheDirectories, $type, $typeRef)
static _getAnnotationsEngineInstance()
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
Ubiquity\annotations$AnnotationsInterface This class is part of Ubiquity.