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

Appearance settings

Commit 05428f2

Browse filesBrowse files
committed
[FrameworkBundle][ContainerLintCommand] Style messages
1 parent c2181b0 commit 05428f2
Copy full SHA for 05428f2

File tree

1 file changed

+27
-2
lines changed
Filter options

1 file changed

+27
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php
+27-2Lines changed: 27 additions & 2 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;
2123
use Symfony\Component\DependencyInjection\ContainerBuilder;
24+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
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,15 +51,32 @@ 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();
56+
57+
try {
58+
$container = $this->getContainerBuilder();
59+
} catch (RuntimeException $e) {
60+
$errorIo->error($e->getMessage());
61+
62+
return 2;
63+
}
5164

5265
$container->setParameter('container.build_hash', 'lint_container');
5366
$container->setParameter('container.build_time', time());
5467
$container->setParameter('container.build_id', 'lint_container');
5568

5669
$container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100);
5770

58-
$container->compile();
71+
try {
72+
$container->compile();
73+
} catch (InvalidArgumentException $e) {
74+
$errorIo->error($e->getMessage());
75+
76+
return 1;
77+
}
78+
79+
$errorIo->success('The injected values in the services seem to be valid.');
5980

6081
return 0;
6182
}
@@ -69,6 +90,10 @@ private function getContainerBuilder(): ContainerBuilder
6990
$kernel = $this->getApplication()->getKernel();
7091

7192
if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
93+
if (!$kernel instanceof Kernel) {
94+
throw new RuntimeException('This command does not support the application kernel.');
95+
}
96+
7297
$buildContainer = \Closure::bind(function (): ContainerBuilder {
7398
$this->initializeBundles();
7499

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.