/** * Test for specific cache functionality in requests */ public function testCacheForRequests() { $session = Security::getInstance(); $session->setSessionKey('__CACHE__', ['cache' => 1, 'http' => 'localhost/', 'slug' => 'test']); $hash = Cache::getInstance()->getRequestCacheHash(); $this->assertNotNull($hash, 'Invalid cache hash'); $this->assertEquals($hash, sha1('localhost/ test'), 'Different hash returned by cache'); $this->assertTrue(false !== Cache::needCache(), 'Test url expired or error checking cache'); }
/** * Create translation file if not exists * * @param string $absoluteTranslationFileName * * @return array */ public static function generateTranslationsFile($absoluteTranslationFileName) { $translations = array(); if (file_exists($absoluteTranslationFileName)) { @(include $absoluteTranslationFileName); } else { Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); } return $translations; }
/** * Método que genera las urls amigables para usar dentro del framework * @return Router */ public function simpatize() { $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; $this->generateSlugs($absoluteTranslationFileName); Config::createDir(CONFIG_DIR); Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); return $this; }
/** * Método que inyecta automáticamente las dependencias en la clase */ public function init() { if (!$this->isLoaded()) { $cacheFilename = "reflections" . DIRECTORY_SEPARATOR . sha1(get_class($this)) . ".json"; /** @var \PSFS\base\Cache $cacheService */ $cacheService = Cache::getInstance(); /** @var \PSFS\base\config\Config $configService */ $configService = Config::getInstance(); $properties = $cacheService->getDataFromFile($cacheFilename, Cache::JSON); if (true === $configService->getDebugMode() || null === $properties) { $properties = InjectorHelper::getClassProperties(get_class($this)); $cacheService->storeData($cacheFilename, $properties, Cache::JSON); } /** @var \ReflectionProperty $property */ if (!empty($properties) && is_array($properties)) { foreach ($properties as $property => $class) { $this->load($property, true, $class); } } $this->setLoaded(); } else { Logger::log(get_class($this) . ' already loaded', LOG_INFO); } }
/** * Method that reloads config file */ public function loadConfigData() { $this->config = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "config.json", Cache::JSON, TRUE) ?: []; $this->debug = array_key_exists('debug', $this->config) ? (bool) $this->config['debug'] : FALSE; }
/** * Método que inicializa el motor de plantillas */ private function setup() { $this->debug = Config::getInstance()->getDebugMode() ?: FALSE; $this->cache = Cache::getInstance(); $loader = new \Twig_Loader_Filesystem(Config::getInstance()->getTemplatePath()); $this->tpl = new \Twig_Environment($loader, array('cache' => Config::getInstance()->getCachePath() . DIRECTORY_SEPARATOR . 'twig', 'debug' => (bool) $this->debug, 'auto_reload' => TRUE)); }