Detect if we should use the FeedRenderer based on model type and/or
Accept header

@param  ViewEvent $e

@return null|WorkflowDescriptorApiRenderer
427598
public function selectRenderer(ViewEvent $e)
    {
        $model = $e->getModel();

        if (!($model instanceof WorkflowDescriptorApiModel || $model instanceof HalEntity)) {
            return null;
        }

        $this->renderer->setViewEvent($e);

        return $this->renderer;
    }
319235
function onRenderRenderWidgets(ViewEvent $e)
    {
        $viewModel = $e->getModel();

        $return = false;

        $options = $viewModel->getOptions();
        if (/*!array_key_exists('has_parent', $options) &&*/ !self::$resolved) {
            $return = new PhpRenderer;
            $return->setServiceLocator($this->sm);

             //self::$resolved = true;
        }

        return $return;
    }
269148
public function restPost(JobEvent $e)
    {
        $response = new JobResponse($this->name, JobResponse::RESPONSE_NOTIMPLEMENTED);
        $serviceManager = $this->serviceManager;
        if ($serviceManager->has('Jobs/RestClient')) {
            try {
                $log = $serviceManager->get('Core/Log');
                $restClient = $serviceManager->get('Jobs/RestClient');
                $provider = $serviceManager->get('Jobs/Options/Provider');

                $entity = $e->getJobEntity();

                $render = $serviceManager->get('ViewPhpRendererStrategy')->getRenderer();
                $viewModel = $serviceManager->get('Jobs/ViewModelTemplateFilter')->getModel($entity);
                $html = $render->render($viewModel);
                $absUrlFilter = $serviceManager->get('filterManager')->get('Core/HtmlAbsPathFilter');
                $html = $absUrlFilter->filter($html);

                $host = $restClient->getHost();
                if (!isset($host)) {
                    throw new \RuntimeException('no host found for Provider');
                }
                $externalIdPublisher = null;
                $referencePublisher = null;
                $publisher = $entity->getPublisher($host);
                if (isset($publisher)) {
                    $externalIdPublisher = $publisher->externalId;
                    $referencePublisher = $publisher->reference;
                }
                if (empty($externalIdPublisher)) {
                    $externalIdPublisher = $entity->applyId;
                }
                if (empty($referencePublisher)) {
                    $referencePublisher = $entity->reference;
                }

                // all this is very alpha and will be due to several changes

                // needed by now are (naming according to the Provider):
                //   applyId           = to identify the job back in the provider
                //   company           = name of the company
                //   title             =
                //   description       =
                //   location          = zip and town-name
                //   datePublishStart  = in a comprehensibly format for \DateTime
                //   channels          = array of externalIds
                $data = array(
                    'referenceId'      => $externalIdPublisher,
                    // applyId is historical, it should be replaced by referenceId
                    'applyId'          => $externalIdPublisher,
                    'reference'        => $referencePublisher,
                    'company'          => $entity->organization->name,
                    'title'            => $entity->title,
                    'description'      => $html,
                    'location'         => $entity->location,
                    'datePublishStart' => $entity->datePublishStart,
                    'channels'         => array(),
                    'templateName'     => $entity->template,
                    'contactEmail'     => $entity->contactEmail

                );
                //$hydrator = $serviceManager->get('Jobs/JobsEntityHydrator');
                //$data = $hydrator->extract($entity);

                foreach ($entity->portals as $portalName => $portal) {
                    if (array_key_exists($portal, $provider->channels)) {
                        $data['channels'][] = $provider->channels[$portal]->externalkey;
                    }
                }

                $dataJson = json_encode($data);
                $restClient->setRawBody($dataJson);
                $response = $restClient->send();
                $StatusCode = $response->getStatusCode();
                $body = $response->getBody();
                $decodedBody = json_decode($body);
                $jsonLastError = json_last_error();
                if (json_last_error() != JSON_ERROR_NONE) {
                    // not able to decode json
                    $log->info('RestCall Response not Json [errorCode: ' . $jsonLastError . ']: ' . var_export($body, true));
                } else {
                    // does the provider want to have an own ID for Identification ?
                    $response_referenceUpdate = $decodedBody->referenceUpdate;
                    $response_externalIdUpdate = $decodedBody->applyIdUpdate;

                    if ($publisher->externalId != $response_externalIdUpdate || $publisher->reference != $response_referenceUpdate) {
                        $logInfo = 'RestCall changed externalID ['
                                   . var_export($publisher->externalId, true)
                                   . ' => '
                                   . var_export($response_externalIdUpdate, true) . '], reference  ['
                                   . var_export($publisher->reference, true)
                                   . ' => '
                                   . var_export($response_referenceUpdate, true) . ']';
                        $log->info($logInfo);
                        $publisher->reference = $response_referenceUpdate;
                        $publisher->externalId = $response_externalIdUpdate;
                        $serviceManager->get('repositories')->store($entity);
                    }
                }

                $e->stopPropagation(true);
                $response = new JobResponse($this->name, JobResponse::RESPONSE_OKANDSTOP);
            } catch (\Exception $e) {
                $response = new JobResponse($this->name, JobResponse::RESPONSE_FAIL);
            }
        }
        return $response;
    }
