bug #21219 [DI] Fixes aliases visibility with and without defaults (ogizanagi)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Fixes aliases visibility with and without defaults
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/21071#discussion_r95202920
| License | MIT
| Doc PR | N/A
Commits
-------
f1cc090465
[DI] Fixes aliases visibility with and without defaults
This commit is contained in:
commit
9e6d6ba3a9
@ -215,7 +215,8 @@ class YamlFileLoader extends FileLoader
|
||||
private function parseDefinition($id, $service, $file, array $defaults)
|
||||
{
|
||||
if (is_string($service) && 0 === strpos($service, '@')) {
|
||||
$this->container->setAlias($id, substr($service, 1));
|
||||
$public = isset($defaults['public']) ? $defaults['public'] : true;
|
||||
$this->container->setAlias($id, new Alias(substr($service, 1), $public));
|
||||
|
||||
return;
|
||||
}
|
||||
@ -231,7 +232,7 @@ class YamlFileLoader extends FileLoader
|
||||
static::checkDefinition($id, $service, $file);
|
||||
|
||||
if (isset($service['alias'])) {
|
||||
$public = array_key_exists('public', $service) ? (bool) $service['public'] : !empty($defaults['public']);
|
||||
$public = array_key_exists('public', $service) ? (bool) $service['public'] : (isset($defaults['public']) ? $defaults['public'] : true);
|
||||
$this->container->setAlias($id, new Alias($service['alias'], $public));
|
||||
|
||||
foreach ($service as $key => $value) {
|
||||
|
@ -34,3 +34,8 @@ services:
|
||||
inherit_tags: true
|
||||
tags:
|
||||
- name: baz
|
||||
|
||||
with_defaults_aliased:
|
||||
alias: with_defaults
|
||||
|
||||
with_defaults_aliased_short: '@with_defaults'
|
||||
|
@ -18,6 +18,8 @@ services:
|
||||
calls:
|
||||
- [ setBar, [ foo, '@foo', [true, false] ] ]
|
||||
alias_for_foo: '@foo'
|
||||
another_third_alias_for_foo:
|
||||
alias: foo
|
||||
another_alias_for_foo:
|
||||
alias: foo
|
||||
public: false
|
||||
|
@ -151,6 +151,9 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(isset($aliases['another_alias_for_foo']));
|
||||
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
|
||||
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
|
||||
$this->assertTrue(isset($aliases['another_third_alias_for_foo']));
|
||||
$this->assertEquals('foo', (string) $aliases['another_third_alias_for_foo']);
|
||||
$this->assertTrue($aliases['another_third_alias_for_foo']->isPublic());
|
||||
|
||||
$this->assertEquals(array('decorated', null, 0), $services['decorator_service']->getDecoratedService());
|
||||
$this->assertEquals(array('decorated', 'decorated.pif-pouf', 0), $services['decorator_service_with_name']->getDecoratedService());
|
||||
@ -362,6 +365,9 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array('foo' => array(array())), $container->getDefinition('with_defaults')->getTags());
|
||||
$this->assertTrue($container->getDefinition('with_defaults')->isAutowired());
|
||||
|
||||
$this->assertFalse($container->getAlias('with_defaults_aliased')->isPublic());
|
||||
$this->assertFalse($container->getAlias('with_defaults_aliased_short')->isPublic());
|
||||
|
||||
$this->assertArrayNotHasKey('public', $container->getDefinition('no_defaults_child')->getChanges());
|
||||
$this->assertArrayNotHasKey('autowire', $container->getDefinition('no_defaults_child')->getChanges());
|
||||
|
||||
|
Reference in New Issue
Block a user