Ejemplo n.º 1
0
 /**
  * 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');
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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);
     }
 }
Ejemplo n.º 5
0
Archivo: Config.php Proyecto: psfs/Core
 /**
  * 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;
 }
Ejemplo n.º 6
0
 /**
  * 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));
 }