You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -75,6 +76,11 @@ class OptionsResolver implements Options
75
76
*/
76
77
private$calling = array();
77
78
79
+
/**
80
+
* A list of deprecated options.
81
+
*/
82
+
private$deprecated = array();
83
+
78
84
/**
79
85
* Whether the instance is locked for reading.
80
86
*
@@ -348,6 +354,52 @@ public function getDefinedOptions()
348
354
returnarray_keys($this->defined);
349
355
}
350
356
357
+
/**
358
+
* Deprecates an option, allowed types or values.
359
+
*
360
+
* Instead of passing the message, you may also pass a closures with the
361
+
* following signature:
362
+
*
363
+
* function ($value) {
364
+
* // ...
365
+
* }
366
+
*
367
+
* The closure receives the value as argument and should return a string
368
+
* or anything else to ignore the option deprecation.
369
+
*
370
+
* The closure is invoked when {@link resolve()} is called. The parameter
371
+
* passed to the closure is the value of the option after validating it
372
+
* and before normalizing it.
373
+
*
374
+
* @param string|\Closure $deprecationMessage
375
+
*/
376
+
publicfunctionsetDeprecated(string$option, $deprecationMessage = 'The option "%name%" is deprecated.'): self
377
+
{
378
+
if ($this->locked) {
379
+
thrownewAccessException('Options cannot be deprecated from a lazy option or normalizer.');
380
+
}
381
+
382
+
if (!isset($this->defined[$option])) {
383
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
384
+
}
385
+
386
+
if (!\is_string($deprecationMessage) && !$deprecationMessageinstanceof \Closure) {
387
+
thrownewInvalidArgumentException(sprintf('Invalid type for deprecation message argument. Expected string or \Closure, but got "%s".', \gettype($deprecationMessage)));
388
+
}
389
+
390
+
$this->deprecated[$option] = $deprecationMessage;
391
+
392
+
// Make sure the option is processed
393
+
unset($this->resolved[$option]);
394
+
395
+
return$this;
396
+
}
397
+
398
+
publicfunctionisDeprecated(string$option): bool
399
+
{
400
+
returnisset($this->deprecated[$option]);
401
+
}
402
+
351
403
/**
352
404
* Sets the normalizer for an option.
353
405
*
@@ -620,6 +672,7 @@ public function clear()
620
672
$this->normalizers = array();
621
673
$this->allowedTypes = array();
622
674
$this->allowedValues = array();
675
+
$this->deprecated = array();
623
676
624
677
return$this;
625
678
}
@@ -836,6 +889,19 @@ public function offsetGet($option)
0 commit comments