@@ -50,6 +50,7 @@ protected function configure()
50
50
$ this
51
51
->setDescription ('Lints a template and outputs encountered errors ' )
52
52
->addOption ('format ' , null , InputOption::VALUE_REQUIRED , 'The output format ' , 'txt ' )
53
+ ->addOption ('show-deprecations ' , null , InputOption::VALUE_NONE , 'Show deprecations as errors ' )
53
54
->addArgument ('filename ' , InputArgument::IS_ARRAY , 'A file, a directory or "-" for reading from STDIN ' )
54
55
->setHelp (<<<'EOF'
55
56
The <info>%command.name%</info> command lints a template and outputs to STDOUT
@@ -77,6 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
77
78
{
78
79
$ io = new SymfonyStyle ($ input , $ output );
79
80
$ filenames = $ input ->getArgument ('filename ' );
81
+ $ showDeprecations = $ input ->getOption ('show-deprecations ' );
80
82
81
83
if (['- ' ] === $ filenames ) {
82
84
return $ this ->display ($ input , $ output , $ io , [$ this ->validate ($ this ->getStdin (), uniqid ('sf_ ' , true ))]);
@@ -104,7 +106,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
104
106
}
105
107
}
106
108
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
+ }
108
131
109
132
return $ this ->display ($ input , $ output , $ io , $ filesInfo );
110
133
}
0 commit comments