Commit b0bff6e2 authored by Fabien Potencier's avatar Fabien Potencier

minor #1034 Change closures to use $app as the first parameter. (henrikbjorn)

This PR was squashed before being merged into the 2.0.x-dev branch (closes #1034).

Discussion
----------

Change closures to use $app as the first parameter.

Almost always the first parameter is $app therefor it makes little sense
to use `use` part of the closure and having PHP do context switching all
over the place.

This also makes it explicit in the service providers exactly what $app
instance is used.

Commits
-------

5efdf830 Change closures to use  as the first parameter.
parents b028c59d 5efdf830
...@@ -62,45 +62,44 @@ class Application extends Container implements HttpKernelInterface, TerminableIn ...@@ -62,45 +62,44 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
{ {
parent::__construct(); parent::__construct();
$app = $this;
$this['routes_factory'] = $this->factory(function () { $this['routes_factory'] = $this->factory(function () {
return new RouteCollection(); return new RouteCollection();
}); });
$this['routes'] = function () use ($app) {
$this['routes'] = function ($app) {
return $app['routes_factory']; return $app['routes_factory'];
}; };
$this['controllers'] = function () use ($app) { $this['controllers'] = function ($app) {
return $app['controllers_factory']; return $app['controllers_factory'];
}; };
$this['controllers_factory'] = $this->factory(function () use ($app) { $this['controllers_factory'] = $this->factory(function ($app) {
return new ControllerCollection($app['route_factory'], $app['routes_factory']); return new ControllerCollection($app['route_factory'], $app['routes_factory']);
}); });
$this['route_class'] = 'Silex\\Route'; $this['route_class'] = 'Silex\\Route';
$this['route_factory'] = $this->factory(function () use ($app) { $this['route_factory'] = $this->factory(function ($app) {
return new $app['route_class'](); return new $app['route_class']();
}); });
$this['exception_handler'] = function () use ($app) { $this['exception_handler'] = function ($app) {
return new ExceptionHandler($app['debug']); return new ExceptionHandler($app['debug']);
}; };
$this['callback_resolver'] = function () use ($app) { $this['callback_resolver'] = function ($app) {
return new CallbackResolver($app); return new CallbackResolver($app);
}; };
$this['resolver'] = function () use ($app) { $this['resolver'] = function ($app) {
return new ControllerResolver($app, $app['logger']); return new ControllerResolver($app, $app['logger']);
}; };
$this['kernel'] = function () use ($app) { $this['kernel'] = function ($app) {
return new HttpKernel($app['dispatcher'], $app['resolver'], $app['request_stack']); return new HttpKernel($app['dispatcher'], $app['resolver'], $app['request_stack']);
}; };
$this['request_stack'] = function () use ($app) { $this['request_stack'] = function () {
return new RequestStack(); return new RequestStack();
}; };
......
...@@ -34,11 +34,11 @@ class RoutingServiceProvider implements ServiceProviderInterface, EventListenerP ...@@ -34,11 +34,11 @@ class RoutingServiceProvider implements ServiceProviderInterface, EventListenerP
return new UrlGenerator($app['routes'], $app['request_context']); return new UrlGenerator($app['routes'], $app['request_context']);
}; };
$app['request_matcher'] = function () use ($app) { $app['request_matcher'] = function ($app) {
return new RedirectableUrlMatcher($app['routes'], $app['request_context']); return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
}; };
$app['request_context'] = function () use ($app) { $app['request_context'] = function ($app) {
$context = new RequestContext(); $context = new RequestContext();
$context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80); $context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
...@@ -47,7 +47,7 @@ class RoutingServiceProvider implements ServiceProviderInterface, EventListenerP ...@@ -47,7 +47,7 @@ class RoutingServiceProvider implements ServiceProviderInterface, EventListenerP
return $context; return $context;
}; };
$app['routing.listener'] = function () use ($app) { $app['routing.listener'] = function ($app) {
$urlMatcher = new LazyRequestMatcher(function () use ($app) { $urlMatcher = new LazyRequestMatcher(function () use ($app) {
return $app['request_matcher']; return $app['request_matcher'];
}); });
......
...@@ -35,7 +35,7 @@ class SerializerServiceProvider implements ServiceProviderInterface ...@@ -35,7 +35,7 @@ class SerializerServiceProvider implements ServiceProviderInterface
*/ */
public function register(Container $app) public function register(Container $app)
{ {
$app['serializer'] = function () use ($app) { $app['serializer'] = function ($app) {
return new Serializer($app['serializer.normalizers'], $app['serializer.encoders']); return new Serializer($app['serializer.normalizers'], $app['serializer.encoders']);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment