Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e6d6ba

Browse filesBrowse files
committed
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 | #21071 (comment) | License | MIT | Doc PR | N/A Commits ------- f1cc090 [DI] Fixes aliases visibility with and without defaults
2 parents e66e6af + f1cc090 commit 9e6d6ba
Copy full SHA for 9e6d6ba

File tree

Expand file treeCollapse file tree

4 files changed

+16
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+16
-2
lines changed

‎src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ private function parseDefinitions($content, $file)
215215
private function parseDefinition($id, $service, $file, array $defaults)
216216
{
217217
if (is_string($service) && 0 === strpos($service, '@')) {
218-
$this->container->setAlias($id, substr($service, 1));
218+
$public = isset($defaults['public']) ? $defaults['public'] : true;
219+
$this->container->setAlias($id, new Alias(substr($service, 1), $public));
219220

220221
return;
221222
}
@@ -231,7 +232,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
231232
static::checkDefinition($id, $service, $file);
232233

233234
if (isset($service['alias'])) {
234-
$public = array_key_exists('public', $service) ? (bool) $service['public'] : !empty($defaults['public']);
235+
$public = array_key_exists('public', $service) ? (bool) $service['public'] : (isset($defaults['public']) ? $defaults['public'] : true);
235236
$this->container->setAlias($id, new Alias($service['alias'], $public));
236237

237238
foreach ($service as $key => $value) {

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services28.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services28.yml
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ services:
3434
inherit_tags: true
3535
tags:
3636
- name: baz
37+
38+
with_defaults_aliased:
39+
alias: with_defaults
40+
41+
with_defaults_aliased_short: '@with_defaults'

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ services:
1818
calls:
1919
- [ setBar, [ foo, '@foo', [true, false] ] ]
2020
alias_for_foo: '@foo'
21+
another_third_alias_for_foo:
22+
alias: foo
2123
another_alias_for_foo:
2224
alias: foo
2325
public: false

‎src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public function testLoadServices()
151151
$this->assertTrue(isset($aliases['another_alias_for_foo']));
152152
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
153153
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
154+
$this->assertTrue(isset($aliases['another_third_alias_for_foo']));
155+
$this->assertEquals('foo', (string) $aliases['another_third_alias_for_foo']);
156+
$this->assertTrue($aliases['another_third_alias_for_foo']->isPublic());
154157

155158
$this->assertEquals(array('decorated', null, 0), $services['decorator_service']->getDecoratedService());
156159
$this->assertEquals(array('decorated', 'decorated.pif-pouf', 0), $services['decorator_service_with_name']->getDecoratedService());
@@ -362,6 +365,9 @@ public function testDefaults()
362365
$this->assertSame(array('foo' => array(array())), $container->getDefinition('with_defaults')->getTags());
363366
$this->assertTrue($container->getDefinition('with_defaults')->isAutowired());
364367

368+
$this->assertFalse($container->getAlias('with_defaults_aliased')->isPublic());
369+
$this->assertFalse($container->getAlias('with_defaults_aliased_short')->isPublic());
370+
365371
$this->assertArrayNotHasKey('public', $container->getDefinition('no_defaults_child')->getChanges());
366372
$this->assertArrayNotHasKey('autowire', $container->getDefinition('no_defaults_child')->getChanges());
367373

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.