@@ -46,8 +46,8 @@ class Deprecation
46
46
private const TYPE_TRIGGER_ERROR = 2 ;
47
47
private const TYPE_PSR_LOGGER = 4 ;
48
48
49
- /** @var int */
50
- private static $ type = self :: TYPE_NONE ;
49
+ /** @var self::TYPE_*|null */
50
+ private static $ type ;
51
51
52
52
/** @var LoggerInterface|null */
53
53
private static $ logger ;
@@ -72,7 +72,9 @@ class Deprecation
72
72
*/
73
73
public static function trigger (string $ package , string $ link , string $ message , ...$ args ): void
74
74
{
75
- if (self ::$ type === self ::TYPE_NONE ) {
75
+ $ type = self ::$ type ?? self ::getTypeFromEnv ();
76
+
77
+ if ($ type === self ::TYPE_NONE ) {
76
78
return ;
77
79
}
78
80
@@ -118,7 +120,9 @@ public static function trigger(string $package, string $link, string $message, .
118
120
*/
119
121
public static function triggerIfCalledFromOutside (string $ package , string $ link , string $ message , ...$ args ): void
120
122
{
121
- if (self ::$ type === self ::TYPE_NONE ) {
123
+ $ type = self ::$ type ?? self ::getTypeFromEnv ();
124
+
125
+ if ($ type === self ::TYPE_NONE ) {
122
126
return ;
123
127
}
124
128
@@ -161,7 +165,9 @@ public static function triggerIfCalledFromOutside(string $package, string $link,
161
165
*/
162
166
private static function delegateTriggerToBackend (string $ message , array $ backtrace , string $ link , string $ package ): void
163
167
{
164
- if ((self ::$ type & self ::TYPE_PSR_LOGGER ) > 0 ) {
168
+ $ type = self ::$ type ?? self ::getTypeFromEnv ();
169
+
170
+ if (($ type & self ::TYPE_PSR_LOGGER ) > 0 ) {
165
171
$ context = [
166
172
'file ' => $ backtrace [0 ]['file ' ],
167
173
'line ' => $ backtrace [0 ]['line ' ],
@@ -172,7 +178,7 @@ private static function delegateTriggerToBackend(string $message, array $backtra
172
178
self ::$ logger ->notice ($ message , $ context );
173
179
}
174
180
175
- if (! ((self :: $ type & self ::TYPE_TRIGGER_ERROR ) > 0 )) {
181
+ if (! (($ type & self ::TYPE_TRIGGER_ERROR ) > 0 )) {
176
182
return ;
177
183
}
178
184
@@ -263,4 +269,26 @@ public static function getTriggeredDeprecations(): array
263
269
{
264
270
return self ::$ ignoredLinks ;
265
271
}
272
+
273
+ /**
274
+ * @return self::TYPE_*
275
+ */
276
+ private static function getTypeFromEnv (): int
277
+ {
278
+ switch ($ _SERVER ['DOCTRINE_DEPRECATIONS ' ] ?? $ _ENV ['DOCTRINE_DEPRECATIONS ' ] ?? null ) {
279
+ case 'trigger ' :
280
+ self ::$ type = self ::TYPE_TRIGGER_ERROR ;
281
+ break ;
282
+
283
+ case 'track ' :
284
+ self ::$ type = self ::TYPE_TRACK_DEPRECATIONS ;
285
+ break ;
286
+
287
+ default :
288
+ self ::$ type = self ::TYPE_NONE ;
289
+ break ;
290
+ }
291
+
292
+ return self ::$ type ;
293
+ }
266
294
}
0 commit comments