8000 [DI] Fixes aliases visibility with and without defaults by ogizanagi · Pull Request #21219 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Fixes aliases visibility with and without defaults #21219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ private function parseDefinitions($content, $file)
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;
}
Expand All @@ -231,7 +232,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ services:
inherit_tags: true
tags:
- name: baz

with_defaults_aliased:
alias: with_defaults

with_defaults_aliased_short: '@with_defaults'
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
calls:
- [ setBar, [ foo, '@foo', [true, false] ] ]
alias_for_foo: '@foo'
another_third_alias_for_foo:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alias is before another_alias_for_foo because of an issue with the YamlDumper. See #21220

alias: foo
another_alias_for_foo:
alias: foo
public: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public function testLoadServices()
$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());
Expand Down Expand Up @@ -362,6 +365,9 @@ public function testDefaults()
$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());

Expand Down
0