0 follower

Final Class Yiisoft\Yii\Http\Handler\NotFoundHandler

InheritanceYiisoft\Yii\Http\Handler\NotFoundHandler
ImplementsPsr\Http\Server\RequestHandlerInterface

NotFoundHandler is used as a fallback handler by default {@see \Yiisoft\Yii\Http\Application}.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Yii\Http\Handler\NotFoundHandler
handle() Handles a request and produces a response. Yiisoft\Yii\Http\Handler\NotFoundHandler

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Psr\Http\Message\ResponseFactoryInterface $responseFactory )
$responseFactory \Psr\Http\Message\ResponseFactoryInterface

                public function __construct(
    private readonly ResponseFactoryInterface $responseFactory,
) {
}

            
handle() public method

Handles a request and produces a response.

May call other collaborating code to generate the response.

public \Psr\Http\Message\ResponseInterface handle ( \Psr\Http\Message\ServerRequestInterface $request )
$request \Psr\Http\Message\ServerRequestInterface

                public function handle(ServerRequestInterface $request): ResponseInterface
{
    $path = $request->getUri()->getPath();
    $response = $this->responseFactory->createResponse(Status::NOT_FOUND);
    $response->getBody()->write("We were unable to find the page \"$path\".");
    return $response;
}