Skip to content

Commit 4c1b449

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: Add missing Albanian translations for Security and Validator components suppress proc_open errors [DependencyInjection] Fix `XmlFileLoader` not respecting when env for services
2 parents e86616a + 132f97d commit 4c1b449

File tree

6 files changed

+94
-5
lines changed

6 files changed

+94
-5
lines changed

Loader/XmlFileLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function parseImports(\DOMDocument $xml, string $file, ?\DOMNode $root =
118118
$xpath = new \DOMXPath($xml);
119119
$xpath->registerNamespace('container', self::NS);
120120

121-
if (false === $imports = $xpath->query('.//container:imports/container:import', $root)) {
121+
if (false === $imports = $xpath->query('./container:imports/container:import', $root)) {
122122
return;
123123
}
124124

@@ -134,14 +134,14 @@ private function parseDefinitions(\DOMDocument $xml, string $file, Definition $d
134134
$xpath = new \DOMXPath($xml);
135135
$xpath->registerNamespace('container', self::NS);
136136

137-
if (false === $services = $xpath->query('.//container:services/container:service|.//container:services/container:prototype|.//container:services/container:stack', $root)) {
137+
if (false === $services = $xpath->query('./container:services/container:service|./container:services/container:prototype|./container:services/container:stack', $root)) {
138138
return;
139139
}
140140
$this->setCurrentDir(\dirname($file));
141141

142142
$this->instanceof = [];
143143
$this->isLoadingInstanceof = true;
144-
$instanceof = $xpath->query('.//container:services/container:instanceof', $root);
144+
$instanceof = $xpath->query('./container:services/container:instanceof', $root);
145145
foreach ($instanceof as $service) {
146146
$this->setDefinition((string) $service->getAttribute('id'), $this->parseDefinition($service, $file, new Definition()));
147147
}
@@ -192,7 +192,7 @@ private function getServiceDefaults(\DOMDocument $xml, string $file, ?\DOMNode $
192192
$xpath = new \DOMXPath($xml);
193193
$xpath->registerNamespace('container', self::NS);
194194

195-
if (null === $defaultsNode = $xpath->query('.//container:services/container:defaults', $root)->item(0)) {
195+
if (null === $defaultsNode = $xpath->query('./container:services/container:defaults', $root)->item(0)) {
196196
return new Definition();
197197
}
198198

Tests/Fixtures/RemoteCaller.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
interface RemoteCaller
15+
{
16+
}

Tests/Fixtures/RemoteCallerHttp.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
class RemoteCallerHttp implements RemoteCaller
15+
{
16+
}

Tests/Fixtures/RemoteCallerSocket.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
class RemoteCallerSocket implements RemoteCaller
15+
{
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
<services>
7+
<service id="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCaller"
8+
alias="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerHttp"/>
9+
10+
<service id="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerHttp"
11+
class="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerHttp"/>
12+
13+
<service id="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerSocket"
14+
class="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerSocket"/>
15+
</services>
16+
17+
<when env="dev">
18+
<services>
19+
<service id="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCaller"
20+
alias="Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerSocket"/>
21+
</services>
22+
</when>
23+
</container>

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;
4646
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
4747
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;
48+
use Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCaller;
49+
use Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerHttp;
50+
use Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerSocket;
4851
use Symfony\Component\ExpressionLanguage\Expression;
4952

5053
class XmlFileLoaderTest extends TestCase
@@ -1262,10 +1265,25 @@ public function testStaticConstructor()
12621265
public function testStaticConstructorWithFactoryThrows()
12631266
{
12641267
$container = new ContainerBuilder();
1265-
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
1268+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath . '/xml'));
12661269

12671270
$this->expectException(LogicException::class);
12681271
$this->expectExceptionMessage('The "static_constructor" service cannot declare a factory as well as a constructor.');
12691272
$loader->load('static_constructor_and_factory.xml');
12701273
}
1274+
1275+
public function testLoadServicesWithEnvironment()
1276+
{
1277+
$container = new ContainerBuilder();
1278+
1279+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'), 'prod');
1280+
$loader->load('when-env-services.xml');
1281+
1282+
self::assertInstanceOf(RemoteCallerHttp::class, $container->get(RemoteCaller::class));
1283+
1284+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'), 'dev');
1285+
$loader->load('when-env-services.xml');
1286+
1287+
self::assertInstanceOf(RemoteCallerSocket::class, $container->get(RemoteCaller::class));
1288+
}
12711289
}

0 commit comments

Comments
 (0)