0 follower

Final Class Yiisoft\Request\Body\BadRequestHandler

InheritanceYiisoft\Request\Body\BadRequestHandler
ImplementsYiisoft\Request\Body\BadRequestHandlerInterface

Default handler that is used when there is an error during parsing a request.

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

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

                public function handle(ServerRequestInterface $request): ResponseInterface
{
    $response = $this->responseFactory->createResponse(Status::BAD_REQUEST);
    $response
        ->getBody()
        ->write(Status::TEXTS[Status::BAD_REQUEST]);
    if ($this->parserException !== null) {
        $response
            ->getBody()
            ->write("\n" . $this->parserException->getMessage());
    }
    return $response;
}

            
withParserException() public method

public Yiisoft\Request\Body\BadRequestHandlerInterface withParserException ( Yiisoft\Request\Body\ParserException $e )
$e Yiisoft\Request\Body\ParserException

                public function withParserException(ParserException $e): BadRequestHandlerInterface
{
    $new = clone $this;
    $new->parserException = $e;
    return $new;
}