936415
public function injectResponse(ViewEvent $e)
    {
        $result   = $e->getResult();
        $response = $e->getResponse();

        $response->setContent($result);
    }
1170657
public function selectRenderer(ViewEvent $event)
    {
        $model = $event->getModel();
        
        if ($model instanceof Model\PdfModel) {
            return $this->renderer;
        }

        return null;
    }
68362
public function onBootstrap(MvcEvent $e)
    {
        $serviceManager = $e->getApplication()->getServiceManager();

        // Don't break console routes
        if ($e->getRequest() instanceof Request) {
            return;
        }

        //Add Domain Checker
        $onDispatchListener = $serviceManager->get(
            \RcmAdmin\EventListener\DispatchListener::class
        );

        /** @var \Zend\EventManager\EventManager $eventManager */
        $eventManager = $e->getApplication()->getEventManager();

        $eventManager->attach(
            MvcEvent::EVENT_DISPATCH,
            [
                $onDispatchListener,
                'getAdminPanel'
            ],
            10001
        );
    }
185348
public function addRequestAttributes(FilterViewBuilderParametersEvent $e)
    {
        $parameterBag = $e->getParameters();
        $parameterBag->add($e->getRequest()->attributes->all());

        // maybe this should be in its own listener ? The ViewBuilder needs it.
        if (!$parameterBag->has('viewType')) {
            $parameterBag->add(['viewType' => null]);
        }
    }
773243
public function injectResponse(ViewEvent $e)
    {
        $renderer = $e->getRenderer();
        if ($renderer !== $this->renderer) {
            // Discovered renderer is not ours; do nothing
            return;
        }

        $result = $e->getResult();

        if (!is_string($result)) {
            // @todo Potentially throw an exception here since we should *always* get back a result.
            return;
        }

        $response = $e->getResponse();
        $response->setContent($result);
        $response->getHeaders()->addHeaderLine('content-type', 'application/pdf');

        $fileName = $e->getModel()->getOption('filename');
        if (isset($fileName)) {
            if (substr($fileName, -4) != '.pdf') {
                $fileName .= '.pdf';
            }

            $response->getHeaders()->addHeaderLine(
                'Content-Disposition',
                'attachment; filename=' . $fileName
            );
        }
    }
1222965
public function viewCheck(ViewCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if ($event->getView() == 'category') {
            $category = CategoryQuery::create()
                ->filterById($event->getViewId())
                ->filterByVisible(1)
                ->count();

            if ($category == 0) {
                $dispatcher->dispatch(TheliaEvents::VIEW_CATEGORY_ID_NOT_VISIBLE, $event);
            }
        }
    }
1269940
public function getViewRenderer(): ViewRenderer
    {
        if ($this->viewRenderer === null) {
            $collector = $this->getCollector();
            $routes = $collector->getViews();
            $resolver = $collector->getViewEngineResolver();
            $templateHandlers = $collector->getTemplateStreamHandlers();
            if (!$templateHandlers->has('callback')) {
                $templateHandlers->add('callback', CallbackTemplateHandler::class);
            }
            $this->viewRenderer = new ViewRenderer($routes, new ViewEngine());
            $resolver->copyEngines($this->viewRenderer->getEngineResolver());
            $this->viewRenderer->handle('error.{error}', function ($error) {
                return TemplateStream::url('callback', '\Opis\Colibri\Rendering\Template::error' . $error, 'php');
            }, -100)->where('error', '401|403|404|405|500|503');
            $this->viewRenderer->handle('alerts', function () {
                return TemplateStream::url('callback', '\Opis\Colibri\Rendering\Template::alerts', 'php');
            }, -100);
        }

        return $this->viewRenderer;
    }
