Skip to content

Commit

Permalink
bug #36441 [DI] fix loading defaults when using the PHP-DSL (nicolas-…
Browse files Browse the repository at this point in the history
…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
-------

51e0d37 [DI] fix loading defaults when using the PHP-DSL
  • Loading branch information
nicolas-grekas committed Apr 13, 2020
2 parents 311a944 + 51e0d37 commit 41c93b6
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
Expand Up @@ -44,7 +44,9 @@ public function process(ContainerBuilder $container)

$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([]);
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -79,10 +79,13 @@ final public function set($id, $class = null)
$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());
Expand All @@ -101,7 +104,10 @@ final public function set($id, $class = null)
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);
Expand Down
Expand Up @@ -6,5 +6,4 @@ services:
synthetic: true
App\BarService:
class: App\BarService
public: true
arguments: [!service { class: FooClass }]
Expand Up @@ -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'
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand All @@ -18,4 +17,3 @@ services:
configurator: c
foo:
class: App\FooService
public: true
Expand Up @@ -13,7 +13,6 @@ services:
arguments: ['@bar']
bar:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
public: true
calls:
- [setFoo, { }]

Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
Expand Up @@ -14,7 +14,7 @@
$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)
Expand Down Expand Up @@ -120,7 +120,6 @@
->tag('foo');

$s->set('tagged_iterator', 'Bar')
->public()
->args([tagged('foo')]);

$s->alias('alias_for_foo', 'foo')->private()->public();
Expand Down

0 comments on commit 41c93b6

Please sign in to comment.