PHP Class Zend\Expressive\TemplatedErrorHandler

Provides the optional ability to render a template for each of 404 and general error conditions. If no template renderer is provided, returns empty responses with appropriate status codes.
Mostrar archivo Open project: zendframework/zend-expressive Class Usage Examples

Public Methods

Method Description
__construct ( Zend\Expressive\Template\TemplateRendererInterface $renderer = null, null | string $template404 = 'error::404', null | string $templateError = 'error::error', Psr\Http\Message\ResponseInterface $originalResponse = null )
__invoke ( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response, null | mixed $err = null ) : Psr\Http\Message\ResponseInterface Final handler for an application.
setOriginalResponse ( Psr\Http\Message\ResponseInterface $response ) Set the original response for comparisons.

Protected Methods

Method Description
handleError ( mixed $error, Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface Handle a non-exception error.
handleException ( Throwable $exception, Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface Prepare the exception for display.

Private Methods

Method Description
create404 ( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface Create a 404 response.
handleErrorResponse ( mixed $error, Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface Handle an error response.
handlePotentialSuccess ( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface Handle a non-error condition.
marshalReceivedResponse ( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface Determine whether to return the given response, or a 404.

Method Details

__construct() public method

public __construct ( Zend\Expressive\Template\TemplateRendererInterface $renderer = null, null | string $template404 = 'error::404', null | string $templateError = 'error::error', Psr\Http\Message\ResponseInterface $originalResponse = null )
$renderer Zend\Expressive\Template\TemplateRendererInterface Template renderer.
$template404 null | string Template to use for 404 responses.
$templateError null | string Template to use for general errors.
$originalResponse Psr\Http\Message\ResponseInterface Original response (used to calculate if the response has changed during middleware execution).

__invoke() public method

Final handler for an application.
public __invoke ( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response, null | mixed $err = null ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\RequestInterface
$response Psr\Http\Message\ResponseInterface
$err null | mixed
return Psr\Http\Message\ResponseInterface

handleError() protected method

If a template renderer is present, passes the following to the template specified in the $templateError property: - error (the error itself) - uri - status (response status) - reason (reason associated with response status) - request (full PSR-7 request instance) - response (full PSR-7 response instance) The results of rendering are then written to the response body. This method may be used as an extension point.
protected handleError ( mixed $error, Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface
$error mixed
$request Psr\Http\Message\RequestInterface
$response Psr\Http\Message\ResponseInterface
return Psr\Http\Message\ResponseInterface

handleException() protected method

Proxies to handleError(); exists primarily to as an extension point for other handlers.
protected handleException ( Throwable $exception, Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : Psr\Http\Message\ResponseInterface
$exception Throwable
$request Psr\Http\Message\RequestInterface
$response Psr\Http\Message\ResponseInterface
return Psr\Http\Message\ResponseInterface

setOriginalResponse() public method

Set the original response for comparisons.
public setOriginalResponse ( Psr\Http\Message\ResponseInterface $response )
$response Psr\Http\Message\ResponseInterface