1919class DeprecationErrorHandler
2020{
2121const MODE_WEAK ='weak ' ;
22+ const MODE_WEAK_VENDORS ='weak_vendors ' ;
2223const MODE_DISABLED ='disabled ' ;
2324
2425private static $ isRegistered =false ;
@@ -28,6 +29,7 @@ class DeprecationErrorHandler
2829 *
2930 * The following reporting modes are supported:
3031 * - use "weak" to hide the deprecation report but keep a global count;
32+ * - use "weak_vendors" to act as "weak" but only for vendors;
3133 * - use "/some-regexp/" to stop the test suite whenever a deprecation
3234 * message matches the given regular expression;
3335 * - use a number to define the upper bound of allowed deprecations,
@@ -50,7 +52,10 @@ public static function register($mode = 0)
5052if (false ===$ mode ) {
5153$ mode =getenv ('SYMFONY_DEPRECATIONS_HELPER ' );
5254 }
53- if (DeprecationErrorHandler::MODE_WEAK !==$ mode && (!isset ($ mode [0 ]) ||'/ ' !==$ mode [0 ])) {
55+ if (!in_array ($ mode ,array (
56+ DeprecationErrorHandler::MODE_WEAK ,
57+ DeprecationErrorHandler::MODE_WEAK_VENDORS
58+ )) && (!isset ($ mode [0 ]) ||'/ ' !==$ mode [0 ])) {
5459$ mode =preg_match ('/^[1-9][0-9]*$/ ' ,$ mode ) ? (int )$ mode :0 ;
5560 }
5661
@@ -67,6 +72,12 @@ public static function register($mode = 0)
6772'legacy ' =>array (),
6873'other ' =>array (),
6974 );
75+ if (DeprecationErrorHandler::MODE_WEAK_VENDORS ===$ mode ) {
76+ $ deprecations +=array (
77+ 'remaining vendorCount ' =>0 ,
78+ 'remaining vendor ' =>array (),
79+ );
80+ }
7081$ deprecationHandler =function ($ type ,$ msg ,$ file ,$ line ,$ context )use (&$ deprecations ,$ getMode ) {
7182$ mode =$ getMode ();
7283if ((E_USER_DEPRECATED !==$ type &&E_DEPRECATED !==$ type ) || DeprecationErrorHandler::MODE_DISABLED ===$ mode ) {
@@ -76,6 +87,10 @@ public static function register($mode = 0)
7687$ trace =debug_backtrace (true );
7788$ group ='other ' ;
7889
90+ $ isVendor = (strpos ($ file ,'/vendor/ ' ) !==false );
91+ $ isWeak = DeprecationErrorHandler::MODE_WEAK ===$ mode ||
92+ DeprecationErrorHandler::MODE_WEAK_VENDORS ===$ mode &&$ isVendor ;
93+
7994$ i =count ($ trace );
8095while (1 <$ i && (!isset ($ trace [--$ i ]['class ' ]) || ('ReflectionMethod ' ===$ trace [$ i ]['class ' ] ||0 ===strpos ($ trace [$ i ]['class ' ],'PHPUnit_ ' )))) {
8196// No-op
@@ -94,6 +109,8 @@ public static function register($mode = 0)
94109 ||in_array ('legacy ' , \PHPUnit_Util_Test::getGroups ($ class ,$ method ),true )
95110 ) {
96111$ group ='legacy ' ;
112+ }elseif (DeprecationErrorHandler::MODE_WEAK_VENDORS ===$ mode &&$ isVendor ) {
113+ $ group ='remaining vendor ' ;
97114 }else {
98115$ group ='remaining ' ;
99116 }
@@ -112,13 +129,13 @@ public static function register($mode = 0)
112129
113130exit (1 );
114131 }
115- if ('legacy ' !==$ group &&DeprecationErrorHandler:: MODE_WEAK !== $ mode ) {
132+ if ('legacy ' !==$ group &&! $ isWeak ) {
116133$ ref = &$ deprecations [$ group ][$ msg ]['count ' ];
117134 ++$ ref ;
118135$ ref = &$ deprecations [$ group ][$ msg ][$ class .':: ' .$ method ];
119136 ++$ ref ;
120137 }
121- }elseif (DeprecationErrorHandler:: MODE_WEAK !== $ mode ) {
138+ }elseif (! $ isWeak ) {
122139$ ref = &$ deprecations [$ group ][$ msg ]['count ' ];
123140 ++$ ref ;
124141 }
@@ -162,9 +179,15 @@ public static function register($mode = 0)
162179return $ b ['count ' ] -$ a ['count ' ];
163180 };
164181
165- foreach (array ('unsilenced ' ,'remaining ' ,'legacy ' ,'other ' )as $ group ) {
182+ $ groups =array ('unsilenced ' ,'remaining ' );
183+ if (DeprecationErrorHandler::MODE_WEAK_VENDORS ===$ mode ) {
184+ $ groups [] ='remaining vendor ' ;
185+ }
186+ array_push ($ groups ,'legacy ' ,'other ' );
187+
188+ foreach ($ groupsas $ group ) {
166189if ($ deprecations [$ group .'Count ' ]) {
167- echo "\n" ,$ colorize (sprintf ('%s deprecation notices (%d) ' ,ucfirst ($ group ),$ deprecations [$ group .'Count ' ]),'legacy ' !== $ group ),"\n" ;
190+ echo "\n" ,$ colorize (sprintf ('%s deprecation notices (%d) ' ,ucfirst ($ group ),$ deprecations [$ group .'Count ' ]),! in_array ( $ group , array ( 'legacy ' , ' remaining vendor ' ), true ) ),"\n" ;
168191
169192uasort ($ deprecations [$ group ],$ cmp );
170193