Skip to content

Remove the 'ResponseFactoryInterface $responseFactory' parameter from the 'Authentication' constructor #129

Description

@klsoft-web

Proposed new feature or change

The 'ResponseFactoryInterface $responseFactory' parameter is proposed for removal from the 'Authentication' constructor in order to simplify the 'Authentication' configuration, while retaining the same logic.

Current:

final class Authentication implements MiddlewareInterface
{
    // ...
    public function __construct(
        private AuthenticatorInterface|AuthenticationMethodInterface $authenticationMethod,
        ResponseFactoryInterface $responseFactory,
        ?RequestHandlerInterface $authenticationFailureHandler = null,
    ) {
        $this->failureHandler = $authenticationFailureHandler ?? new AuthenticationFailureHandler(
            $responseFactory,
        );
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // ...
        if ($identity === null && !$this->isOptional($request)) {
            $response = $this->failureHandler->handle($request);
            // ...
        }
        // ...
    }
    // ...
}

Proposed:

final class Authentication implements MiddlewareInterface
{
    // ...
    public function __construct(
        private AuthenticatorInterface|AuthenticationMethodInterface $authenticationMethod,
        private RequestHandlerInterface $authenticationFailureHandler
    ) {}

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    { 
        // ...
        if ($identity === null && !$this->isOptional($request)) {
            $response = $this->authenticationFailureHandler->handle($request);
            // ...
        }
        // ...
    }
    // ...
}
//config/di-web.php
use App\Web\Auth\AuthenticationFailureHandler;
use Psr\Http\Server\RequestHandlerInterface;

return [
    RequestHandlerInterface::class => AuthenticationFailureHandler::class
];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions