/**
  * Listener for the Response call
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  * @return void
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     // Only for Sub Requests
     $subRequest = $event->getRequest();
     if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     // Check if Configuration is present
     if (!($configuration = $subRequest->attributes->get('_acilia_component_fragment_cache', false))) {
         return;
     }
     // If Key is present, save content for that key, expiration retreived in minutes
     if (($key = $subRequest->attributes->get('_acilia_component_fragment_cache_key', false)) !== false) {
         if ($this->enabled) {
             $this->cache->set($key, $event->getResponse()->getContent(), $configuration->getExpiration());
             $fragment = '';
             if ($this->debug) {
                 $fragment .= '<!-- MISS - Begin Fragment Cache for KEY: ' . $key . ' -->';
             }
             $fragment .= $event->getResponse()->getContent();
             if ($this->debug) {
                 $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
             }
             $event->getResponse()->setContent($fragment);
         } elseif (!$this->enabled) {
             $fragment = '';
             if ($this->debug) {
                 $fragment .= '<!-- DISABLED - Begin Fragment Cache for KEY: ' . $key . ' -->';
             }
             $fragment .= $event->getResponse()->getContent();
             if ($this->debug) {
                 $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
             }
             $event->getResponse()->setContent($fragment);
         }
     }
     return;
 }
Beispiel #2
0
 public function getType($slug)
 {
     $key = 'Banner:Types';
     if (!is_array($this->types)) {
         $types = $this->memcache->get($key);
         if ($this->memcache->notFound()) {
             $bannerTypes = $this->doctrine->getManager()->getRepository('AciliaBannerBundle:BannerType')->findAll();
             $types = array();
             foreach ($bannerTypes as $bannerType) {
                 $types[$bannerType->getSlug()] = $bannerType->getId();
             }
             $this->memcache->set($key, $types, 1440);
         }
         $this->types = $types;
     }
     if (isset($this->types[$slug])) {
         return $this->types[$slug];
     } elseif (isset($this->types['none'])) {
         return $this->types['none'];
     } else {
         return 0;
     }
 }