Skip to content

injecting a middleware as callable array (non-static) #91

@webmaster777

Description

@webmaster777

Just a stub for now, I'll try to expand this later.

Bit related: slimphp/Slim#2780

I was trying to do this:

    $app->get('/register-platform', [RegisterPlatform::class, 'getRegister'])
      ->add([RegisterPlatform::class, 'assertValidRegistrationRequest']);

assertValidRegistrationRequest is a public (non-static) method with a valid middleware signature:

public function assertValidRegistrationRequest(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface

This however results in a

Uncaught RuntimeException: A middleware must be an object/class name referencing an implementation of MiddlewareInterface or a callable with a matching signature. in /app/vendor/slim/slim/Slim/MiddlewareDispatcher.php:92

My current workaround/solution is:

$app->get('/register-platform', [RegisterPlatform::class, 'getRegister'])
      ->add($callableResolver->resolve([RegisterPlatform::class, 'assertValidRegistrationRequest']));

where $callableResolver is of type DI\Bridge\Slim\CallableResolver. This however feels very verbose.

// or

$app->get('/register-platform', [RegisterPlatform::class, 'getRegister'])
      ->add(RegisterPlatform::class . '::assertValidRegistrationRequest');

but this is ugly.

Is it too extreme to override the MiddlewareDispatcher here to allow these notations? Otherwise the problem needs to be fixed in Slim's MiddlewareDispatcher to defer all middleware notations to the CallableResolver instead of only string variants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions