bug #36441 [DI] fix loading defaults when using the PHP-DSL (nicolas-grekas)
This PR was merged into the 3.4 branch.
Discussion
----------
[DI] fix loading defaults when using the PHP-DSL
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
Commits
-------
51e0d3792c
[DI] fix loading defaults when using the PHP-DSL
This commit is contained in:
commit
41c93b65bf
@ -44,7 +44,9 @@ class CacheCollectorPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$recorder = new Definition(is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class);
|
$recorder = new Definition(is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class);
|
||||||
$recorder->setTags($definition->getTags());
|
$recorder->setTags($definition->getTags());
|
||||||
$recorder->setPublic($definition->isPublic());
|
if (!$definition->isPublic() || !$definition->isPrivate()) {
|
||||||
|
$recorder->setPublic($definition->isPublic());
|
||||||
|
}
|
||||||
$recorder->setArguments([new Reference($innerId = $id.'.recorder_inner')]);
|
$recorder->setArguments([new Reference($innerId = $id.'.recorder_inner')]);
|
||||||
|
|
||||||
$definition->setTags([]);
|
$definition->setTags([]);
|
||||||
|
@ -45,10 +45,13 @@ class PrototypeConfigurator extends AbstractServiceConfigurator
|
|||||||
public function __construct(ServicesConfigurator $parent, PhpFileLoader $loader, Definition $defaults, $namespace, $resource, $allowParent)
|
public function __construct(ServicesConfigurator $parent, PhpFileLoader $loader, Definition $defaults, $namespace, $resource, $allowParent)
|
||||||
{
|
{
|
||||||
$definition = new Definition();
|
$definition = new Definition();
|
||||||
$definition->setPublic($defaults->isPublic());
|
if (!$defaults->isPublic() || !$defaults->isPrivate()) {
|
||||||
|
$definition->setPublic($defaults->isPublic());
|
||||||
|
}
|
||||||
$definition->setAutowired($defaults->isAutowired());
|
$definition->setAutowired($defaults->isAutowired());
|
||||||
$definition->setAutoconfigured($defaults->isAutoconfigured());
|
$definition->setAutoconfigured($defaults->isAutoconfigured());
|
||||||
$definition->setBindings($defaults->getBindings());
|
// deep clone, to avoid multiple process of the same instance in the passes
|
||||||
|
$definition->setBindings(unserialize(serialize($defaults->getBindings())));
|
||||||
$definition->setChanges([]);
|
$definition->setChanges([]);
|
||||||
|
|
||||||
$this->loader = $loader;
|
$this->loader = $loader;
|
||||||
|
@ -79,10 +79,13 @@ class ServicesConfigurator extends AbstractConfigurator
|
|||||||
$allowParent = !$defaults->getChanges() && empty($this->instanceof);
|
$allowParent = !$defaults->getChanges() && empty($this->instanceof);
|
||||||
|
|
||||||
$definition = new Definition();
|
$definition = new Definition();
|
||||||
$definition->setPublic($defaults->isPublic());
|
if (!$defaults->isPublic() || !$defaults->isPrivate()) {
|
||||||
|
$definition->setPublic($defaults->isPublic() && !$defaults->isPrivate());
|
||||||
|
}
|
||||||
$definition->setAutowired($defaults->isAutowired());
|
$definition->setAutowired($defaults->isAutowired());
|
||||||
$definition->setAutoconfigured($defaults->isAutoconfigured());
|
$definition->setAutoconfigured($defaults->isAutoconfigured());
|
||||||
$definition->setBindings($defaults->getBindings());
|
// deep clone, to avoid multiple process of the same instance in the passes
|
||||||
|
$definition->setBindings(unserialize(serialize($defaults->getBindings())));
|
||||||
$definition->setChanges([]);
|
$definition->setChanges([]);
|
||||||
|
|
||||||
$configurator = new ServiceConfigurator($this->container, $this->instanceof, $allowParent, $this, $definition, $id, $defaults->getTags());
|
$configurator = new ServiceConfigurator($this->container, $this->instanceof, $allowParent, $this, $definition, $id, $defaults->getTags());
|
||||||
@ -101,7 +104,10 @@ class ServicesConfigurator extends AbstractConfigurator
|
|||||||
final public function alias($id, $referencedId)
|
final public function alias($id, $referencedId)
|
||||||
{
|
{
|
||||||
$ref = static::processValue($referencedId, true);
|
$ref = static::processValue($referencedId, true);
|
||||||
$alias = new Alias((string) $ref, $this->defaults->isPublic());
|
$alias = new Alias((string) $ref);
|
||||||
|
if (!$this->defaults->isPublic() || !$this->defaults->isPrivate()) {
|
||||||
|
$alias->setPublic($this->defaults->isPublic());
|
||||||
|
}
|
||||||
$this->container->setAlias($id, $alias);
|
$this->container->setAlias($id, $alias);
|
||||||
|
|
||||||
return new AliasConfigurator($this, $alias);
|
return new AliasConfigurator($this, $alias);
|
||||||
|
@ -6,5 +6,4 @@ services:
|
|||||||
synthetic: true
|
synthetic: true
|
||||||
App\BarService:
|
App\BarService:
|
||||||
class: App\BarService
|
class: App\BarService
|
||||||
public: true
|
|
||||||
arguments: [!service { class: FooClass }]
|
arguments: [!service { class: FooClass }]
|
||||||
|
@ -6,10 +6,7 @@ services:
|
|||||||
synthetic: true
|
synthetic: true
|
||||||
foo:
|
foo:
|
||||||
class: Class2
|
class: Class2
|
||||||
public: true
|
|
||||||
file: file.php
|
file: file.php
|
||||||
lazy: true
|
lazy: true
|
||||||
arguments: [!service { class: Class1, public: false }]
|
arguments: [!service { class: Class1, public: false }]
|
||||||
bar:
|
bar: '@foo'
|
||||||
alias: foo
|
|
||||||
public: true
|
|
||||||
|
@ -6,7 +6,6 @@ services:
|
|||||||
synthetic: true
|
synthetic: true
|
||||||
App\BarService:
|
App\BarService:
|
||||||
class: App\BarService
|
class: App\BarService
|
||||||
public: true
|
|
||||||
arguments: [!service { class: FooClass }]
|
arguments: [!service { class: FooClass }]
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||||
|
@ -6,7 +6,6 @@ services:
|
|||||||
synthetic: true
|
synthetic: true
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||||
public: true
|
|
||||||
tags:
|
tags:
|
||||||
- { name: tag, k: v }
|
- { name: tag, k: v }
|
||||||
lazy: true
|
lazy: true
|
||||||
@ -18,4 +17,3 @@ services:
|
|||||||
configurator: c
|
configurator: c
|
||||||
foo:
|
foo:
|
||||||
class: App\FooService
|
class: App\FooService
|
||||||
public: true
|
|
||||||
|
@ -13,7 +13,6 @@ services:
|
|||||||
arguments: ['@bar']
|
arguments: ['@bar']
|
||||||
bar:
|
bar:
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||||
public: true
|
|
||||||
calls:
|
calls:
|
||||||
- [setFoo, { }]
|
- [setFoo, { }]
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ services:
|
|||||||
synthetic: true
|
synthetic: true
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||||
public: true
|
|
||||||
tags:
|
tags:
|
||||||
- { name: foo }
|
- { name: foo }
|
||||||
- { name: baz }
|
- { name: baz }
|
||||||
@ -15,7 +14,6 @@ services:
|
|||||||
factory: f
|
factory: f
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
|
||||||
public: true
|
|
||||||
tags:
|
tags:
|
||||||
- { name: foo }
|
- { name: foo }
|
||||||
- { name: baz }
|
- { name: baz }
|
||||||
|
@ -14,7 +14,7 @@ return function (ContainerConfigurator $c) {
|
|||||||
$p->set('foo_class', FooClass::class)
|
$p->set('foo_class', FooClass::class)
|
||||||
->set('foo', 'bar');
|
->set('foo', 'bar');
|
||||||
|
|
||||||
$s = $c->services();
|
$s = $c->services()->defaults()->public();
|
||||||
$s->set('foo')
|
$s->set('foo')
|
||||||
->args(['foo', ref('foo.baz'), ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, ref('service_container')])
|
->args(['foo', ref('foo.baz'), ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, ref('service_container')])
|
||||||
->class(FooClass::class)
|
->class(FooClass::class)
|
||||||
@ -120,7 +120,6 @@ return function (ContainerConfigurator $c) {
|
|||||||
->tag('foo');
|
->tag('foo');
|
||||||
|
|
||||||
$s->set('tagged_iterator', 'Bar')
|
$s->set('tagged_iterator', 'Bar')
|
||||||
->public()
|
|
||||||
->args([tagged('foo')]);
|
->args([tagged('foo')]);
|
||||||
|
|
||||||
$s->alias('alias_for_foo', 'foo')->private()->public();
|
$s->alias('alias_for_foo', 'foo')->private()->public();
|
||||||
|
Reference in New Issue
Block a user