diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index 6004444ee5a6f..a86faea00b338 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -9,6 +9,7 @@ CHANGELOG `DebugCommand::__construct()` method, swap the variables position. * the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided * deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit. + * added `--show-deprecations` option to the `lint:twig` command 4.3.0 ----- diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index f3e718c0a4a94..be49df5fdf0c3 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -50,6 +50,7 @@ protected function configure() $this ->setDescription('Lints a template and outputs encountered errors') ->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt') + ->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors') ->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN') ->setHelp(<<<'EOF' The %command.name% command lints a template and outputs to STDOUT @@ -77,6 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $filenames = $input->getArgument('filename'); + $showDeprecations = $input->getOption('show-deprecations'); if (['-'] === $filenames) { return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]); @@ -104,7 +106,28 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - $filesInfo = $this->getFilesInfo($filenames); + if ($showDeprecations) { + $prevErrorHandler = set_error_handler(static function ($level, $message, $file, $line) use (&$prevErrorHandler) { + if (E_USER_DEPRECATED === $level) { + $templateLine = 0; + if (preg_match('/ at line (\d+) /', $message, $matches)) { + $templateLine = $matches[1]; + } + + throw new Error($message, $templateLine); + } + + return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false; + }); + } + + try { + $filesInfo = $this->getFilesInfo($filenames); + } finally { + if ($showDeprecations) { + restore_error_handler(); + } + } return $this->display($input, $output, $io, $filesInfo); } 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