Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Allow options to be marked as deprecated #27
Comments
|
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_DEPRECATEDerror to triggered when used.Proposed implementation
Add a new method called
deprecated()to theBasetrait - 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
Contexttoo 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.