Skip to content

Commit 6253369

Browse files
committed
feature #33961 [TwigBridge] Add show-deprecations option to the lint:twig command (yceruto)
This PR was merged into the 4.4 branch. Discussion ---------- [TwigBridge] Add show-deprecations option to the lint:twig command | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #33957 (partially) | License | MIT | Doc PR | TODO ![lint-twig-deprecations](https://user-images.githubusercontent.com/2028198/66682028-fe994e00-ec41-11e9-91f3-43885c9ee48b.png) Commits ------- a676c7e Add show-deprecations option to lint:twig command
2 parents 46e94d9 + a676c7e commit 6253369

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
`DebugCommand::__construct()` method, swap the variables position.
1010
* the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided
1111
* deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
12+
* added `--show-deprecations` option to the `lint:twig` command
1213

1314
4.3.0
1415
-----

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function configure()
5050
$this
5151
->setDescription('Lints a template and outputs encountered errors')
5252
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
53+
->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors')
5354
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
5455
->setHelp(<<<'EOF'
5556
The <info>%command.name%</info> command lints a template and outputs to STDOUT
@@ -77,6 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7778
{
7879
$io = new SymfonyStyle($input, $output);
7980
$filenames = $input->getArgument('filename');
81+
$showDeprecations = $input->getOption('show-deprecations');
8082

8183
if (['-'] === $filenames) {
8284
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
@@ -104,7 +106,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
104106
}
105107
}
106108

107-
$filesInfo = $this->getFilesInfo($filenames);
109+
if ($showDeprecations) {
110+
$prevErrorHandler = set_error_handler(static function ($level, $message, $file, $line) use (&$prevErrorHandler) {
111+
if (E_USER_DEPRECATED === $level) {
112+
$templateLine = 0;
113+
if (preg_match('/ at line (\d+) /', $message, $matches)) {
114+
$templateLine = $matches[1];
115+
}
116+
117+
throw new Error($message, $templateLine);
118+
}
119+
120+
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
121+
});
122+
}
123+
124+
try {
125+
$filesInfo = $this->getFilesInfo($filenames);
126+
} finally {
127+
if ($showDeprecations) {
128+
restore_error_handler();
129+
}
130+
}
108131

109132
return $this->display($input, $output, $io, $filesInfo);
110133
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy