/**
  *
  * @return \Zend\View\View
  */
 public function getView()
 {
     if ($this->view) {
         return $this->view;
     }
     $helperManager = $this->serviceLocator->get('ViewHelperManager');
     $resolver = $this->serviceLocator->get('ViewResolver');
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($helperManager);
     $renderer->setResolver($resolver);
     $rendererStrategy = new PhpRendererStrategy($renderer);
     $this->view = new View();
     $this->view->setEventManager($this->serviceLocator->get('EventManager'));
     $this->view->getEventManager()->attach($rendererStrategy);
     return $this->view;
 }
Example #2
0
 /**
  * @param  ContainerInterface $container
  * @param  string $name
  * @param  null|array $options
  * @return View
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     $view = new View();
     $events = $container->get('EventManager');
     $view->setEventManager($events);
     $container->get(PhpRendererStrategy::class)->attach($events);
     return $view;
 }
Example #3
0
 public function testOnRenderAttachesJsonStrategy()
 {
     $jsonLDJsonStrategy = $this->getMockBuilder('ZF\\JsonLD\\View\\HalJsonStrategy')->disableOriginalConstructor()->getMock();
     $view = new View();
     $eventManager = $this->getMock('Zend\\EventManager\\EventManager');
     $eventManager->expects($this->once())->method('attach')->with($jsonLDJsonStrategy, 200);
     $view->setEventManager($eventManager);
     $serviceManager = new ServiceManager();
     $serviceManager->setService('ZF\\JsonLD\\JsonStrategy', $jsonLDJsonStrategy)->setService('View', $view);
     $application = $this->getMock('Zend\\Mvc\\ApplicationInterface');
     $application->expects($this->once())->method('getServiceManager')->will($this->returnValue($serviceManager));
     $mvcEvent = $this->getMock('Zend\\Mvc\\MvcEvent');
     $mvcEvent->expects($this->at(0))->method('getResult')->will($this->returnValue(new JsonLDModel()));
     $mvcEvent->expects($this->at(1))->method('getTarget')->will($this->returnValue($application));
     $this->module->onRender($mvcEvent);
 }
Example #4
0
 public function testOnRenderAttachesJsonStrategy()
 {
     $strategy = new HalJsonStrategy(new HalJsonRenderer(new ApiProblemRenderer()));
     $view = new View();
     $eventManager = $this->getMockBuilder('Zend\\EventManager\\EventManager')->getMock();
     $eventManager->expects($this->exactly(2))->method('attach');
     $view->setEventManager($eventManager);
     $serviceManager = new ServiceManager();
     $serviceManager->setService('ZF\\Hal\\JsonStrategy', $strategy);
     $serviceManager->setService('View', $view);
     $application = $this->getMockBuilder('Zend\\Mvc\\ApplicationInterface')->getMock();
     $application->expects($this->once())->method('getServiceManager')->will($this->returnValue($serviceManager));
     $mvcEvent = $this->getMockBuilder('Zend\\Mvc\\MvcEvent')->getMock();
     $mvcEvent->expects($this->at(0))->method('getResult')->will($this->returnValue(new HalJsonModel()));
     $mvcEvent->expects($this->at(1))->method('getTarget')->will($this->returnValue($application));
     $this->module->onRender($mvcEvent);
 }
 /**
  * @param $name
  * @param $path
  * @return View
  */
 private function createView($name, $path)
 {
     $ar = new Resolver\AggregateResolver();
     $helper = $this->helpers;
     $map = new Resolver\TemplateMapResolver(array($name => $path));
     $ar->attach($map);
     foreach ($this->resolvers as $r) {
         $ar->attach($r);
     }
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($helper);
     $renderer->setResolver($ar);
     $strategy = new PhpRendererStrategy($renderer);
     $view = new View();
     $view->setEventManager(clone $this->events);
     $view->setResponse(new Response());
     $view->getEventManager()->attach($strategy);
     return $view;
 }