![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/laminas/laminas-mvc/src/View/Http/ |
<?php namespace Laminas\Mvc\View\Http; use Exception; use Throwable; use Laminas\EventManager\AbstractListenerAggregate; use Laminas\EventManager\EventManagerInterface; use Laminas\Mvc\Application; use Laminas\Mvc\MvcEvent; use Laminas\Stdlib\ResponseInterface as Response; use Laminas\View\Model\ModelInterface as ViewModel; use Laminas\View\View; class DefaultRenderingStrategy extends AbstractListenerAggregate { /** * Layout template - template used in root ViewModel of MVC event. * * @var string */ protected $layoutTemplate = 'layout'; /** * Set view * * @return DefaultRenderingStrategy */ public function __construct(protected View $view) { } /** * {@inheritDoc} */ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, [$this, 'render'], -10000); $this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, [$this, 'render'], -10000); } /** * Set layout template value * * @param string $layoutTemplate * @return DefaultRenderingStrategy */ public function setLayoutTemplate($layoutTemplate) { $this->layoutTemplate = (string) $layoutTemplate; return $this; } /** * Get layout template value * * @return string */ public function getLayoutTemplate() { return $this->layoutTemplate; } /** * Render the view * * @return Response|null * @throws Exception|Throwable */ public function render(MvcEvent $e) { $result = $e->getResult(); if ($result instanceof Response) { return $result; } // Martial arguments $request = $e->getRequest(); $response = $e->getResponse(); $viewModel = $e->getViewModel(); if (! $viewModel instanceof ViewModel) { return; } $view = $this->view; $view->setRequest($request); $view->setResponse($response); $caughtException = null; try { $view->render($viewModel); } catch (Throwable $ex) { $caughtException = $ex; } catch (Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced $caughtException = $ex; } if ($caughtException !== null) { if ($e->getName() === MvcEvent::EVENT_RENDER_ERROR) { throw $caughtException; } $application = $e->getApplication(); $events = $application->getEventManager(); $e->setError(Application::ERROR_EXCEPTION); $e->setParam('exception', $caughtException); $e->setName(MvcEvent::EVENT_RENDER_ERROR); $events->triggerEvent($e); } return $response; } }