Skip to content

Commit 72bf9cd

Browse files
Merge branch '5.0'
* 5.0: updated VERSION for 3.4.40 update CONTRIBUTORS for 3.4.40 updated CHANGELOG for 3.4.40 [WebProfilerBundle] changed label of peak memory usage in the time & memory panels (MB into MiB) add tests for the ConstraintViolationBuilder class Improve dirname usage [PhpUnitBridge] Use COMPOSER_BINARY env var if available Allow invalidateTags calls to be traced by data collector [YAML] escape DEL(\x7f) fix compatibility with phpunit 9 [Cache] skip APCu in chains when the backend is disabled [Mailer] Add a comment to avoid more wrong PRs on this piece of code [Form] apply automatically step=1 for datetime-local input remove getContainer overwrites in tests Fixing a bug where class_alias would cause incorrect items in debug:autowiring [DependencyInjection][ServiceSubscriber] Support late aliases Fix profiler nullable string type
2 parents 3c721a6 + 92d8b3b commit 72bf9cd

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

Dumper/PhpDumper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,11 @@ private function dumpValue($value, bool $interpolate = true): string
17261726
if (!$v) {
17271727
continue;
17281728
}
1729-
$definition = $this->container->findDefinition($id = (string) $v);
1729+
$id = (string) $v;
1730+
while ($this->container->hasAlias($id)) {
1731+
$id = (string) $this->container->getAlias($id);
1732+
}
1733+
$definition = $this->container->getDefinition($id);
17301734
$load = !($definition->hasErrors() && $e = $definition->getErrors()) ? $this->asFiles && !$this->inlineFactories && !$this->isHotPath($definition) : reset($e);
17311735
$serviceMap .= sprintf("\n %s => [%s, %s, %s, %s],",
17321736
$this->export($k),

Tests/Compiler/RegisterServiceSubscribersPassTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function testNoAttributes()
8888
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
8989
'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'bar')),
9090
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'baz')),
91+
'late_alias' => new ServiceClosureArgument(new TypedReference(TestDefinition1::class, TestDefinition1::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'late_alias')),
9192
];
9293

9394
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
@@ -118,6 +119,7 @@ public function testWithAttributes()
118119
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
119120
'bar' => new ServiceClosureArgument(new TypedReference('bar', CustomDefinition::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'bar')),
120121
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'baz')),
122+
'late_alias' => new ServiceClosureArgument(new TypedReference(TestDefinition1::class, TestDefinition1::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'late_alias')),
121123
];
122124

123125
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
@@ -260,6 +262,7 @@ public function testBinding()
260262
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
261263
'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'bar')),
262264
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'baz')),
265+
'late_alias' => new ServiceClosureArgument(new TypedReference(TestDefinition1::class, TestDefinition1::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'late_alias')),
263266
];
264267

265268
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));

Tests/Dumper/PhpDumperTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
2222
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
2323
use Symfony\Component\DependencyInjection\Argument\ServiceLocator as ArgumentServiceLocator;
24+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
25+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
2426
use Symfony\Component\DependencyInjection\ContainerBuilder;
2527
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
2628
use Symfony\Component\DependencyInjection\Definition;
@@ -38,6 +40,7 @@
3840
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;
3941
use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory;
4042
use Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator;
43+
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;
4144
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber;
4245
use Symfony\Component\DependencyInjection\TypedReference;
4346
use Symfony\Component\DependencyInjection\Variable;
@@ -911,6 +914,20 @@ public function testServiceSubscriber()
911914

912915
$container->register(CustomDefinition::class, CustomDefinition::class)
913916
->setPublic(false);
917+
918+
$container->register(TestDefinition1::class, TestDefinition1::class)->setPublic(true);
919+
920+
$container->addCompilerPass(new class() implements CompilerPassInterface {
921+
/**
922+
* {@inheritdoc}
923+
*/
924+
public function process(ContainerBuilder $container)
925+
{
926+
$container->setDefinition('late_alias', new Definition(TestDefinition1::class));
927+
$container->setAlias(TestDefinition1::class, 'late_alias');
928+
}
929+
}, PassConfig::TYPE_AFTER_REMOVING);
930+
914931
$container->compile();
915932

916933
$dumper = new PhpDumper($container);

Tests/Fixtures/TestServiceSubscriber.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static function getSubscribedServices(): array
2222
'?'.CustomDefinition::class,
2323
'bar' => CustomDefinition::class,
2424
'baz' => '?'.CustomDefinition::class,
25+
'late_alias' => TestDefinition1::class,
2526
];
2627
}
2728
}

Tests/Fixtures/php/services_subscriber.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ public function __construct()
2424
$this->methodMap = [
2525
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'getTestServiceSubscriberService',
2626
'foo_service' => 'getFooServiceService',
27+
'late_alias' => 'getLateAliasService',
28+
];
29+
$this->aliases = [
30+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestDefinition1' => 'late_alias',
2731
];
28-
29-
$this->aliases = [];
3032
}
3133

3234
public function compile(): void
@@ -42,11 +44,13 @@ public function isCompiled(): bool
4244
public function getRemovedIds(): array
4345
{
4446
return [
45-
'.service_locator.Csd_kfL' => true,
46-
'.service_locator.Csd_kfL.foo_service' => true,
47+
'.service_locator.dZze14t' => true,
48+
'.service_locator.dZze14t.foo_service' => true,
4749
'Psr\\Container\\ContainerInterface' => true,
4850
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
4951
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true,
52+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestDefinition1' => true,
53+
'late_alias' => true,
5054
];
5155
}
5256

@@ -72,14 +76,26 @@ protected function getFooServiceService()
7276
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
7377
'bar' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
7478
'baz' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
79+
'late_alias' => ['services', 'late_alias', 'getLateAliasService', false],
7580
], [
7681
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
7782
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber',
7883
'bar' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
7984
'baz' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
85+
'late_alias' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestDefinition1',
8086
]))->withContext('foo_service', $this));
8187
}
8288

89+
/**
90+
* Gets the public 'late_alias' shared service.
91+
*
92+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1
93+
*/
94+
protected function getLateAliasService()
95+
{
96+
return $this->services['late_alias'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1();
97+
}
98+
8399
/**
84100
* Gets the private 'Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition' shared service.
85101
*

0 commit comments

Comments
 (0)