Doctrine/Deprecations is a small package that operates as a layer above trigger_error(E_USER_DEPRECATED)
or PSR-3 logging. This PHP library provides additional functionality with less side-effects, allowing for the ability to disable all or specific deprecations for packages. This helps developers in dealing with deprecated code and preparing for future updates, in a more efficient, less error-prone way.
Using Doctrine/Deprecations involves several key methods and environments settings. At the basic level, to enable Doctrine deprecations to be sent to a PSR3 logger, you can run:
\Doctrine\Deprecations\Deprecation::enableWithPsrLogger($logger);
To allow the deprecations to be sent as @trigger_error messages, you should set the DOCTRINE_DEPRECATIONS environment variable to 'trigger', or simply call:
\Doctrine\Deprecations\Deprecation::enableWithTriggerError();
To disable deprecations for specific packages or identifiers, use the ignoreDeprecations
and ignorePackage
methods as shown:
\Doctrine\Deprecations\Deprecation::ignoreDeprecations("https://link/to/deprecations-description-identifier");
\Doctrine\Deprecations\Deprecation::ignorePackage("doctrine/orm");
To trigger a deprecation, the trigger
and triggerIfCalledFromOutside
methods can be used:
\Doctrine\Deprecations\Deprecation::trigger(
"doctrine/orm",
"https://link/to/deprecations-description",
"message"
);
Note: Replace "https://link/to/deprecations-description"
and "message"
with the appropriate deprecation description and message.
The documentation for Doctrine/Deprecations can be found within the README file in the package's GitHub repository at https://github.com/doctrine/deprecations
. This documentation provides a comprehensive view of the functionalities available in the library, useful code snippets, and guidelines for usage scenarios including PHPUnit tests.