Skip to content

Commit 2e8e960

Browse files
committed
feature #27065 [DI][Routing] Allow invokable objects to be used as PHP-DSL loaders (aurimasniekis)
This PR was squashed before being merged into the 4.1-dev branch (closes #27065). Discussion ---------- [DI][Routing] Allow invokable objects to be used as PHP-DSL loaders | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26583, #25630 | License | MIT | Doc PR | none Changed DI/Router PHPFileLoader to check is_object && is_callable instead of instance of Closure Commits ------- 662ff7e10b [DI][Routing] Allow invokable objects to be used as PHP-DSL loaders
2 parents 6ab684e + 97b8e1d commit 2e8e960

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

Loader/PhpFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function load($resource, $type = null)
4343

4444
$callback = $load($path);
4545

46-
if ($callback instanceof \Closure) {
46+
if (\is_object($callback) && \is_callable($callback)) {
4747
$callback(new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource), $this->container, $this);
4848
}
4949
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
services:
3+
service_container:
4+
class: Symfony\Component\DependencyInjection\ContainerInterface
5+
public: true
6+
synthetic: true
7+
App\BarService:
8+
class: App\BarService
9+
public: true
10+
arguments: [!service { class: FooClass }]

Tests/Fixtures/config/object.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use App\BarService;
6+
7+
return new class() {
8+
public function __invoke(ContainerConfigurator $c)
9+
{
10+
$s = $c->services();
11+
$s->set(BarService::class)
12+
->args(array(inline('FooClass')));
13+
}
14+
};

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function testConfig($file)
6868
public function provideConfig()
6969
{
7070
yield array('basic');
71+
yield array('object');
7172
yield array('defaults');
7273
yield array('instanceof');
7374
yield array('prototype');

0 commit comments

Comments
 (0)