injectInterceptor() public method

public injectInterceptor ( Phalcon\Mvc\DispatcherInterface $dispatcher ) : boolean
$dispatcher Phalcon\Mvc\DispatcherInterface
return boolean true if cache missed(intercepter injected), false if cache hit(intercepter not injected)
示例#1
0
 public function testJsonpCacheHit()
 {
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb&callback=testcallback&_=123456';
     $_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb', 'callback' => 'testcallback', '_' => '123456');
     $request = new Request();
     $this->di->set('request', $request);
     $this->di->getViewCache()->flush();
     $this->di->getViewCache()->save('d6bd338ec8eb8666f3d054566f335039_b', '{"foo":"bar"}');
     $this->di->getViewCache()->save('d6bd338ec8eb8666f3d054566f335039_h', '{"Content-Type":"application\\/json;+charset=utf-8","X-EvaEngine-Interceptor-Cache":"2014-12-09T06:45:42+0100"}');
     $interceptor = new DispatchInterceptor();
     /**
      * @var Dispatcher $dispatcher
     */
     $dispatcher = $this->di->getDispatcher();
     $dispatcher->setParams(array('_dispatch_cache' => 'lifetime=100&format=jsonp'));
     $this->assertEquals(false, $interceptor->injectInterceptor($dispatcher));
     $this->assertEquals('testcallback({"foo":"bar"})', $this->di->getResponse()->getContent());
 }
示例#2
0
 public function testTextCacheHitWithCorsEnabled()
 {
     $this->di->getViewCache()->save('d6bd338ec8eb8666f3d054566f335039_h', '{"foo":"header"}');
     $this->di->getViewCache()->save('d6bd338ec8eb8666f3d054566f335039_b', 'bar');
     $_SERVER['HTTP_ORIGIN'] = 'https://api.bar.com';
     $interceptor = new DispatchInterceptor();
     /**
      * @var Dispatcher $dispatcher
      */
     $dispatcher = $this->di->getDispatcher();
     $dispatcher->setParams(array('_dispatch_cache' => 'lifetime=100&cors_enabled=true'));
     /*
      * Cors enabled when function injectInterceptor was called.
      * So before calling function injectInterceptor, there will be no Access-Control-Allow-Origin header.
      */
     $this->assertEquals(false, $this->di->getResponse()->getHeaders()->get('Access-Control-Allow-Origin'));
     $this->assertEquals(false, $interceptor->injectInterceptor($dispatcher));
     $this->assertEquals('bar', $this->di->getResponse()->getContent());
     $this->assertEquals($_SERVER['HTTP_ORIGIN'], $this->di->getResponse()->getHeaders()->get('Access-Control-Allow-Origin'));
 }