0 follower

Final Class Yiisoft\Middleware\Dispatcher\InvalidMiddlewareDefinitionException

InheritanceYiisoft\Middleware\Dispatcher\InvalidMiddlewareDefinitionException » InvalidArgumentException
ImplementsYiisoft\FriendlyException\FriendlyExceptionInterface

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( mixed $definition )
$definition mixed

                public function __construct(
    private mixed $definition
) {
    $this->definitionString = $this->convertDefinitionToString($definition);
    parent::__construct(
        'Parameter should be either PSR middleware class name or a callable. Got ' . $this->definitionString . '.'
    );
}

            
getName() public method

public string getName ( )

                public function getName(): string
{
    return 'Invalid middleware definition';
}

            
getSolution() public method

public string|null getSolution ( )

                public function getSolution(): ?string
{
    $solution = [
        <<<SOLUTION
        ## Got definition value
        `{$this->definitionString}`
        SOLUTION
    ];
    $suggestion = $this->generateSuggestion();
    if ($suggestion !== null) {
        $solution[] = '## Suggestion';
        $solution[] = $suggestion;
    }
    $solution[] = <<<SOLUTION
    ## Middleware definition examples
    PSR middleware class name:
    ```php
    Yiisoft\Session\SessionMiddleware::class
    ```
    PSR request handler class name:
    ```php
    Yiisoft\Yii\Swagger\Action\SwaggerUi::class
    ```
    An identifier of container definition for PSR middleware:
    ```php
    'sessionMiddleware'
    ```
    where `sessionMiddleware` is the identifier of container definition for `Yiisoft\Session\SessionMiddleware`.
    PSR middleware array definition:
    ```php
    [
        'class' => MyMiddleware::class,
        '__construct()' => [
            'someVar' => 42,
        ],
    ]
    ```
    Closure that returns `ResponseInterface`:
    ```php
    static function (): ResponseInterface {
        return new Response(418);
    },
    ```
    Closure that returns `MiddlewareInterface`:
    ```php
    static function (): MiddlewareInterface {
        return new TestMiddleware();
    }
    ```
    Closure that returns `RequestHandlerInterface`:
    ```php
    static function (): RequestHandlerInterface {
        return new SimpleRequestHandler();
    }
    ```
    Action in controller:
    ```php
    [App\Backend\UserController::class, 'index']
    ```
    ## Related links
    - [Array definition syntax](https://github.com/yiisoft/definitions#arraydefinition)
    - [Callable PHP documentation](https://www.php.net/manual/language.types.callable.php)
    SOLUTION;
    return implode("\n\n", $solution);
}