[DI] fix loading defaults when using the PHP-DSL
This commit is contained in:
parent
311a944a08
commit
51e0d3792c
@ -44,7 +44,9 @@ class CacheCollectorPass implements CompilerPassInterface
|
||||
|
||||
$recorder = new Definition(is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class);
|
||||
$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')]);
|
||||
|
||||
$definition->setTags([]);
|
||||
|
@ -45,10 +45,13 @@ class PrototypeConfigurator extends AbstractServiceConfigurator
|
||||
public function __construct(ServicesConfigurator $parent, PhpFileLoader $loader, Definition $defaults, $namespace, $resource, $allowParent)
|
||||
{
|
||||
$definition = new Definition();
|
||||
$definition->setPublic($defaults->isPublic());
|
||||
if (!$defaults->isPublic() || !$defaults->isPrivate()) {
|
||||
$definition->setPublic($defaults->isPublic());
|
||||
}
|
||||
$definition->setAutowired($defaults->isAutowired());
|
||||
$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([]);
|
||||
|
||||
$this->loader = $loader;
|
||||
|
@ -79,10 +79,13 @@ class ServicesConfigurator extends AbstractConfigurator
|
||||
$allowParent = !$defaults->getChanges() && empty($this->instanceof);
|
||||
|
||||
$definition = new Definition();
|
||||
$definition->setPublic($defaults->isPublic());
|
||||
if (!$defaults->isPublic() || !$defaults->isPrivate()) {
|
||||
$definition->setPublic($defaults->isPublic() && !$defaults->isPrivate());
|
||||
}
|
||||
$definition->setAutowired($defaults->isAutowired());
|
||||
$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([]);
|
||||
|
||||
$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)
|
||||
{
|
||||
$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);
|
||||
|
||||
return new AliasConfigurator($this, $alias);
|
||||
|
@ -6,5 +6,4 @@ services:
|
||||
synthetic: true
|
||||
App\BarService:
|
||||
class: App\BarService
|
||||
public: true
|
||||
arguments: [!service { class: FooClass }]
|
||||
|
@ -6,10 +6,7 @@ services:
|
||||
synthetic: true
|
||||
foo:
|
||||
class: Class2
|
||||
public: true
|
||||
file: file.php
|
||||
lazy: true
|
||||
arguments: [!service { class: Class1, public: false }]
|
||||
bar:
|
||||
alias: foo
|
||||
public: true
|
||||
bar: '@foo'
|
||||
|
@ -6,7 +6,6 @@ services:
|
||||
synthetic: true
|
||||
App\BarService:
|
||||
class: App\BarService
|
||||
public: true
|
||||
arguments: [!service { class: FooClass }]
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
|
@ -6,7 +6,6 @@ services:
|
||||
synthetic: true
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
tags:
|
||||
- { name: tag, k: v }
|
||||
lazy: true
|
||||
@ -18,4 +17,3 @@ services:
|
||||
configurator: c
|
||||
foo:
|
||||
class: App\FooService
|
||||
public: true
|
||||
|
@ -13,7 +13,6 @@ services:
|
||||
arguments: ['@bar']
|
||||
bar:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
calls:
|
||||
- [setFoo, { }]
|
||||
|
||||
|
@ -6,7 +6,6 @@ services:
|
||||
synthetic: true
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
tags:
|
||||
- { name: foo }
|
||||
- { name: baz }
|
||||
@ -15,7 +14,6 @@ services:
|
||||
factory: f
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
|
||||
public: true
|
||||
tags:
|
||||
- { name: foo }
|
||||
- { name: baz }
|
||||
|
@ -14,7 +14,7 @@ return function (ContainerConfigurator $c) {
|
||||
$p->set('foo_class', FooClass::class)
|
||||
->set('foo', 'bar');
|
||||
|
||||
$s = $c->services();
|
||||
$s = $c->services()->defaults()->public();
|
||||
$s->set('foo')
|
||||
->args(['foo', ref('foo.baz'), ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, ref('service_container')])
|
||||
->class(FooClass::class)
|
||||
@ -120,7 +120,6 @@ return function (ContainerConfigurator $c) {
|
||||
->tag('foo');
|
||||
|
||||
$s->set('tagged_iterator', 'Bar')
|
||||
->public()
|
||||
->args([tagged('foo')]);
|
||||
|
||||
$s->alias('alias_for_foo', 'foo')->private()->public();
|
||||
|
Reference in New Issue
Block a user