Пример #1
0
 public function testFactory()
 {
     $pattern1 = Cache\PatternFactory::factory('capture');
     $this->assertInstanceOf('Zend\\Cache\\Pattern\\CaptureCache', $pattern1);
     $pattern2 = Cache\PatternFactory::factory('capture');
     $this->assertInstanceOf('Zend\\Cache\\Pattern\\CaptureCache', $pattern2);
     $this->assertNotSame($pattern1, $pattern2);
 }
Пример #2
0
 public function __invoke($pageId = null, $pageExtension = null, array $options = array())
 {
     $this->setPageId($pageId);
     $config = $this->getConfig();
     if (!isset($config['cache']['page_capture'])) {
         return false;
     }
     $config = $config['cache']['page_capture'];
     if (!isset($config['enable']) || !$config['enable']) {
         return false;
     }
     if (!$pageExtension) {
         $pageExtension = isset($config['page_extension']) && $config['page_extension'] ? $config['page_extension'] : 'html';
     }
     if (!$options) {
         $options = isset($config['options']) && $config['options'] ? $config['options'] : array('public_dir' => EVA_PUBLIC_PATH . '/static/cache/');
     }
     if (!$pageId) {
         $request = $this->getController()->getEvent()->getRequest();
         $baseUrl = $request->getBaseUrl();
         $path = $request->getUri()->getPath();
         if ($baseUrl) {
             $path = substr($path, strlen($baseUrl));
         }
     }
     if (isset($config['adapter']) && $config['adapter'] == 'memcached') {
         if (!$pageId) {
             $pageId = $path;
             $this->setPageId($pageId);
         }
         //Note: get global MvcEvent must use getApplication
         $this->getController()->getEvent()->getApplication()->getEventManager()->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish'));
     } else {
         $capture = PatternFactory::factory('capture', $options);
         if ($pageId) {
             $pageId .= '.' . $pageExtension;
         } else {
             $pageId = $path . '.' . $pageExtension;
         }
         $capture->start($pageId);
     }
 }
Пример #3
0
 public function testChangeBroker()
 {
     $broker = new Cache\PatternBroker();
     Cache\PatternFactory::setBroker($broker);
     $this->assertSame($broker, Cache\PatternFactory::getBroker());
 }
Пример #4
0
<?php

require_once './autoloader.php';
$capture = \Zend\Cache\PatternFactory::factory('capture', array('public_dir' => __DIR__));
$pageId = 'test.html';
$capture->start($pageId);