Closed colinodell closed 4 years ago
I tried to implement it. I prefer to not use a custom error handler to detect warnings here, so I added Processor::getWarnings().
$processor = new Processor;
$schema = Expect::structure([
'old' => Expect::int()->deprecated('The option %path% is deprecated'),
]);
$processor->process($schema, ['old' => 1]);
var_dump($processor->getWarnings()); // ["The option 'old' is deprecated"]
Theoretically, this creates room for other possible warnings, not only for deprecation notes.
That implementation works for me. Thanks so much!
Problem
I would like the ability to mark certain options as being 'deprecated'. These are elements that are still currently allowed but may be removed in future versions. Using a deprecated option should cause a silenced
E_USER_DEPRECATED
error to triggered when used.Proposed implementation
Add a new method called
deprecated()
to theBase
trait - something like this:Users can then flag options as deprecated like so:
At some point during the
complete()
method call we'd raise a silenced deprecation error if any value was provided:Why a silenced error?
The
@trigger_error('...', E_USER_DEPRECATED)
pattern is borrowed from Symfony and other projects:See https://symfony.com/doc/4.4/contributing/code/conventions.html#deprecating-code for more details.
Outstanding questions
Context
too if that's desired?Am I willing to implement this?
Yes - but I could use a little guidance on the best place to put the deprecation check and how to properly determine if a value is given or omitted.