Pimcore\Controller\Action\Frontend::checkForErrors PHP Метод

checkForErrors() публичный Метод

public checkForErrors ( )
    public function checkForErrors()
    {
        if ($error = $this->getParam('error_handler')) {
            if ($error->exception) {
                if ($error->exception instanceof \Zend_Controller_Router_Exception || $error->exception instanceof \Zend_Controller_Action_Exception) {
                    header('HTTP/1.1 404 Not Found');
                    //$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
                    $this->getResponse()->setHttpResponseCode(404);
                    // check if the resource that wasn't found is a common static file
                    // for them we don't show the error page, as generating this is very heavy in terms of performance
                    if (preg_match("/\\.(js|css|png|jpe?g|gif|eot|ttf|woff|svg|ico|map|swf|txt)\$/", $this->getRequest()->getPathInfo())) {
                        echo "HTTP/1.1 404 Not Found\nFiltered by error handler (static file exception)";
                        exit;
                    }
                } else {
                    header('HTTP/1.1 503 Service Temporarily Unavailable');
                    //$this->getResponse()->setRawHeader('HTTP/1.1 503 Service Temporarily Unavailable');
                    $this->getResponse()->setHttpResponseCode(503);
                }
                Logger::error("Unable to find URL: " . $_SERVER["REQUEST_URI"]);
                Logger::error($error->exception);
                $results = \Pimcore::getEventManager()->trigger("frontend.error", $this, ["exception" => $error->exception]);
                $cacheKeySuffix = "";
                foreach ($results as $result) {
                    $cacheKeySuffix .= "_" . $result;
                }
                try {
                    // check if we have the error page already in the cache
                    // the cache is written in Pimcore\Controller\Plugin\HttpErrorLog::dispatchLoopShutdown()
                    $responseCode = $this->getResponse()->getHttpResponseCode();
                    $cacheKey = "error_" . $responseCode . "_" . \Pimcore\Tool\Frontend::getSiteKey() . $cacheKeySuffix;
                    if ($responseBody = \Pimcore\Cache::load($cacheKey)) {
                        $this->getResponse()->setBody($responseBody);
                        $this->getResponse()->sendResponse();
                        // write to http_error log
                        $errorLogPlugin = \Zend_Controller_Front::getInstance()->getPlugin("Pimcore\\Controller\\Plugin\\HttpErrorLog");
                        if ($errorLogPlugin) {
                            $errorLogPlugin->writeLog();
                        }
                        exit;
                    } else {
                        $errorLogPlugin = \Zend_Controller_Front::getInstance()->getPlugin("Pimcore\\Controller\\Plugin\\HttpErrorLog");
                        if ($errorLogPlugin) {
                            $errorLogPlugin->setCacheKey($cacheKey);
                        }
                        $document = \Zend_Registry::get("pimcore_error_document");
                        $this->setDocument($document);
                        $this->setParam("document", $document);
                        $this->disableLayout();
                        // http_error log writing is done in Pimcore_Controller_Plugin_HttpErrorLog in this case
                    }
                } catch (\Exception $e) {
                    $m = "Unable to load error document";
                    Tool::exitWithError($m);
                }
            }
        }
    }