@@ -21,6 +21,7 @@ class DeprecationErrorHandler
2121 const MODE_WEAK = 'weak ' ;
2222
2323 private static $ isRegistered = false ;
24+ private static $ mode ;
2425
2526 /**
2627 * Registers and configures the deprecation handler.
@@ -39,9 +40,8 @@ public static function register($mode = 0)
3940 if (self ::$ isRegistered ) {
4041 return ;
4142 }
42- if (self ::MODE_WEAK !== $ mode && (!isset ($ mode [0 ]) || '/ ' !== $ mode [0 ])) {
43- $ mode = preg_match ('/^[1-9][0-9]*$/ ' , $ mode ) ? (int ) $ mode : 0 ;
44- }
43+ self ::$ mode = $ mode ;
44+
4545 $ deprecations = array (
4646 'unsilencedCount ' => 0 ,
4747 'remainingCount ' => 0 ,
@@ -52,11 +52,12 @@ public static function register($mode = 0)
5252 'legacy ' => array (),
5353 'other ' => array (),
5454 );
55- $ deprecationHandler = function ($ type , $ msg , $ file , $ line , $ context ) use (&$ deprecations, $ mode ) {
55+ $ deprecationHandler = function ($ type , $ msg , $ file , $ line , $ context ) use (&$ deprecations ) {
5656 if (E_USER_DEPRECATED !== $ type ) {
5757 return \PHPUnit_Util_ErrorHandler::handleError ($ type , $ msg , $ file , $ line , $ context );
5858 }
5959
60+ $ mode = self ::getMode ();
6061 $ trace = debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT );
6162
6263 $ i = count ($ trace );
@@ -101,7 +102,7 @@ public static function register($mode = 0)
101102 $ ref = &$ deprecations [$ group ][$ msg ][$ class .':: ' .$ method ];
102103 ++$ ref ;
103104 }
104- } else {
105+ } elseif ( self :: MODE_WEAK !== $ mode ) {
105106 $ group = 'other ' ;
106107 $ ref = &$ deprecations [$ group ][$ msg ]['count ' ];
107108 ++$ ref ;
@@ -116,18 +117,22 @@ public static function register($mode = 0)
116117 restore_error_handler ();
117118 self ::register ($ mode );
118119 }
119- } elseif (! isset ( $ mode [ 0 ]) || ' / ' !== $ mode [ 0 ]) {
120+ } else {
120121 self ::$ isRegistered = true ;
121- if (self ::hasColorSupport ()) {
122- $ colorize = function ($ str , $ red ) {
123- $ color = $ red ? '41;37 ' : '43;30 ' ;
122+ register_shutdown_function (function () use (&$ deprecations , $ deprecationHandler ) {
123+ $ mode = self ::getMode ();
124+ if (isset ($ mode [0 ]) && '/ ' === $ mode [0 ]) {
125+ return ;
126+ }
127+ if (DeprecationErrorHandler::MODE_WEAK !== $ mode && self ::hasColorSupport ()) {
128+ $ colorize = function ($ str , $ red ) {
129+ $ color = $ red ? '41;37 ' : '43;30 ' ;
124130
125- return "\x1B[ {$ color }m {$ str }\x1B[0m " ;
126- };
127- } else {
128- $ colorize = function ($ str ) {return $ str ;};
129- }
130- register_shutdown_function (function () use ($ mode , &$ deprecations , $ deprecationHandler , $ colorize ) {
131+ return "\x1B[ {$ color }m {$ str }\x1B[0m " ;
132+ };
133+ } else {
134+ $ colorize = function ($ str ) {return $ str ;};
135+ }
131136 $ currErrorHandler = set_error_handler ('var_dump ' );
132137 restore_error_handler ();
133138
@@ -169,6 +174,21 @@ public static function register($mode = 0)
169174 }
170175 }
171176
177+ private static function getMode ()
178+ {
179+ if (false !== self ::$ mode ) {
180+ return self ::$ mode ;
181+ }
182+
183+ $ mode = getenv ('SYMFONY_DEPRECATIONS_HELPER ' );
184+
185+ if (self ::MODE_WEAK !== $ mode && (!isset ($ mode [0 ]) || '/ ' !== $ mode [0 ])) {
186+ $ mode = preg_match ('/^[1-9][0-9]*$/ ' , $ mode ) ? (int ) $ mode : 0 ;
187+ }
188+
189+ return self ::$ mode = $ mode ;
190+ }
191+
172192 private static function hasColorSupport ()
173193 {
174194 if ('\\' === DIRECTORY_SEPARATOR ) {
0 commit comments