Ejemplo n.º 1
0
 /**
  * @param         $object
  * @param         $item
  * @param  array  $arguments
  * @param  string $type
  * @param  bool   $isDefinedTest
  *
  * @return mixed
  */
 protected function getAttribute($object, $item, array $arguments = array(), $type = \Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false)
 {
     $attribute = parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest);
     if (self::$recorder && is_object($object)) {
         self::$recorder->add($object);
     }
     return $attribute;
 }
Ejemplo n.º 2
0
 /**
  * @param Request $request
  *
  * @return mixed
  */
 public function cacheAction(Request $request)
 {
     $parameters = array_merge($request->query->all(), $request->attributes->all());
     if ($request->get('_token') != $this->computeHash($parameters)) {
         throw new AccessDeniedHttpException('Invalid token');
     }
     $manager = $this->getManager($request);
     $page = $manager->getPageById($request->get('page_id'));
     if (!$page) {
         throw new NotFoundHttpException(sprintf('Page not found : %s', $request->get('page_id')));
     }
     $block = $manager->getBlock($request->get('block_id'));
     $blockContext = $this->contextManager->get($block);
     if ($this->recorder) {
         $this->recorder->add($blockContext->getBlock());
         $this->recorder->push();
     }
     $response = $this->blockRenderer->render($blockContext);
     if ($this->recorder) {
         $keys = $this->recorder->pop();
         $keys['page_id'] = $page->getId();
         $keys['block_id'] = $block->getId();
         foreach ($keys as $key => $value) {
             $response->headers->set($this->normalize($key), $value);
         }
     }
     $response->headers->set('x-sonata-page-not-decorable', true);
     return $response;
 }
Ejemplo n.º 3
0
 public function testRecorder()
 {
     $collection = new ModelCollectionIdentifiers(array('Sonata\\Cache\\Tests\\Invalidation\\Recorder_Model_1' => 'getCacheIdentifier'));
     $m1 = new Recorder_Model_1();
     $m2 = new Recorder_Model_2();
     $m3 = new Recorder_Model_3();
     $recorder = new Recorder($collection);
     $recorder->push();
     $recorder->add($m1);
     $recorder->push();
     $recorder->add($m1);
     $recorder->add($m2);
     $recorder->add($m2);
     $innerKeys = $recorder->pop();
     $recorder->add($m3);
     $keys = $recorder->pop();
     $this->assertArrayHasKey('Sonata\\Cache\\Tests\\Invalidation\\Recorder_Model_1', $innerKeys);
     $this->assertArrayHasKey('Sonata\\Cache\\Tests\\Invalidation\\Recorder_Model_2', $innerKeys);
     $this->assertArrayHasKey('Sonata\\Cache\\Tests\\Invalidation\\Recorder_Model_1', $keys);
     $this->assertArrayHasKey('Sonata\\Cache\\Tests\\Invalidation\\Recorder_Model_3', $keys);
 }