From 0d6cb778c5b2e47665a92d17867e7111f46771cf Mon Sep 17 00:00:00 2001 From: jdreesen Date: Tue, 1 Sep 2015 20:14:03 +0200 Subject: [PATCH] Override ControllerResolver as a shared service --- src/Application.php | 4 +++- tests/ApplicationTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Application.php b/src/Application.php index 34558dc..d8afe4d 100644 --- a/src/Application.php +++ b/src/Application.php @@ -43,7 +43,9 @@ public function __construct(ContainerBuilder $containerBuilder = null, array $va parent::__construct($values); // Override the controller resolver with ours - $this['resolver'] = new ControllerResolver($this->phpdi); + $this['resolver'] = $this->share(function () { + return new ControllerResolver($this->phpdi); + }); } public function offsetGet($id) diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 9431831..6fc68c1 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -42,4 +42,15 @@ public function the_application_should_expose_phpdi_container() $this->assertInstanceOf('DI\Container', $app->getPhpDi()); } + + /** + * @test + */ + public function the_controller_resolver_should_be_registered_as_a_service() + { + $app = new Application(); + + $this->assertInstanceOf('Closure', $app->raw('resolver')); + $this->assertInstanceOf('DI\Bridge\Silex\Controller\ControllerResolver', $app['resolver']); + } }