/** * */ private function loadDefinitions() { // Get the cache $cacheCode = 'routes_' . \z\boot()->environment; $cache = \z\cache()->getCache($cacheCode); if ($cache !== false) { $this->_definitions = unserialize($cache); return; } // $dependencies = \z\boot()->dependencies; // foreach ($dependencies as $dependency) { // Find definitions $paths = \z\service('helper/file')->listFiles($dependency . '/Config/Routes', 'json', true); // For each definitions foreach ($paths as $path) { // Load definitions $rawDefinitions = file_get_contents($path); $definitions = json_decode($rawDefinitions, true); // Make sure definitions is an array if (is_array($definitions) === false) { continue; } // For each definition foreach ($definitions as &$definition) { // Make sure the definition is valid $definition = array_merge(['arguments' => [], 'verbs' => [], 'post' => [], 'pre' => []], $definition); // For each verb foreach ($definition['verbs'] as &$verb) { // Make sure the verb is valid $verb = array_merge(['action' => 'index', 'controller' => null], $verb); } } // Store definitions $this->_definitions = array_merge($this->_definitions, $definitions); } } // Set the cache \z\cache()->setCache($cacheCode, serialize($this->_definitions)); }
/** * */ private function loadPreferences() { // Get the cache $cacheCode = 'preferences_' . \z\boot()->environment; $cache = \z\cache()->getCache($cacheCode); if ($cache !== false) { $this->_preferences = unserialize($cache); return; } // Define the number of passes $dependencies = \z\boot()->dependencies; $nbPasses = count($dependencies) - 1; // Perform n passes for ($i = 0; $i < $nbPasses; $i++) { foreach ($dependencies as $dependency) { // List preferences $paths = array_merge(\z\service('helper/file')->listFiles($dependency . '/Config/Preferences', 'json'), \z\service('helper/file')->listFiles($dependency . '/Config/Preferences/' . \z\boot()->environment, 'json')); // Parse each path foreach ($paths as $path) { // Build the preference code $parentPreferenceCode = strtolower(basename($path, '.json')); // Load preferences $preferences = \z\service('factory/json')->loadJson($path); // Store preferences foreach ($preferences as $preferenceCode => $preferenceValue) { // Build the new preference code $preferenceCode = $parentPreferenceCode . '/' . $preferenceCode; // Get the previous preference value $oldPreferenceValue = \z\pref($preferenceCode); // Is it an array? if (is_array($oldPreferenceValue) === true) { // Merge the old + the new $preferenceValue = array_merge($oldPreferenceValue, $preferenceValue); } // Set the preference \z\pref($preferenceCode, $preferenceValue); } } } // End of pass, remove the first extension array_shift($dependencies); } // Set the cache \z\cache()->setCache($cacheCode, serialize($this->_preferences)); }
/** * */ public function actionCacheClear() { \z\cache()->clearCache(); }
/** * */ private function loadConfig() { // Get the cache $cacheCode = 'events_' . \z\boot()->environment; $cache = \z\cache()->getCache($cacheCode); if ($cache !== false) { $this->_followers = unserialize($cache); return; } // Parse each dependency $dependencies = \z\boot()->dependencies; foreach ($dependencies as $dependency) { // $paths = \z\service('helper/file')->listFiles($dependency . '/Config/Events', 'php'); foreach ($paths as $path) { require_once $path; } } // Set the cache \z\cache()->setCache($cacheCode, serialize($this->_followers)); }
/** * */ private function loadStrings() { // Get the cache $cacheCode = 'strings_' . $this->_localeCode . '_' . $this->_fallbackCode; $cache = \z\cache()->getCache($cacheCode); if ($cache !== false) { $this->_strings = unserialize($cache); return; } // Build locales $locales = [$this->_localeCode, $this->_fallbackCode]; // Parse each locale foreach ($locales as $localeCode) { // Build an array for the locale $this->_strings[$localeCode] = []; // List string files for this locale $paths = \z\service('helper/file')->listFiles(PATH_APP . '/Config/Strings/' . $localeCode, 'json'); // Parse each string file foreach ($paths as $path) { // Load the string file $rawStrings = file_get_contents($path); $strings = json_decode($rawStrings, true); // Store the strings $this->_strings[$localeCode] = array_merge($this->_strings[$localeCode], $strings); } } // Set the cache \z\cache()->setCache($cacheCode, serialize($this->_strings)); }
/** * */ private function loadDefinitions() { // Get the cache $cacheCode = 'services_' . \z\boot()->environment; $cache = \z\cache()->getCache($cacheCode); if ($cache !== false) { $this->_definitions = unserialize($cache); return; } // $dependencies = \z\boot()->dependencies; // foreach ($dependencies as $dependency) { // Find services $fileHelper = new \fbenard\Zero\Services\Helpers\FileHelper(); $paths = $fileHelper->listFiles($dependency . '/Config/Services', 'json'); // For each service foreach ($paths as $path) { // Load definitions $rawDefinitions = file_get_contents($path); $definitions = json_decode($rawDefinitions, true); // Register services $this->registerServices($definitions); } } // Set the cache \z\cache()->setCache($cacheCode, serialize($this->_definitions)); }