206898
public function onDispatch(MvcEvent $e)
    {
        $routeMatch       = $e->getRouteMatch();
        $controllerName   = $routeMatch->getParam('controller', 'not-found');
        $application      = $e->getApplication();
        $controllerLoader = $application->getServiceManager()->get('ControllerLoader');

        if (!$controllerLoader->has($controllerName)) {
            throw new ControllerNotFoundException(sprintf(
                'Controller "%s" not found.'
                , $controllerName
            ));
        }

        $controller = $controllerLoader->get($controllerName);

        $request  = $e->getRequest();
        $response = $application->getResponse();

        if ($controller instanceof InjectApplicationEventInterface) {
            $controller->setEvent($e);
        }

        $return = $controller->dispatch($request, $response);

        return $this->complete($return, $e);
    }
921818
public function onDispatchError(MvcEvent $e)
    {
        $ex = $e->getParam('exception');
        $model = $e->getResult();

        if ($model instanceof ViewModel
            && Application::ERROR_EXCEPTION == $e->getError()
            && 0 === strpos($ex->getMessage(), 'Your application id and secret')
        ) {
            $model->setTemplate('auth/error/social-profiles-unconfigured');
        }
    }
862838
protected function handleViewException( Throwable $e )
	{
		$e = new ErrorException( $this->getMessage( $e ), 0, 1, $e->getFile(), $e->getLine(), $e );

		parent::handleViewException( $e );
	}
