Skip to content

Commit fa1275b

Browse files
Merge branch '4.4' into 5.0
* 4.4: (21 commits) fix merge CS [FrameworkBundle][ContainerLintCommand] Improve messages when the kernel or the container is not supported [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer stop using deprecated Doctrine persistence classes [Cache] Fix wrong classname in deprecation message Fix regex lookahead syntax in ApplicationTest Fixed syntax in comment [SecurityBundle][FirewallMap] Remove unused property [Messenger][AMQP] Use delivery_mode=2 by default [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of #28462" [FrameworkBundle][Secrets] Hook configured local dotenv file [DI] Improve performance of processDefinition fix redis multi host dsn not recognized fix constructor argument type declaration Fix invalid Windows path normalization [Validator][ConstraintValidator] Safe fail on invalid timezones [DoctrineBridge] Fixed submitting invalid ids when using queries with limit [FrameworkBundle] Add info & example to auto_mapping config ...
2 parents ed03986 + fbff912 commit fa1275b

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

Command/ContainerLintCommand.php

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
use Symfony\Component\Config\ConfigCache;
1515
use Symfony\Component\Config\FileLocator;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Exception\RuntimeException;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Style\SymfonyStyle;
1921
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
2022
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
23+
use Symfony\Component\DependencyInjection\Container;
2124
use Symfony\Component\DependencyInjection\ContainerBuilder;
2225
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2326
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
27+
use Symfony\Component\HttpKernel\Kernel;
2428

2529
final class ContainerLintCommand extends Command
2630
{
@@ -47,13 +51,18 @@ protected function configure()
4751
*/
4852
protected function execute(InputInterface $input, OutputInterface $output): int
4953
{
50-
$container = $this->getContainerBuilder();
54+
$io = new SymfonyStyle($input, $output);
55+
$errorIo = $io->getErrorStyle();
5156

52-
$container->setParameter('container.build_hash', 'lint_container');
53-
$container->setParameter('container.build_time', time());
54-
$container->setParameter('container.build_id', 'lint_container');
57+
try {
58+
$container = $this->getContainerBuilder();
59+
} catch (RuntimeException $e) {
60+
$errorIo->error($e->getMessage());
61+
62+
return 2;
63+
}
5564

56-
$container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100);
65+
$container->setParameter('container.build_time', time());
5766

5867
$container->compile();
5968

@@ -67,22 +76,44 @@ private function getContainerBuilder(): ContainerBuilder
6776
}
6877

6978
$kernel = $this->getApplication()->getKernel();
79+
$kernelContainer = $kernel->getContainer();
80+
81+
if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
82+
if (!$kernel instanceof Kernel) {
83+
throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', \get_class($kernel), Kernel::class));
84+
}
7085

71-
if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
7286
$buildContainer = \Closure::bind(function (): ContainerBuilder {
7387
$this->initializeBundles();
7488

7589
return $this->buildContainer();
7690
}, $kernel, \get_class($kernel));
7791
$container = $buildContainer();
92+
93+
$skippedIds = [];
7894
} else {
79-
(new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
95+
if (!$kernelContainer instanceof Container) {
96+
throw new RuntimeException(sprintf('This command does not support the application container: "%s" does not extend "%s".', \get_class($kernelContainer), Container::class));
97+
}
98+
99+
(new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernelContainer->getParameter('debug.container.dump'));
80100

81101
$refl = new \ReflectionProperty($parameterBag, 'resolved');
82102
$refl->setAccessible(true);
83103
$refl->setValue($parameterBag, true);
104+
105+
$passConfig = $container->getCompilerPassConfig();
106+
$passConfig->setRemovingPasses([]);
107+
$passConfig->setAfterRemovingPasses([]);
108+
109+
$skippedIds = $kernelContainer->getRemovedIds();
84110
}
85111

112+
$container->setParameter('container.build_hash', 'lint_container');
113+
$container->setParameter('container.build_id', 'lint_container');
114+
115+
$container->addCompilerPass(new CheckTypeDeclarationsPass(true, $skippedIds), PassConfig::TYPE_AFTER_REMOVING, -100);
116+
86117
return $this->containerBuilder = $container;
87118
}
88119
}

DependencyInjection/Configuration.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function addSecretsSection(ArrayNodeDefinition $rootNode)
130130
->canBeDisabled()
131131
->children()
132132
->scalarNode('vault_directory')->defaultValue('%kernel.project_dir%/config/secrets/%kernel.environment%')->cannotBeEmpty()->end()
133-
->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.local')->end()
133+
->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.%kernel.environment%.local')->end()
134134
->scalarNode('decryption_env_var')->defaultValue('base64:default::SYMFONY_DECRYPTION_SECRET')->end()
135135
->end()
136136
->end()
@@ -724,6 +724,11 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
724724
->end()
725725
->end()
726726
->arrayNode('auto_mapping')
727+
->info('A collection of namespaces for which auto-mapping will be enabled.')
728+
->example([
729+
'App\\Entity\\' => [],
730+
'App\\WithSpecificLoaders\\' => ['validator.property_info_loader'],
731+
])
727732
->useAttributeAsKey('namespace')
728733
->normalizeKeys(false)
729734
->beforeNormalization()

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,9 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
13531353

13541354
$container->getDefinition('secrets.vault')->replaceArgument(0, $config['vault_directory']);
13551355

1356-
if (!$config['local_dotenv_file']) {
1356+
if ($config['local_dotenv_file']) {
1357+
$container->getDefinition('secrets.local_vault')->replaceArgument(0, $config['local_dotenv_file']);
1358+
} else {
13571359
$container->removeDefinition('secrets.local_vault');
13581360
}
13591361

Resources/config/secrets.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<services>
88
<service id="secrets.vault" class="Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault">
99
<tag name="container.env_var_loader" />
10-
<argument>%kernel.project_dir%/config/secrets/%kernel.environment%</argument>
11-
<argument>%env(base64:default::SYMFONY_DECRYPTION_SECRET)%</argument>
10+
<argument />
11+
<argument />
1212
</service>
1313

1414
<service id="secrets.local_vault" class="Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault">
15-
<argument>%kernel.project_dir%/.env.local</argument>
15+
<argument />
1616
</service>
1717
</services>
1818
</container>

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
503503
'secrets' => [
504504
'enabled' => true,
505505
'vault_directory' => '%kernel.project_dir%/config/secrets/%kernel.environment%',
506-
'local_dotenv_file' => '%kernel.project_dir%/.env.local',
506+
'local_dotenv_file' => '%kernel.project_dir%/.env.%kernel.environment%.local',
507507
'decryption_env_var' => 'base64:default::SYMFONY_DECRYPTION_SECRET',
508508
],
509509
];

0 commit comments

Comments
 (0)