Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Middlewares для страницы 405

Вы можете задавать middlewares для страницы 405.

Для этого необходимо:

  1. Создать middleware или использовать существующую реализацию \Psr\Http\Server\MiddlewareInterface.
  2. Указать middlewares которые должны использоваться.

src/Middleware405.php расположить можно где угодно, главное следовать psr4.

<?php

declare(strict_types=1);

namespace App;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class Middleware405 implements MiddlewareInterface
{
    /**
     * @inheritDoc
     */
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // you can handle request here!!!
        return  $handler->handle($request);
    }
}

В файле src/Application.php при создании модуля \Cekta\Framework\HTTP\Module() можно указать имена middlewares для страницы 405, через параметр middlewares_405.

// ...
new \Cekta\Framework\HTTP\Module(
    middlewares_405: [
        \App\Example405::class,
    ]
),
// ...

Перезапустим (минимум build) чтобы изменения вступили в силу.

make restart

Теперь при появлении страницы 405, будут вызываться указанные middlewares.