isException example



    /** * Optimize Sourcecode / Apply SEO rules */
    public function onPostDispatch(Enlight_Controller_ActionEventArgs $args)
    {
        $request = $args->getSubject()->Request();
        $response = $args->getSubject()->Response();
        $view = $args->getSubject()->View();

        if (!$request->isDispatched() || $response->isException()
            || $request->getModuleName() !== 'frontend'
            || !$view->hasTemplate()
        ) {
            return;
        }

        $config = $this->get(Shopware_Components_Config::class);

        /** @var QueryAliasMapper $mapper */
        $mapper = $this->get(QueryAliasMapper::class);

        
Shopware()->Events()->registerListener($event);
    }

    /** * Checks the url / the request and passes it around if necessary. */
    public function onPreDispatch(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();
        $response = $args->getResponse();

        if ($response->isException()
            || $request->isPost()
            || $request->isXmlHttpRequest()             // is a ajax call             || $request->has('callback')                // is a jsonp call             || $request->getModuleName() != 'frontend'  // is not frontend             || !$request->getParam('rewriteAlias')      // is not a rewrite url alias         ) {
            return;
        }
        $router = $args->getSubject()->ensureRouter();

        $query = $request->getQuery();
        


    /** * On post dispatch we try to find affected articleIds displayed during this request * * @return void */
    public function onPostDispatch(Enlight_Controller_ActionEventArgs $args)
    {
        $view = $args->getSubject()->View();
        if (!$this->request->isDispatched()
            || $this->response->isException()
            || !$view->hasTemplate()
        ) {
            return;
        }

        if (!$this->hasSurrogateEsiCapability($this->request)) {
            return;
        }

        if ($this->request->getModuleName() !== 'frontend' && $this->request->getModuleName() !== 'widgets') {
            return;
        }

    public function onPostDispatch(Enlight_Event_EventArgs $args)
    {
        /** @var Enlight_Controller_Action $subject */
        $subject = $args->getSubject();

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

        if (!$request->isDispatched() || $response->isException() || $request->getModuleName() !== 'frontend') {
            return;
        }

        $id = (int) $subject->Request()->getParam('sArticle');
        $view = $subject->View();
        /** @var SessionInterface $session */
        $session = $this->get('session');

        $sArticle = $view->getAssign('sArticle');

        $notificationVariants = [];

        
/** * Validate that this argument works. By default, all arguments are valid. */
  public function validateArgument($arg) {
    // By using % in URLs, arguments could be validated twice; this eases     // that pain.     if (isset($this->argument_validated)) {
      return $this->argument_validated;
    }

    if ($this->isException($arg)) {
      return $this->argument_validated = TRUE;
    }

    $plugin = $this->getPlugin('argument_validator');
    return $this->argument_validated = $plugin->validateArgument($arg);
  }

  /** * Called by the menu system to validate an argument. * * This checks to see if this is a 'soft fail', which means that if the * argument fails to validate, but there is an action to take anyway, * then validation cannot actually fail. */
if ($last instanceof CSRFTokenValidationException || $this->isBotSession($request)) {
                        $this->logger->warning($last->getMessage());
                    } else {
                        $this->logger->critical($last->getMessage());
                    }
                }
            }

            return;
        }

        if (!$response->isException()) {
            return;
        }

        $this->isInsideErrorHandlerLoop = true;

        // Get exception information         $error = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS);
        $exceptions = $response->getException();
        $exception = $exceptions[0];
        $error->offsetSet('exception', $exception);

        

    public function sendResponse()
    {
        $headers = $this->getHeaders();
        $content = implode("\n", $headers) . "\n\n";

        if ($this->isException() && $this->renderExceptions()) {
            $exceptions = '';
            foreach ($this->getException() as $e) {
                $exceptions .= $e->__toString() . "\n";
            }
            $content .= $exceptions;
        } else {
            $content .= $this->outputBody();
        }

        return $content;
    }
}
$this->$action(...$this->getActionArguments($action));
            }

            $this->postDispatch();
        }

        // Fire "Secure"-PostDispatch-Events only if:         // - Request is Dispatched         // - Response in no Exception         // - View has template         if ($this->Request()->isDispatched()
            && !$this->Response()->isException()
            && $this->View()->hasTemplate()
        ) {
            Shopware()->Events()->notify(
                __CLASS__ . '_PostDispatchSecure_' . $this->controller_name,
                $args
            );

            Shopware()->Events()->notify(
                __CLASS__ . '_PostDispatchSecure_' . $moduleName,
                $args
            );

            

    public function onPostDispatch(Enlight_Event_EventArgs $args)
    {
        $request = $args->getSubject()->Request();
        $response = $args->getSubject()->Response();

        /** @var Enlight_View_Default $view */
        $view = $args->getSubject()->View();

        if (!$request->isDispatched() || $response->isException()
            || $request->getModuleName() !== 'frontend'
            || !$view->hasTemplate()
        ) {
            return;
        }

        $view->assign('baseUrl', $request->getBaseUrl() . $request->getPathInfo());

        $shop = Shopware()->Shop();
        $view->assign('Controller', $args->getSubject()->Request()->getControllerName());

        
/** * @return void */
    public function onPostDispatch(Enlight_Event_EventArgs $args)
    {
        $view = $args->getSubject()->View();
        $request = $args->getSubject()->Request();
        $response = $args->getSubject()->Response();

        if (!$request->isDispatched()
            || $response->isException()
            || $request->getModuleName() !== 'frontend'
        ) {
            return;
        }

        $config = $this->Config();
        if (empty($config->show)) {
            return;
        }

        if (strpos($config->controller, $request->getControllerName()) !== false) {
            
// remember that this argument was computed, not passed on the URL.           $argument->is_default = TRUE;
        }

        // Set the argument, which ensures that the argument is valid and         // possibly transforms the value.         if (!$argument->setArgument($arg)) {
          $status = $argument->validateFail($arg);
          break;
        }

        if ($argument->isException()) {
          $arg_title = $argument->exceptionTitle();
        }
        else {
          $arg_title = $argument->getTitle();
          $argument->query($this->display_handler->useGroupBy());
        }

        // Add this argument's substitution.         $substitutions["{{ arguments.$id }}"] = $arg_title;
        // Since argument validator plugins can potentially transform the value,         // use whatever value the argument handler now has, not the raw value.
public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Front_RouteShutdown' => ['onDispatchEvent', 100],
            'Enlight_Controller_Front_PostDispatch' => ['onDispatchEvent', 100],
            'Enlight_Controller_Front_DispatchLoopShutdown' => ['onDispatchEvent', 100],
        ];
    }

    public function onDispatchEvent(EventArgs $args)
    {
        if (!$args->getResponse()->isException()) {
            return;
        }

        $exception = $args->getResponse()->getException();
        $this->handleException($exception[0]);
    }

    /** * @param Exception $exception * * @throws Exception */
Home | Imprint | This part of the site doesn't use cookies.