当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception::getHeaders方法代码示例

本文整理汇总了PHP中Exception::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getHeaders方法的具体用法?PHP Exception::getHeaders怎么用?PHP Exception::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::getHeaders方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

    public static function create(\Exception $exception, $statusCode = null, array $headers = array())
    {
        $e = new static();
        $e->setMessage($exception->getMessage());
        $e->setCode($exception->getCode());

        if ($exception instanceof HttpExceptionInterface) {
            $statusCode = $exception->getStatusCode();
            $headers = array_merge($headers, $exception->getHeaders());
        } elseif ($exception instanceof RequestExceptionInterface) {
            $statusCode = 400;
        }

        if (null === $statusCode) {
            $statusCode = 500;
        }

        $e->setStatusCode($statusCode);
        $e->setHeaders($headers);
        $e->setTraceFromException($exception);
        $e->setClass(get_class($exception));
        $e->setFile($exception->getFile());
        $e->setLine($exception->getLine());

        $previous = $exception->getPrevious();

        if ($previous instanceof \Exception) {
            $e->setPrevious(static::create($previous));
        } elseif ($previous instanceof \Throwable) {
            $e->setPrevious(static::create(new FatalThrowableError($previous)));
        }

        return $e;
    }
开发者ID:symfony,项目名称:symfony,代码行数:34,代码来源:FlattenException.php

示例2: extractHeaders

 private static function extractHeaders(\Exception $exception)
 {
     if ($exception instanceof HttpExceptionInterface) {
         return $exception->getHeaders();
     }
     return [];
 }
开发者ID:jsor,项目名称:stack-hal,代码行数:7,代码来源:VndErrorResponse.php

示例3: create

    public static function create(\Exception $exception, $statusCode = null, array $headers = array())
    {
        $e = new static();
        $e->setMessage($exception->getMessage());
        $e->setCode($exception->getCode());

        if ($exception instanceof HttpExceptionInterface) {
            $statusCode = $exception->getStatusCode();
            $headers = array_merge($headers, $exception->getHeaders());
        }

        if (null === $statusCode) {
            $statusCode = 500;
        }

        $e->setStatusCode($statusCode);
        $e->setHeaders($headers);
        $e->setTrace($exception->getTrace(), $exception->getFile(), $exception->getLine());
        $e->setClass(get_class($exception));
        $e->setFile($exception->getFile());
        $e->setLine($exception->getLine());
        if ($exception->getPrevious()) {
            $e->setPrevious(static::create($exception->getPrevious()));
        }

        return $e;
    }
开发者ID:n3b,项目名称:symfony,代码行数:27,代码来源:FlattenException.php

示例4: createErrorResponseByException

 /**
  * {@inheritdoc}
  */
 public function createErrorResponseByException(\Exception $ex = null)
 {
     //TODO - handle more content types
     if (null !== $ex && $ex instanceof HttpExceptionInterface) {
         $statusCode = $ex->getStatusCode();
         $headers = (array) $ex->getHeaders();
     } else {
         $statusCode = 500;
         $headers = array('Content-Type' => array('text/html; charset=UTF-8'), 'Cache-Control' => array('max-age=0', 'must-revalidate', 'no-cache', 'no-store', 'private'));
     }
     return $this->messageFactory->createResponse($this->errorPageLoader->loadContentByStatusCode($statusCode), $statusCode, $headers);
 }
开发者ID:syrma-php,项目名称:web-container,代码行数:15,代码来源:DefaultExceptionHandler.php

示例5: htmlException

 /**
  * Format an exception as HTML and send appropriate exception info as HTTP headers
  * @param \Exception $e
  * @param array $title_tag
  * @param array $message_tag
  * @param array $trace_tag
  * @return string
  */
 public static function htmlException(\Exception $e, array $title_tag = ["h1"], array $message_tag = ["p"], array $trace_tag = ["pre", "style='font-size:smaller;overflow-x:scroll'"])
 {
     if ($e instanceof \http\Controller\Exception) {
         $code = $e->getCode() ?: 500;
         foreach ($e->getHeaders() as $key => $val) {
             HTTP::setResponseHeader($key, $val);
         }
     } else {
         $code = 500;
     }
     for ($html = ""; $e; $e = $e->getPrevious()) {
         $html .= static::htmlError(HTTP::getResponseStatusForCode($code), $e->getMessage(), $code, $e->getTraceAsString(), $title_tag, $message_tag, $trace_tag);
     }
     return $html;
 }
开发者ID:justforleo,项目名称:mdref,代码行数:23,代码来源:ExceptionHandler.php

示例6: createResponse

 /**
  * create response
  * with a HttpException status code and headers are considered
  * other exceptions default to status code 500
  * a error_docs/error_{status_code}.php template is parsed, when found
  * otherwise the exception data is decorated and dumped
  * 
  * @param \Exception $e
  * @return \vxPHP\Http\Response
  */
 protected function createResponse(\Exception $e)
 {
     if ($e instanceof HttpException) {
         $status = $e->getStatusCode();
         $headers = $e->getHeaders();
     } else {
         $status = Response::HTTP_INTERNAL_SERVER_ERROR;
         $headers = array();
     }
     $config = Application::getInstance()->getConfig();
     if (isset($config->paths['tpl_path'])) {
         $path = ($config->paths['tpl_path']['absolute'] ? '' : rtrim(Application::getInstance()->getRootPath(), DIRECTORY_SEPARATOR)) . $config->paths['tpl_path']['subdir'];
         if (file_exists($path . 'error_docs' . DIRECTORY_SEPARATOR . 'error_' . $status . '.php')) {
             $tpl = SimpleTemplate::create('error_docs' . DIRECTORY_SEPARATOR . 'error_' . $status . '.php');
             $content = $tpl->assign('exception', $e)->assign('status', $status)->display();
         } else {
             $content = $this->decorateException($e, $status);
         }
     } else {
         $content = $this->decorateException($e, $status);
     }
     return new Response($content, $status, $headers);
 }
开发者ID:vectrex,项目名称:vxphp,代码行数:33,代码来源:ExceptionHandler.php

示例7: create

 public static function create(\Exception $exception, $statusCode = null, array $headers = array())
 {
     $e = new static();
     $e->setMessage($exception->getMessage());
     $e->setCode($exception->getCode());
     if ($exception instanceof HttpExceptionInterface) {
         //TODO: Despues quitar la dependencia a esta excepcion de symfony
         $statusCode = $exception->getStatusCode();
         $headers = array_merge($headers, $exception->getHeaders());
     }
     if (null === $statusCode) {
         $statusCode = 500;
     }
     $e->setStatusCode($statusCode);
     $e->setHeaders($headers);
     $e->setTraceFromException($exception);
     $e->setClass(get_class($exception));
     $e->setFile($exception->getFile());
     $e->setLine($exception->getLine());
     if ($exception->getPrevious()) {
         $e->setPrevious(static::create($exception->getPrevious()));
     }
     return $e;
 }
开发者ID:aprezcuba24,项目名称:CULabsBugCatchPHP,代码行数:24,代码来源:FlattenException.php

示例8: handleException

 /**
  * Converts an exception into a response.
  *
  * @param \Exception $e
  *   An exception
  * @param Request $request
  *   A Request instance
  * @param int $type
  *   The type of the request (one of HttpKernelInterface::MASTER_REQUEST or
  *   HttpKernelInterface::SUB_REQUEST)
  *
  * @return Response
  *   A Response instance
  *
  * @throws \Exception
  *   If the passed in exception cannot be turned into a response.
  */
 protected function handleException(\Exception $e, $request, $type)
 {
     if ($e instanceof HttpExceptionInterface) {
         $response = new Response($e->getMessage(), $e->getStatusCode());
         $response->headers->add($e->getHeaders());
         return $response;
     } else {
         throw $e;
     }
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:27,代码来源:DrupalKernel.php

示例9: handleException

 /**
  * Converts an exception into a response.
  *
  * @param \Exception $e
  *   An exception
  * @param Request $request
  *   A Request instance
  * @param int $type
  *   The type of the request (one of HttpKernelInterface::MASTER_REQUEST or
  *   HttpKernelInterface::SUB_REQUEST)
  *
  * @return Response
  *   A Response instance
  */
 protected function handleException(\Exception $e, $request, $type)
 {
     if ($e instanceof HttpExceptionInterface) {
         $response = new Response($e->getMessage(), $e->getStatusCode());
         $response->headers->add($e->getHeaders());
         return $response;
     } else {
         // @todo: _drupal_log_error() and thus _drupal_exception_handler() prints
         // the message directly. Extract a function which generates and returns it
         // instead, then remove the output buffer hack here.
         ob_start();
         try {
             // @todo: The exception handler prints the message directly. Extract a
             // function which returns the message instead.
             _drupal_exception_handler($e);
         } catch (\Exception $e) {
             $message = Settings::get('rebuild_message', 'If you have just changed code (for example deployed a new module or moved an existing one) read <a href="https://www.drupal.org/documentation/rebuild">https://www.drupal.org/documentation/rebuild</a>');
             if ($message && Settings::get('rebuild_access', FALSE)) {
                 $rebuild_path = $GLOBALS['base_url'] . '/rebuild.php';
                 $message .= " or run the <a href=\"{$rebuild_path}\">rebuild script</a>";
             }
             print $message;
         }
         return new Response(ob_get_clean(), 500);
     }
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:40,代码来源:DrupalKernel.php

示例10: getAdaptedExceptionResponse

 /**
  * Return adapted (status code) Exception response from exception
  * @param \Exception $exception
  * @return \Symfony\Component\HttpFoundation\Response
  */
 private function getAdaptedExceptionResponse(\Exception $exception)
 {
     $response = new Response();
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->replace($exception->getHeaders());
     } else {
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     return $response;
 }
开发者ID:modnarlluf,项目名称:TwigException,代码行数:16,代码来源:KwrzExceptionListener.php

示例11: getHeaders

 /**
  * Get exception headers
  *
  * @param \Exception $exception
  *
  * @return array
  */
 private function getHeaders(\Exception $exception)
 {
     $headers = $this->default['headers'];
     if ($exception instanceof SymfonyHttpExceptionInterface || $exception instanceof HttpExceptionInterface) {
         $headers = $exception->getHeaders();
     }
     return $headers;
 }
开发者ID:pborreli,项目名称:ApiExceptionBundle,代码行数:15,代码来源:ExceptionListener.php


注:本文中的Exception::getHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。