thephpleague / route

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
http://route.thephpleague.com
MIT License
651 stars 126 forks source link

Route::getCallable doesn't work if handler is an alias of an instance of a callable class #281

Closed pfazzi closed 4 years ago

pfazzi commented 4 years ago

In a PSR-11 compliant Container i may define services using IDs instead of the FQCN. This is usefull when a class has multiple instances in the container. Let's consider the following definition:

'controller.project.create_project' => GenericCreateController::class

Where GenericCreateController is an invokable class.

If I define the following route:

$router->post('/projects', 'controller.project.create_project');

it won't work. ATM I have to define it as:

$router->post('/projects', ['controller.project.create_project', '__invoke']);

It would be nice to simply use the class alias without the need to specify the __invoke method.

memran commented 4 years ago

i think You can try to use custom strategy. You need to set container on strategy by calling method 'setContainer'.

for more help please check here https://route.thephpleague.com/4.x/dependency-injection/.

philipobenito commented 4 years ago

Duplicate of #263