validate() public méthode

validate the cache
Since: 3.0.0
public validate ( mixed $bundle = null, integer $lifetime = 3600 ) : boolean
$bundle mixed key or collection of the bundle
$lifetime integer lifetime of the bundle
Résultat boolean
Exemple #1
0
 /**
  * renderTemplate
  *
  * @since 3.0.0
  *
  * @return mixed
  */
 public static function renderTemplate()
 {
     $registry = Registry::getInstance();
     $request = Request::getInstance();
     $language = Language::getInstance();
     /* handle notification */
     if (!is_dir(self::$_configArray['directory']) && !mkdir(self::$_configArray['directory'])) {
         self::setNotification('error', $language->get('directory_not_found') . $language->get('colon') . ' ' . self::$_configArray['directory'] . $language->get('point'));
     }
     /* prevent as needed */
     if ($request->getPost() || $registry->get('noCache')) {
         return false;
     }
     /* cache as needed */
     $cache = new Cache();
     $cache->init(self::$_configArray['directory'], self::$_configArray['extension']);
     $fullRoute = $registry->get('fullRoute');
     /* load from cache */
     if ($cache->validate($fullRoute, self::$_configArray['lifetime'])) {
         $raw = $cache->retrieve($fullRoute);
         $content = preg_replace('/' . self::$_configArray['tokenPlaceholder'] . '/', $registry->get('token'), self::_uncompress($raw));
         return ['header' => function_exists('gzdeflate') ? 'content-encoding: deflate' : null, 'content' => self::_compress($content)];
     } else {
         $raw = Template\Tag::partial('templates/' . $registry->get('template') . '/index.phtml');
         $content = preg_replace('/' . $registry->get('token') . '/', self::$_configArray['tokenPlaceholder'], $raw);
         $cache->store($fullRoute, self::_compress($content));
         return ['content' => $raw];
     }
 }
Exemple #2
0
 /**
  * concat the collection
  *
  * @since 3.0.0
  *
  * @param array $optionArray
  * @param array $rewriteArray
  *
  * @return Loader
  */
 public function concat($optionArray = [], $rewriteArray = [])
 {
     $bundleArray = [];
     $restArray = [];
     /* prevent as needed */
     if ($this->_registry->get('noCache')) {
         return $this;
     }
     /* process collection */
     foreach ($this->_collectionArray as $collectionKey => $attributeArray) {
         $path = $attributeArray[$optionArray['attribute']];
         $fileArray = pathinfo($path);
         if (is_file($path) && $fileArray['extension'] === $optionArray['extension']) {
             $bundleArray[] = $attributeArray[$optionArray['attribute']];
         } else {
             $restArray[] = $attributeArray;
         }
     }
     /* cache as needed */
     $cache = new Cache();
     $cache->init($optionArray['directory'], $optionArray['extension']);
     /* load from cache */
     if ($cache->validate($bundleArray, $optionArray['lifetime'])) {
         $this->_collectionArray = $restArray;
         $this->_collectionArray['bundle'] = [$optionArray['attribute'] => $cache->getPath($bundleArray)];
         if ($optionArray['extension'] === 'css') {
             $this->_collectionArray['bundle']['rel'] = 'stylesheet';
         }
     } else {
         $content = $this->_getContent($bundleArray, $rewriteArray);
         $cache->store($bundleArray, $content);
     }
     return $this;
 }
Exemple #3
0
 /**
  * testValidate
  *
  * @since 3.0.0
  */
 public function testValidate()
 {
     /* setup */
     $cache = new Cache();
     $cache->init(Stream::url('root'), 'cache')->store('test1', 'test')->store('test2', 'test');
     touch($cache->getPath('test2'), time() - 3600);
     /* compare */
     $this->assertTrue($cache->validate('test1'));
     $this->assertFalse($cache->validate('test2'));
     $this->assertFalse($cache->validate('invalid'));
 }