Gc\Mvc\Listener\CacheListener::onFinish PHP Method

onFinish() public method

Save page contents to the cache
public onFinish ( MvcEvent $e ) : void
$e Zend\Mvc\MvcEvent Mvc Event
return void
    public function onFinish(MvcEvent $e)
    {
        if ($this->cacheIsActive($e) === false) {
            return;
        }
        if (!$e->getRequest() instanceof HttpRequest || $this->loadedFromCache) {
            return;
        }
        $serviceManager = $e->getApplication()->getServiceManager();
        $serviceManager->get('CacheService')->save($e);
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testOnFinishWithCache()
 {
     $config = Mockery::mock('Gc\\Core\\Config');
     $config->shouldReceive('getValue')->with('cache_is_active')->once()->andReturn(true);
     $identity = Mockery::mock('Zend\\Authentication\\AuthenticationService');
     $identity->shouldReceive('hasIdentity')->andReturn(false);
     $cacheService = Mockery::mock('Gc\\Mvc\\Service\\CacheService');
     $cacheService->shouldReceive('save')->once()->andReturn();
     $serviceLocator = Mockery::mock('Zend\\Mvc\\MvcEvent');
     $serviceLocator->shouldReceive('get')->once()->with('CoreConfig')->andReturn($config);
     $serviceLocator->shouldReceive('get')->once()->with('Auth')->andReturn($identity);
     $serviceLocator->shouldReceive('get')->once()->with('CacheService')->andReturn($cacheService);
     $application = Mockery::Mock('Zend\\Mvc\\Application');
     $application->shouldReceive('getServiceManager')->once()->andReturn($serviceLocator);
     $event = Mockery::mock('Zend\\Mvc\\MvcEvent');
     $event->shouldReceive('getApplication')->once()->andReturn($application);
     $event->shouldReceive('getRequest')->once()->andReturn(Mockery::mock('Zend\\Http\\PhpEnvironment\\Request'));
     $this->object->onFinish($event);
 }