Skip to content

Commit 5fa0b62

Browse files
Merge branch '5.3' into 5.4
* 5.3: [DependencyInjection] Removed unsetting of environment property in loaders [Messenger] fix BC for FrameworkBundle 4.4 with a non-existence alias being used fix tests Optimize travis file a bit [DependencyInjection] Fix testServiceSubscriber for PHP 8.1 Remove duplicate catch block Add missing translations for Thai Add missing translations for Swedish [Serializer] Fix not null return check by "getCollectionKeyTypes"
2 parents 8b6c1d5 + 892f58c commit 5fa0b62

File tree

11 files changed

+293
-17
lines changed

11 files changed

+293
-17
lines changed

ContainerBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,11 @@ final public static function willBeAvailable(string $package, string $class, arr
14861486
// the package is installed but in dev-mode only, check if this applies to one of the parent packages too
14871487

14881488
$rootPackage = InstalledVersions::getRootPackage()['name'] ?? '';
1489+
1490+
if ('symfony/symfony' === $rootPackage) {
1491+
return true;
1492+
}
1493+
14891494
foreach ($parentPackages as $parentPackage) {
14901495
if ($rootPackage === $parentPackage || (InstalledVersions::isInstalled($parentPackage) && !InstalledVersions::isInstalled($parentPackage, false))) {
14911496
return true;

Loader/XmlFileLoader.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ public function load($resource, string $type = null)
5151

5252
$this->container->fileExists($path);
5353

54-
$env = $this->env;
55-
$this->env = null;
56-
try {
57-
$this->loadXml($xml, $path);
58-
} finally {
59-
$this->env = $env;
60-
}
54+
$this->loadXml($xml, $path);
6155

6256
if ($this->env) {
6357
$xpath = new \DOMXPath($xml);
6458
$xpath->registerNamespace('container', self::NS);
6559
foreach ($xpath->query(sprintf('//container:when[@env="%s"]', $this->env)) ?: [] as $root) {
66-
$this->loadXml($xml, $path, $root);
60+
$env = $this->env;
61+
$this->env = null;
62+
try {
63+
$this->loadXml($xml, $path, $root);
64+
} finally {
65+
$this->env = $env;
66+
}
6767
}
6868
}
6969
}

Loader/YamlFileLoader.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,21 @@ public function load($resource, string $type = null)
130130
return;
131131
}
132132

133-
$env = $this->env;
134-
$this->env = null;
135-
try {
136-
$this->loadContent($content, $path);
137-
} finally {
138-
$this->env = $env;
139-
}
133+
$this->loadContent($content, $path);
140134

141135
// per-env configuration
142136
if ($this->env && isset($content['when@'.$this->env])) {
143137
if (!\is_array($content['when@'.$this->env])) {
144138
throw new InvalidArgumentException(sprintf('The "when@%s" key should contain an array in "%s". Check your YAML syntax.', $this->env, $path));
145139
}
146140

147-
$this->loadContent($content['when@'.$this->env], $path);
141+
$env = $this->env;
142+
$this->env = null;
143+
try {
144+
$this->loadContent($content['when@'.$env], $path);
145+
} finally {
146+
$this->env = $env;
147+
}
148148
}
149149
}
150150

Tests/Dumper/PhpDumperTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,11 @@ public function process(ContainerBuilder $container)
973973

974974
$dumper = new PhpDumper($container);
975975

976-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_subscriber.php', $dumper->dump());
976+
if (80100 <= \PHP_VERSION_ID) {
977+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_subscriber_php81.php', $dumper->dump());
978+
} else {
979+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_subscriber.php', $dumper->dump());
980+
}
977981
}
978982

979983
public function testPrivateWithIgnoreOnInvalidReference()
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
4+
use Symfony\Component\DependencyInjection\ContainerInterface;
5+
use Symfony\Component\DependencyInjection\Container;
6+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7+
use Symfony\Component\DependencyInjection\Exception\LogicException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
11+
12+
/**
13+
* @internal This class has been auto-generated by the Symfony Dependency Injection Component.
14+
*/
15+
class ProjectServiceContainer extends Container
16+
{
17+
protected $parameters = [];
18+
protected $getService;
19+
20+
public function __construct()
21+
{
22+
$this->getService = \Closure::fromCallable([$this, 'getService']);
23+
$this->services = $this->privates = [];
24+
$this->methodMap = [
25+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'getTestServiceSubscriberService',
26+
'foo_service' => 'getFooServiceService',
27+
'late_alias' => 'getLateAliasService',
28+
];
29+
$this->aliases = [
30+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestDefinition1' => 'late_alias',
31+
];
32+
}
33+
34+
public function compile(): void
35+
{
36+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
37+
}
38+
39+
public function isCompiled(): bool
40+
{
41+
return true;
42+
}
43+
44+
public function getRemovedIds(): array
45+
{
46+
return [
47+
'.service_locator.JmEob1b' => true,
48+
'.service_locator.JmEob1b.foo_service' => true,
49+
'.service_locator.KIgkoLM' => true,
50+
'Psr\\Container\\ContainerInterface' => true,
51+
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
52+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true,
53+
];
54+
}
55+
56+
/**
57+
* Gets the public 'Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber' shared service.
58+
*
59+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber
60+
*/
61+
protected function getTestServiceSubscriberService()
62+
{
63+
return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber();
64+
}
65+
66+
/**
67+
* Gets the public 'foo_service' shared autowired service.
68+
*
69+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber
70+
*/
71+
protected function getFooServiceService()
72+
{
73+
return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($this->getService, [
74+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
75+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
76+
'bar' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
77+
'baz' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
78+
'late_alias' => ['services', 'late_alias', 'getLateAliasService', false],
79+
], [
80+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
81+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber',
82+
'bar' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
83+
'baz' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
84+
'late_alias' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestDefinition1',
85+
]))->withContext('foo_service', $this));
86+
}
87+
88+
/**
89+
* Gets the public 'late_alias' shared service.
90+
*
91+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1
92+
*/
93+
protected function getLateAliasService()
94+
{
95+
return $this->services['late_alias'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1();
96+
}
97+
98+
/**
99+
* Gets the private 'Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition' shared service.
100+
*
101+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition
102+
*/
103+
protected function getCustomDefinitionService()
104+
{
105+
return $this->privates['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition();
106+
}
107+
}

Tests/Fixtures/xml/services29.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
6+
<imports>
7+
<import resource="services30.xml"/>
8+
</imports>
9+
10+
<parameters>
11+
<parameter key="root_parameter">default value</parameter>
12+
</parameters>
13+
14+
<when env="dev">
15+
<parameters>
16+
<parameter key="root_parameter">value when on dev</parameter>
17+
</parameters>
18+
</when>
19+
20+
<when env="test">
21+
<parameters>
22+
<parameter key="root_parameter">value when on test</parameter>
23+
</parameters>
24+
</when>
25+
26+
<when env="prod">
27+
<parameters>
28+
<parameter key="root_parameter">value when on prod</parameter>
29+
</parameters>
30+
</when>
31+
</container>

Tests/Fixtures/xml/services30.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<parameters>
4+
<parameter key="imported_parameter">default value</parameter>
5+
</parameters>
6+
7+
<when env="dev">
8+
<parameters>
9+
<parameter key="imported_parameter">value when on dev</parameter>
10+
</parameters>
11+
</when>
12+
13+
<when env="test">
14+
<parameters>
15+
<parameter key="imported_parameter">value when on test</parameter>
16+
</parameters>
17+
</when>
18+
19+
<when env="prod">
20+
<parameters>
21+
<parameter key="imported_parameter">value when on prod</parameter>
22+
</parameters>
23+
</when>
24+
</container>

Tests/Fixtures/yaml/services29.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
imports:
2+
- { resource: services30.yml }
3+
4+
parameters:
5+
root_parameter: 'default value'
6+
7+
when@dev:
8+
parameters:
9+
root_parameter: 'value when on dev'
10+
11+
when@test:
12+
parameters:
13+
root_parameter: 'value when on test'
14+
15+
when@prod:
16+
parameters:
17+
root_parameter: 'value when on prod'

Tests/Fixtures/yaml/services30.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
parameters:
2+
imported_parameter: 'default value'
3+
4+
when@dev:
5+
parameters:
6+
imported_parameter: 'value when on dev'
7+
8+
when@test:
9+
parameters:
10+
imported_parameter: 'value when on test'
11+
12+
when@prod:
13+
parameters:
14+
imported_parameter: 'value when on prod'

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,43 @@ public function testLoadImports()
231231
}
232232
}
233233

234+
public function testLoadWithEnvironment()
235+
{
236+
$container = new ContainerBuilder();
237+
238+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'), 'dev');
239+
$loader->load('services29.xml');
240+
241+
self::assertSame([
242+
'imported_parameter' => 'value when on dev',
243+
'root_parameter' => 'value when on dev',
244+
], $container->getParameterBag()->all());
245+
246+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'), 'test');
247+
$loader->load('services29.xml');
248+
249+
self::assertSame([
250+
'imported_parameter' => 'value when on test',
251+
'root_parameter' => 'value when on test',
252+
], $container->getParameterBag()->all());
253+
254+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'), 'prod');
255+
$loader->load('services29.xml');
256+
257+
self::assertSame([
258+
'imported_parameter' => 'value when on prod',
259+
'root_parameter' => 'value when on prod',
260+
], $container->getParameterBag()->all());
261+
262+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'), 'other');
263+
$loader->load('services29.xml');
264+
265+
self::assertSame([
266+
'imported_parameter' => 'default value',
267+
'root_parameter' => 'default value',
268+
], $container->getParameterBag()->all());
269+
}
270+
234271
public function testLoadAnonymousServices()
235272
{
236273
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)