コード例 #1
0
 public function testOptions()
 {
     $options = new VarnishOptions();
     $options->setCacheEnabled(true);
     $this->assertTrue($options->isCacheEnabled());
     $options->setCacheableRoutes(['test/route' => 60]);
     $this->assertEquals(['test/route' => 60], $options->getCacheableRoutes());
     $options->setPolicy(VarnishOptions::POLICY_ALLOW);
     $this->assertEquals(VarnishOptions::POLICY_ALLOW, $options->getPolicy());
     $options->setDebug(true);
     $this->assertTrue($options->getDebug());
     $options->setDefaultTtl(3600);
     $this->assertEquals(3600, $options->getDefaultTtl());
     $options->setServers(['server1' => ['host' => '127.0.0.1']]);
     $this->assertEquals(['server1' => ['host' => '127.0.0.1']], $options->getServers());
 }
コード例 #2
0
 /**
  *
  * @param EventInterface $e
  */
 public function injectEsi(EventInterface $e)
 {
     if (!$this->canUseEsi()) {
         return;
     }
     /* @var $block ViewModel */
     $block = $e->getParam('block');
     if ($options = $block->getOption('esi')) {
         $block->setTemplate(self::ESI_TEMPLATE);
         $block->setVariable('__HANDLES__', $this->getHandles($block));
         if ($this->varnishOptions->getDebug()) {
             $block->setVariables(['__DEBUG__' => true, '__TTL__' => isset($options['ttl']) ? $options['ttl'] : 'n/a', '__TAGS__' => $block->getOption('cache_tags', [])]);
         }
         $this->injectEsiHeader();
     }
 }