11034
public static function processViewHelpersInControllers($e) {
        $viewHelperManager = $e->getApplication()->getServiceManager()->get('ViewHelperManager');

        if (isset($_SESSION['processHead'])) {
            $process = $_SESSION['processHead'];
            unset($_SESSION['processHead']);
        } else {
            $process = null;
        }
        /**
         * Definbe um novo ou adiciona outro Titulo da página
         */
        if (isset($process['headTitle']) and ! empty($process['headTitle'])) {
            $headTitle = $viewHelperManager->get('headTitle');
            $headTitle($process['headTitle']['title'], $process['headTitle']['type'])->setSeparator($process['headTitle']['separator'])->setAutoEscape(false);
        }

        /**
         * Define o Doctype da página
         */
        if (isset($process['doctype']) and ! empty($process['doctype'])) {
            $doctype = $viewHelperManager->get('doctype');
            $doctype($process['doctype']);
        }

        /**
         * Define o Content Type da página
         */
        if (isset($process['contentType']) and ! empty($process['contentType'])) {
            $contentType = $viewHelperManager->get('headMeta');
            if (($process['doctype'] == \Zend\View\Helper\Doctype::XHTML5) or ( $process['doctype'] == \Zend\View\Helper\Doctype::HTML5)) {
                $contentType()->setCharset($process['contentType'])->setSeparator(PHP_EOL);
            } else {
                $contentType()->appendHttpEquiv('Content-Type', 'text/html; charset=' . $process['contentType'])->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define o Content Lang da página
         */
        if (isset($process['contentLang']) and ! empty($process['contentLang'])) {
            $contentLang = $viewHelperManager->get('headMeta');
            $contentLang()->appendHttpEquiv('Content-Language', $process['contentLang'])->setSeparator(PHP_EOL);
        }

        /**
         * Define Link de Estilo CSS ou Less da página
         */
        if (isset($process['headCssLink']) and ! empty($process['headCssLink'])) {
            $headCssLink = $viewHelperManager->get('headLink');
            foreach ($process['headCssLink'] as $key => $value) {
                if ($value['typeFile'] == 'css') {
                    $headCssLink()->appendStylesheet($value['url'], $value['media'], $value['conditional'])->setSeparator(PHP_EOL);
                } else if ($value['typeFile'] == 'less') {
                    $headCssLink()->appendStylesheet(URL_DEFAULT . 'less.php?' . $value['url'], $value['media'], $value['conditional'])->setSeparator(PHP_EOL);
                }
            }
        }

        /**
         * Define Link de Scripts JS na página
         */
        if (isset($process['headJsLink']) and ! empty($process['headJsLink'])) {
            $headJsLink = $viewHelperManager->get('headScript');
            foreach ($process['headJsLink'] as $key => $value) {
                $headJsLink()->appendFile($value['url'], $value['type'], $value['attrs'])->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define Link de cabeçalho da página
         */
        if (isset($process['headLink']) and ! empty($process['headLink'])) {
            $headLink = $viewHelperManager->get('headLink');
            foreach ($process['headLink'] as $valueHeadLink) {
                $headLink($valueHeadLink, 'PREPEND')->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define Estilo CSS na página
         */
        if (isset($process['headCssStyle']) and ! empty($process['headCssStyle'])) {
            $headCssLink = $viewHelperManager->get('headStyle');
            foreach ($process['headCssStyle'] as $key => $value) {
                $headCssLink()->appendStyle($value['css'], $value['conditional'])->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define Scripts JS na página
         */
        if (isset($process['headJsScript']) and ! empty($process['headJsScript'])) {
            $headJsScript = $viewHelperManager->get('headScript');
            foreach ($process['headJsScript'] as $key => $value) {
                $headJsScript()->appendScript($value['script'], $value['type'], $value['conditional'])->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define o Favicon da página
         */
        if (isset($process['favicon']) and ! empty($process['favicon'])) {
            $favicon = $viewHelperManager->get('headLink');
            if (($this->getDoctype() == \Zend\View\Helper\Doctype::XHTML5) or ( $this->getDoctype() == \Zend\View\Helper\Doctype::HTML5)) {
                $favicon(array('rel' => 'shortcut icon', 'href' => $process['favicon']), 'PREPEND')->setSeparator(PHP_EOL);
            } else {
                $favicon(array('rel' => 'favicon', 'href' => $process['favicon']), 'PREPEND')->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define Meta Tags do tipo Name
         */
        if (isset($process['metaName']) and ! empty($process['metaName'])) {
            $metaName = $viewHelperManager->get('headMeta');
            foreach ($process['metaName'] as $key => $value) {
                $metaName()->appendName($value['key'], $value['content'])->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define Meta Tags do tipo Property
         */
        if (isset($process['metaProperty']) and ! empty($process['metaProperty'])) {
            /**
             *
              $isFacebook = new \Cityware\View\Helper\IsFacebook();
              if ($isFacebook) {
              $this->getRenderer()->setDoctype(\Zend\View\Helper\Doctype::XHTML1_RDFA11);
              $this->getRenderer()->appendProperty($keyValue, $content)->setSeparator(PHP_EOL);
              }
             */
            $metaProperty = $viewHelperManager->get('headMeta');
            $doctype = $viewHelperManager->get('doctype');
            $doctype(\Zend\View\Helper\Doctype::XHTML1_RDFA11);

            foreach ($process['metaProperty'] as $key => $value) {
                $metaProperty()->appendProperty($value['key'], $value['content'])->setSeparator(PHP_EOL);
            }
        }

        /**
         * Define Meta Tags do tipo HttpEquiv
         */
        if (isset($process['metaHttpEquiv']) and ! empty($process['metaHttpEquiv'])) {
            $metaName = $viewHelperManager->get('headMeta');
            foreach ($process['metaHttpEquiv'] as $key => $value) {
                $metaName()->appendHttpEquiv($value['key'], $value['content'])->setSeparator(PHP_EOL);
            }
        }
    }
1342524
public function render(): string
   {
       try {
           $output = "";
           foreach ($this->observer as $value) {
               $output .= $value->render();
           }
           return $output;
       } catch (Throwable $e) {
           throw new ViewException(
               "Can't render " . static::class . " " . $e->getMessage()
           );
       }
   }
731014
public function onLoadMetadataHandler(WorkflowDispatchEventInterface $e)
    {
        $mvcEvent = $e->getMvcEvent();
        $controller = $mvcEvent->getTarget();
        if (!$controller instanceof AbstractController) {
            $this->getLog()->notice(
                'Unable to retrieve the metadata for scheduling workflow. No controller object in the property "target" MvcEvent.'
            );
            return null;
        }

        $routeMatch = $mvcEvent->getRouteMatch();
        if (!$routeMatch) {
            $this->getLog()->notice(
                'Unable to retrieve the metadata for scheduling workflow. Do not set RouteMatch'
            );
            return null;
        }

        $action = $routeMatch->getParam('action', 'not-found');
        $actionMethod = AbstractController::getMethodFromAction($action);

        if (!method_exists($controller, $actionMethod)) {
            $this->getLog()->notice(
                sprintf(
                    'Unable to retrieve the metadata for scheduling workflow. There is no action(%s) in controller(%s)',
                    $actionMethod,
                    get_class($controller)
                )
            );
            return null;
        }

        $controllerClassName = get_class($controller);
        $metadata = $this->getMetadataReader()->loadMetadataForAction($controllerClassName, $actionMethod);

        return $metadata;
    }
63960
public function buildViewReference(View $view, EntityManager $em = null)
    {
        $viewReferenceBuilder = $this->viewReferenceBuilderChain->getViewReferenceBuilder($view);
        $viewReference = $viewReferenceBuilder->buildReference($view, $em);

        return $viewReference;
    }