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

4.x - Add an advanced callable resolver #2787

Merged
merged 23 commits into from Aug 11, 2019

Conversation

adriansuter
Copy link
Contributor

@adriansuter adriansuter commented Aug 9, 2019

This PR addresses #2780.

It defines a new AdvancedCallableResolver and a corresponding interface which extends the existing CallableResolverInterface. The advanced callable resolver would be created by default in the App constructor (if none had been passed).

The MiddlewareDispatcher would get the callable resolver as third optional param (non-BC). If it has one, and if the resolver is advanced, then the dispatcher would call the resolveMiddleware method. If the resolver is not advanced or if there is not even a resolver available, the dispatcher would execute its own hard coded resolving.

The \Slim\Routing\Route and the \Slim\Routing\RouteGroup would check if the resolver is advanced. If so, they call resolveRoute to perform the resolving. Otherwise they do as before.

Note: All the test cases for the callable resolver had been copied and implemented for the advanced callable resolver. Some of them were "triplicated", because two had to throw exceptions and one not.

@coveralls
Copy link

coveralls commented Aug 9, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 1386f93 on adriansuter:patch-callable-resolver into b8d2006 on slimphp:4.x.

Copy link
Member

@l0gicgate l0gicgate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adriansuter that's a really good solution so we entirely avoid any BC breaks. It's also opt-in for developers to implement which is awesome. Great work

Slim/MiddlewareDispatcher.php Outdated Show resolved Hide resolved
Slim/MiddlewareDispatcher.php Outdated Show resolved Hide resolved
Slim/AdvancedCallableResolver.php Outdated Show resolved Hide resolved
@l0gicgate l0gicgate added this to the 4.2.0 milestone Aug 9, 2019
@adriansuter
Copy link
Contributor Author

Okay, there are a lot of changes in the unit tests. I tried to make sure that they test the non-advanced callable resolver as well as the advanced callable resolver.

Two tests did not work as expected. But only if the callable resolver was non-advanced:

  • \Slim\Tests\MiddlewareDispatcherTest::testDeferredResolvedClosureIsBoundToContainer
  • \Slim\Tests\MiddlewareDispatcherTest::testFetchesMiddlewareFromContainer

Any idea why? I think there is something wrong in the \Slim\MiddlewareDispatcher::addDeferred() -> class::handle() method. Just couldn't find the bug.

@adriansuter
Copy link
Contributor Author

@l0gicgate Merged your PR. Slim is now using the \Slim\Interfaces\AdvancedCallableResolverInterface for the \Slim\CallableResolver by default.

@adriansuter adriansuter changed the title [WIP] 4.x - Add an advanced callable resolver 4.x - Add an advanced callable resolver Aug 11, 2019
@l0gicgate l0gicgate merged commit 88187e7 into slimphp:4.x Aug 11, 2019
@adriansuter adriansuter deleted the patch-callable-resolver branch August 13, 2019 14:41
@l0gicgate l0gicgate mentioned this pull request Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants