diff --git a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php index f0be7534ea67..022533845427 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php @@ -43,7 +43,7 @@ public function load($resource, $type = null) $callback = $load($path); - if ($callback instanceof \Closure) { + if (\is_object($callback) && \is_callable($callback)) { $callback(new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource), $this->container, $this); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/object.expected.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/object.expected.yml new file mode 100644 index 000000000000..1137961ade13 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/object.expected.yml @@ -0,0 +1,10 @@ + +services: + service_container: + class: Symfony\Component\DependencyInjection\ContainerInterface + public: true + synthetic: true + App\BarService: + class: App\BarService + public: true + arguments: [!service { class: FooClass }] diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/object.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/object.php new file mode 100644 index 000000000000..d8e3828e5573 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/object.php @@ -0,0 +1,14 @@ +services(); + $s->set(BarService::class) + ->args(array(inline('FooClass'))); + } +}; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php index d4149f0301d3..b584a6922c62 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php @@ -68,6 +68,7 @@ public function testConfig($file) public function provideConfig() { yield array('basic'); + yield array('object'); yield array('defaults'); yield array('instanceof'); yield array('prototype'); diff --git a/src/Symfony/Component/Routing/Loader/PhpFileLoader.php b/src/Symfony/Component/Routing/Loader/PhpFileLoader.php index 3fcd692f9256..106ef5f62cc5 100644 --- a/src/Symfony/Component/Routing/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/PhpFileLoader.php @@ -46,7 +46,7 @@ public function load($file, $type = null) $result = $load($path); - if ($result instanceof \Closure) { + if (\is_object($result) && \is_callable($result)) { $collection = new RouteCollection(); $result(new RoutingConfigurator($collection, $this, $path, $file), $this); } else { diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/php_object_dsl.php b/src/Symfony/Component/Routing/Tests/Fixtures/php_object_dsl.php new file mode 100644 index 000000000000..f21f402efd4a --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/php_object_dsl.php @@ -0,0 +1,32 @@ +collection() + ->add('foo', '/foo') + ->condition('abc') + ->options(array('utf8' => true)) + ->add('buz', 'zub') + ->controller('foo:act'); + + $routes->import('php_dsl_sub.php') + ->prefix('/sub') + ->requirements(array('id' => '\d+')); + + $routes->import('php_dsl_sub.php') + ->namePrefix('z_') + ->prefix('/zub'); + + $routes->import('php_dsl_sub_root.php') + ->prefix('/bus', false); + + $routes->add('ouf', '/ouf') + ->schemes(array('https')) + ->methods(array('GET')) + ->defaults(array('id' => 0)); + } +}; diff --git a/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php index e31e381099d3..a148e9ee3fed 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php @@ -88,7 +88,8 @@ public function testRoutingConfigurator() { $locator = new FileLocator(array(__DIR__.'/../Fixtures')); $loader = new PhpFileLoader($locator); - $routeCollection = $loader->load('php_dsl.php'); + $routeCollectionClosure = $loader->load('php_dsl.php'); + $routeCollectionObject = $loader->load('php_object_dsl.php'); $expectedCollection = new RouteCollection(); @@ -122,9 +123,15 @@ public function testRoutingConfigurator() $expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub.php'))); $expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub_root.php'))); - $expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl.php'))); - $this->assertEquals($expectedCollection, $routeCollection); + $expectedCollectionClosure = $expectedCollection; + $expectedCollectionObject = clone $expectedCollection; + + $expectedCollectionClosure->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl.php'))); + $expectedCollectionObject->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_object_dsl.php'))); + + $this->assertEquals($expectedCollectionClosure, $routeCollectionClosure); + $this->assertEquals($expectedCollectionObject, $routeCollectionObject); } public function testRoutingConfiguratorCanImportGlobPatterns()