/** * Gets the thread for a given id. * * @param string $id * * @return View */ public function getAction($id) { $website = $this->getDoctrine()->getRepository('AppBundle:Websites')->find($id); if (null === $website) { throw new NotFoundHttpException(sprintf("Thread with id '%s' could not be found.", $id)); } $view = new View($website); $view->setTemplate('admin2/layout.html.twig'); return $this->handleView($view); }
/** * @Observe(event="kernel.view", priority=110) * {@inheritdoc} */ public function onKernelView(GetResponseForControllerResultEvent $event) { $request = $event->getRequest(); $request->getSession()->save(); if (!$request->attributes->has('_view')) { $configuration = new View([]); $configuration->setSerializerEnableMaxDepthChecks(true); $request->attributes->set('_view', $configuration); } }
/** * @dataProvider getDataForDefaultVarsCopy */ public function testViewWithNoCopyDefaultVars($createAnnotation, $populateDefaultVars, $shouldCopy) { $this->createViewResponseListener(['html' => true]); $request = new Request(); $request->attributes->set('_template_default_vars', ['customer']); $request->attributes->set('customer', 'A person goes here'); $view = View::create(); if ($createAnnotation) { $viewAnnotation = new ViewAnnotation([]); $viewAnnotation->setPopulateDefaultVars($populateDefaultVars); $request->attributes->set('_view', $viewAnnotation); } $event = $this->getResponseEvent($request, $view); $this->listener->onKernelView($event); $data = $view->getData(); if ($shouldCopy) { $this->assertArrayHasKey('customer', $data); $this->assertEquals('A person goes here', $data['customer']); } else { $this->assertNull($data); } }
/** * @dataProvider getDataForDefaultVarsCopy */ public function testViewWithNoCopyDefaultVars($createAnnotation, $populateDefaultVars, $shouldCopy) { $request = new Request(); $request->attributes->set('_template_default_vars', ['customer']); $request->attributes->set('customer', 'A person goes here'); $view = View::create(); if ($createAnnotation) { $viewAnnotation = new ViewAnnotation([]); $viewAnnotation->setPopulateDefaultVars($populateDefaultVars); $request->attributes->set('_view', $viewAnnotation); } $event = $this->getResponseEvent($request, $view); $this->viewHandler = new ViewHandler(['html' => true]); $this->viewHandler->setContainer($this->container); // This is why we avoid container dependencies! $that = $this; $this->container->expects($this->exactly(2))->method('get')->with($this->logicalOr('fos_rest.view_handler', 'fos_rest.templating'))->will($this->returnCallback(function ($service) use($that) { return $service === 'fos_rest.view_handler' ? $that->viewHandler : $that->templating; })); $this->listener->onKernelView($event); $data = $view->getData(); if ($shouldCopy) { $this->assertArrayHasKey('customer', $data); $this->assertEquals('A person goes here', $data['customer']); } else { $this->assertNull($data); } }
/** * View constructor. */ public function __construct(array $values = array()) { parent::__construct($values); }