Skip to content

Commit 9986cfe

Browse files
committed
Merge branch '7.3' into 7.4
* 7.3: Use unique identifier for RequestContextProvider [Validator] Add Japanese translation for Twig template validator fix doc url [FrameworkBundle] Fix `lint:container --resolve-env-vars`
2 parents 9977966 + 282ee04 commit 9986cfe

File tree

9 files changed

+106
-67
lines changed

9 files changed

+106
-67
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
2525
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
2626
use Symfony\Component\DependencyInjection\Compiler\ResolveFactoryClassPass;
27+
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
28+
use Symfony\Component\DependencyInjection\Container;
2729
use Symfony\Component\DependencyInjection\ContainerBuilder;
2830
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2931
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -48,8 +50,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4850
$io = new SymfonyStyle($input, $output);
4951
$errorIo = $io->getErrorStyle();
5052

53+
$resolveEnvVars = $input->getOption('resolve-env-vars');
54+
5155
try {
52-
$container = $this->getContainerBuilder();
56+
$container = $this->getContainerBuilder($resolveEnvVars);
5357
} catch (RuntimeException $e) {
5458
$errorIo->error($e->getMessage());
5559

@@ -59,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5963
$container->setParameter('container.build_time', time());
6064

6165
try {
62-
$container->compile((bool) $input->getOption('resolve-env-vars'));
66+
$container->compile($resolveEnvVars);
6367
} catch (InvalidArgumentException $e) {
6468
$errorIo->error($e->getMessage());
6569

@@ -71,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7175
return 0;
7276
}
7377

74-
private function getContainerBuilder(): ContainerBuilder
78+
private function getContainerBuilder(bool $resolveEnvVars): ContainerBuilder
7579
{
7680
if (isset($this->container)) {
7781
return $this->container;
@@ -103,17 +107,23 @@ private function getContainerBuilder(): ContainerBuilder
103107
throw new RuntimeException(\sprintf('This command does not support the application container: "%s" is not a "%s".', get_debug_type($container), ContainerBuilder::class));
104108
}
105109

106-
$parameterBag = $container->getParameterBag();
107-
$refl = new \ReflectionProperty($parameterBag, 'resolved');
108-
$refl->setValue($parameterBag, true);
110+
if ($resolveEnvVars) {
111+
$container->getCompilerPassConfig()->setOptimizationPasses([new ResolveParameterPlaceHoldersPass(), new ResolveFactoryClassPass()]);
112+
} else {
113+
$parameterBag = $container->getParameterBag();
114+
$refl = new \ReflectionProperty($parameterBag, 'resolved');
115+
$refl->setValue($parameterBag, true);
116+
117+
$container->getCompilerPassConfig()->setOptimizationPasses([new ResolveFactoryClassPass()]);
118+
}
109119

110120
$container->getCompilerPassConfig()->setBeforeOptimizationPasses([]);
111-
$container->getCompilerPassConfig()->setOptimizationPasses([new ResolveFactoryClassPass()]);
112121
$container->getCompilerPassConfig()->setBeforeRemovingPasses([]);
113122
}
114123

115124
$container->setParameter('container.build_hash', 'lint_container');
116125
$container->setParameter('container.build_id', 'lint_container');
126+
$container->setParameter('container.runtime_mode', 'web=0');
117127

118128
$container->addCompilerPass(new CheckAliasValidityPass(), PassConfig::TYPE_BEFORE_REMOVING, -100);
119129
$container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100);

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerLintCommandTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@ class ContainerLintCommandTest extends AbstractWebTestCase
2424
/**
2525
* @dataProvider containerLintProvider
2626
*/
27-
public function testLintContainer(string $configFile, string $expectedOutput)
27+
public function testLintContainer(string $configFile, bool $resolveEnvVars, int $expectedExitCode, string $expectedOutput)
2828
{
2929
$kernel = static::createKernel([
30-
'test_case' => 'ContainerDebug',
30+
'test_case' => 'ContainerLint',
3131
'root_config' => $configFile,
3232
'debug' => true,
3333
]);
3434
$this->application = new Application($kernel);
3535

3636
$tester = $this->createCommandTester();
37-
$exitCode = $tester->execute([]);
37+
$exitCode = $tester->execute(['--resolve-env-vars' => $resolveEnvVars]);
3838

39-
$this->assertSame(0, $exitCode);
39+
$this->assertSame($expectedExitCode, $exitCode);
4040
$this->assertStringContainsString($expectedOutput, $tester->getDisplay());
4141
}
4242

4343
public static function containerLintProvider(): array
4444
{
4545
return [
46-
'default container' => ['config.yml', 'The container was linted successfully'],
47-
'missing dump file' => ['no_dump.yml', 'The container was linted successfully'],
46+
['escaped_percent.yml', false, 0, 'The container was linted successfully'],
47+
['missing_env_var.yml', false, 0, 'The container was linted successfully'],
48+
['missing_env_var.yml', true, 1, 'Environment variable not found: "BAR"'],
4849
];
4950
}
5051

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
14+
15+
return [
16+
new FrameworkBundle(),
17+
new TestBundle(),
18+
];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
parameters:
5+
percent: '%%foo%%'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
parameters:
5+
foo: '%env(BAR)%'

src/Symfony/Component/JsonPath/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $result = $crawler->find("$.store.book[?(@.category == 'fiction')].title");
3535
Resources
3636
---------
3737

38-
* [Documentation](https://symfony.com/doc/current/components/dom_crawler.html)
38+
* [Documentation](https://symfony.com/doc/current/components/json_path.html)
3939
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
4040
* [Report issues](https://github.com/symfony/symfony/issues) and
4141
[send Pull Requests](https://github.com/symfony/symfony/pulls)

0 commit comments

Comments
 (0)