Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
webmaster777 opened this issue Jul 3, 2024 · 0 comments
Open

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

webmaster777 opened this issue Jul 3, 2024 · 0 comments

Comments

@webmaster777
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant