本文整理汇总了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;
}
示例2: extractHeaders
private static function extractHeaders(\Exception $exception)
{
if ($exception instanceof HttpExceptionInterface) {
return $exception->getHeaders();
}
return [];
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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;
}