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

Solve https://github.com/PHP-DI/Slim-Bridge/issues/51 #41

Closed
wants to merge 1 commit into from
Closed

Solve https://github.com/PHP-DI/Slim-Bridge/issues/51 #41

wants to merge 1 commit into from

Conversation

solventt
Copy link

It fixes PHP-DI/Slim-Bridge#51

This package is a dependency of php-di/slim-bridge.

I remind that the php-di/Invoker breakes the PSR-15 middleware resolving in the Slim microframework. When one writes
$app->add(SomeMiddleware::class) it causes displaying NotCallableException.

To fix it - a couple of the code strings should be added (see below).

What was generally done in the pull-request code:

1) Adding the psr/http-server-middleware package to the require (composer.json) section to have MiddlewareInterface

2) Adding to the resolve method of the Invoker\CallableResolver class the following code:

if ($callable instanceof MiddlewareInterface) {
    return fn ($request, $next) => $callable->process($request, $next);
}

3) Adding a unit-test method checking middleware resolving

4) Adding four mock classes for the new test method: Middleware, Request, RequestHandler, Response

Also I want you to pay attention that the php-di/slim-bridge package has the performance problem: its dependency (this package) duplicates the routing code from the Slim\Routing\Route class. See detailed information - PHP-DI/Slim-Bridge#51 (comment)

@mnapoli
Copy link
Member

mnapoli commented Nov 1, 2021

Thank you

I don't think this might be the right approach since it introduces a special behavior for a PSR class. The Invoker tries to stay generic, we don't really want a if for a specific class in there.

I've merged another PR in Slim-bridge to fix the original issue.

@mnapoli mnapoli closed this Nov 1, 2021
@solventt
Copy link
Author

solventt commented Nov 3, 2021

@mnapoli There is a big problem - AdvancedCallableResolver will be removed in Slim 5 (see issue). So the merge you have done will soon become obsolete.

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

Successfully merging this pull request may close these issues.

Custom implementation of CallableResolver breaks deferred middleware
2 participants