@@ -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'
5556The <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