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

v3 Make resolving callables lazy #1427

Closed geggleto closed 9 years ago

geggleto commented 9 years ago

In the app class here... https://github.com/slimphp/Slim/blob/3.x/Slim/App.php#L236

If you use a string callable for your routes, there is always one lookup performed BEFORE the route is dispatched. This means that as the number of routes you provide there is a slight overhead for the lookup.

It would be nice to refactor this so that the lookup is performed after the router has chosen a callable to dispatch.

public function map(array $methods, $pattern, $callable)
    {
        $callable = is_string($callable) ? $this->resolveCallable($callable) : $callable;
        if ($callable instanceof Closure) {
            $callable = $callable->bindTo($this);
        }
        $route = $this->container->get('router')->map($methods, $pattern, $callable);
        if (is_callable([$route, 'setContainer'])) {
            $route->setContainer($this->container);
        }
        if (is_callable([$route, 'setOutputBuffering'])) {
            $route->setOutputBuffering($this->container->get('settings')['outputBuffering']);
        }
        return $route;
    }
silentworks commented 9 years ago

Fixed.