Dispatcher example



        /** @var Enlight_Controller_Front $front */
        $front = $this->container->get('front');

        $enlightRequest = $this->transformSymfonyRequestToEnlightRequest($request);

        if ($front->Request() === null) {
            $front->setRequest($enlightRequest);
            $response = $front->dispatch();
        } else {
            $dispatcher = clone $front->Dispatcher();
            $response = clone $front->Response();

            $response->clearHeaders()
                ->clearBody();

            $response->setStatusCode(SymfonyResponse::HTTP_OK);
            $enlightRequest->setDispatched();
            $dispatcher->dispatch($enlightRequest$response);
        }

        $response->prepare($request);

        
/* * Skip requested action if preDispatch() has reset it */
                if (!$this->ensureRequest()->isDispatched()) {
                    continue;
                }

                /* * Dispatch request */
                $this->Dispatcher()->dispatch($this->ensureRequest()$this->Response());
            } catch (Exception $e) {
                if ($this->throwExceptions()) {
                    throw $e;
                }
                $this->Response()->setException($e);
            }
            /* * Notify plugins of dispatch completion */
            $this->eventManager->notify(
                'Enlight_Controller_Front_PostDispatch',
                
return $this;
    }

    /** * Returns the template name. * * @return string */
    public function getTemplateName()
    {
        $request = $this->viewRenderer->Action()->Request();
        $dispatcher = $this->viewRenderer->Front()->Dispatcher();

        $moduleName = $dispatcher->formatModuleName($request->getModuleName());
        $controllerName = $dispatcher->formatControllerName($request->getControllerName());

        $controllerName = $this->get('events')->filter('Enlight_Controller_Plugin_ScriptRenderer_formatControllerName', $controllerName['subject' => $this]);

        $fileNames = (array) $request->getParam('file', $this->defaultFile);
        if (empty($fileNames)) {
            $fileNames = $request->getParam('f');
            $fileNames = explode('|', (string) $fileNames);
        }

        
/** * Returns the template name of the current request instance. * The module, controller and action is gotten over the dispatcher instance of the Enlight_Controller_Front. * The template parts are imploded by "_" character. * * @return string */
    public function getTemplateName()
    {
        $request = $this->Action()->Request();
        $moduleName = $this->Front()->Dispatcher()->formatModuleName($request->getModuleName());
        $controllerName = $this->Front()->Dispatcher()->formatControllerName($request->getControllerName());
        $actionName = $this->Front()->Dispatcher()->formatActionName($request->getActionName());

        $parts = [$moduleName$controllerName$actionName];
        foreach ($parts as &$part) {
            $part = (string) preg_replace('#[A-Z]#', '_$0', $part);
            $part = trim($part, '_');
            $part = strtolower($part);
        }

        $templateName = implode(DIRECTORY_SEPARATOR, $parts) . '.tpl';

        
$targetErrorCode = $this->get('config')->get('PageNotFoundCode', 404);

        $response->setStatusCode($targetErrorCode);

        // Page not Found should not get logged in error handler         $response->unsetExceptions();

        switch ($targetEmotionId) {
            case -2:
            case null:
                $this->forward(
                    $this->get('front')->Dispatcher()->getDefaultAction(),
                    $this->get('front')->Dispatcher()->getDefaultControllerName()
                );
                break;
            case -1:
                $this->forward('genericError', null, null, ['code' => $targetErrorCode]);
                break;
            default:
                // Try to load the emotion landingpage, render default error in case it is unavailable                 try {
                    $result = $this->get('shopware.emotion.emotion_landingpage_loader')->load(
                        $targetEmotionId,
                        

function smarty_function_action($params, Enlight_Template_Default $template)
{
    $front = Shopware()->Front();
    $dispatcher = clone $front->Dispatcher();

    $request = $front->Request();
    $response = $front->Response();

    if (empty($request)) {
        throw new Exception('Action view helper requires both a registered request and response object in the front controller instance');
    }

    if (isset($params['name'])) {
        $params['action'] = $params['name'];
        unset($params['name']);
    }
/** * @throws Exception * @throws Enlight_Exception * @throws Enlight_Event_Exception */
    public function initController(
        Enlight_Controller_Request_RequestHttp $request,
        Enlight_Controller_Response_ResponseHttp $response
    ) {
        $this->setRequest($request)->setResponse($response);

        $this->controller_name = $this->Front()->Dispatcher()->getFullControllerName($this->Request());

        Shopware()->Events()->notify(
            __CLASS__ . '_Init',
            ['subject' => $this, 'request' => $this->Request(), 'response' => $this->Response()]
        );
        Shopware()->Events()->notify(
            __CLASS__ . '_Init_' . $this->controller_name,
            ['subject' => $this, 'request' => $this->Request(), 'response' => $this->Response()]
        );

        if (method_exists($this, 'init')) {
            
Home | Imprint | This part of the site doesn't use cookies.