Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0f581b

Browse files
fancywebnicolas-grekas
authored andcommitted
[FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass
1 parent25494fa commita0f581b

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

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

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

2529
finalclass ContainerLintCommandextends Command
2630
{
@@ -47,13 +51,18 @@ protected function configure()
4751
*/
4852
protectedfunctionexecute(InputInterface$input,OutputInterface$output):int
4953
{
50-
$container =$this->getContainerBuilder();
54+
$io =newSymfonyStyle($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+
return2;
63+
}
5564

56-
$container->addCompilerPass(newCheckTypeDeclarationsPass(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() || !(newConfigCache($kernelContainer->getParameter('debug.container.dump'),true))->isFresh()) {
82+
if (!$kernelinstanceof Kernel) {
83+
thrownewRuntimeException("This command does not support the console application's kernel.");
84+
}
7085

71-
if (!$kernel->isDebug() || !(newConfigCache($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-
(newXmlFileLoader($container =newContainerBuilder($parameterBag =newEnvPlaceholderParameterBag()),newFileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
95+
if (!$kernelContainerinstanceof Container) {
96+
thrownewRuntimeException("This command does not support the console application kernel's container.");
97+
}
98+
99+
(newXmlFileLoader($container =newContainerBuilder($parameterBag =newEnvPlaceholderParameterBag()),newFileLocator()))->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(newCheckTypeDeclarationsPass(true,$skippedIds), PassConfig::TYPE_AFTER_REMOVING, -100);
116+
86117
return$this->containerBuilder =$container;
87118
}
88119
}

‎src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,30 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
4242
privateconstSCALAR_TYPES = ['int','float','bool','string'];
4343

4444
private$autoload;
45+
private$skippedIds;
4546

4647
private$expressionLanguage;
4748

4849
/**
49-
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
50-
* Defaults to false to save loading code during compilation.
50+
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
51+
* Defaults to false to save loading code during compilation.
52+
* @param array $skippedIds An array indexed by the service ids to skip
5153
*/
52-
publicfunction__construct(bool$autoload =false)
54+
publicfunction__construct(bool$autoload =false,array$skippedIds = [])
5355
{
5456
$this->autoload =$autoload;
57+
$this->skippedIds =$skippedIds;
5558
}
5659

5760
/**
5861
* {@inheritdoc}
5962
*/
6063
protectedfunctionprocessValue($value,$isRoot =false)
6164
{
65+
if (isset($this->skippedIds[$this->currentId])) {
66+
return$value;
67+
}
68+
6269
if (!$valueinstanceof Definition ||$value->hasErrors()) {
6370
returnparent::processValue($value,$isRoot);
6471
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,16 @@ public function testProcessHandleNotFoundEnvPlaceholder()
669669

670670
$this->addToAssertionCount(1);
671671
}
672+
673+
publicfunctiontestProcessSkipSkippedIds()
674+
{
675+
$container =newContainerBuilder();
676+
$container
677+
->register('foobar', BarMethodCall::class)
678+
->addMethodCall('setArray', ['a string']);
679+
680+
(newCheckTypeDeclarationsPass(true, ['foobar' =>true]))->process($container);
681+
682+
$this->addToAssertionCount(1);
683+
}
672684
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp