slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.98k stars 1.95k forks source link

Suggestion Slim3 : Multiple instance of CallableResolver while route mapping #1233

Closed rivetchip closed 9 years ago

rivetchip commented 9 years ago

For each mapped route using a "string controller", Slim create a new instance of CallableResolver.

$app->map(['GET'], '/hello', '\Controller\Class:function');

Isn't it more performance and better to resolve the callable directly into Route::__invoke() ? So only the one and final instance will be created. Something like :

use use ResolveCallable;

public function __invoke( ... ) {

    [...]

    $function = is_string($this->callable) ? $this->resolveCallable($this->callable) : $this->callable;

    $newReponse = $function($request, $response, $request->getAttributes());
}

But it also have a counterparty : passing Slim's Container to Route ( because of ResolveCallable Trait and $this ) or removing protected $container of CallableResolver ( don't think it's really useful unless we want to register a controller )

. What do you guys thinking ?

JoeBengalen commented 9 years ago

May be worth looking at, but it has to be resolved into a callable before any middleware can be added on top. So not sure if this is possible. Also we are not just talking about controllers, middleware also needs to use the same resolver.

lalop commented 9 years ago

Hello, this is done in a pr https://github.com/slimphp/Slim/pull/1208

rivetchip commented 9 years ago

@lalop Thanks I haven't seen it, I'll look in more deeply.