Deprecation
in package
Manages Deprecation logging in different ways.
By default triggered exceptions are not logged.
To enable different deprecation logging mechanisms you can call the following methods:
-
Minimal collection of deprecations via getTriggeredDeprecations() \Doctrine\Deprecations\Deprecation::enableTrackingDeprecations();
-
Uses @trigger_error with E_USER_DEPRECATED \Doctrine\Deprecations\Deprecation::enableWithTriggerError();
-
Sends deprecation messages via a PSR-3 logger \Doctrine\Deprecations\Deprecation::enableWithPsrLogger($logger);
Packages that trigger deprecations should use the trigger()
or
triggerIfCalledFromOutside()
methods.
Table of Contents
- TYPE_NONE = 0
- TYPE_PSR_LOGGER = 4
- TYPE_TRACK_DEPRECATIONS = 1
- TYPE_TRIGGER_ERROR = 2
- $deduplication : bool
- $ignoredLinks : array<string, bool>
- $ignoredPackages : array<string, bool>
- $logger : LoggerInterface|null
- $triggeredDeprecations : array<string, int>
- $type : mixed
- disable() : void
- enableTrackingDeprecations() : void
- enableWithPsrLogger() : void
- enableWithTriggerError() : void
- getTriggeredDeprecations() : array<string, int>
- Returns each triggered deprecation link identifier and the amount of occurrences.
- getUniqueTriggeredDeprecationsCount() : int
- ignoreDeprecations() : void
- ignorePackage() : void
- trigger() : void
- Trigger a deprecation for the given package and identfier.
- triggerIfCalledFromOutside() : void
- Trigger a deprecation for the given package and identifier when called from outside.
- withoutDeduplication() : void
- basename() : string
- A non-local-aware version of PHPs basename function.
- delegateTriggerToBackend() : void
- getTypeFromEnv() : int
Constants
TYPE_NONE
private
mixed
TYPE_NONE
= 0
TYPE_PSR_LOGGER
private
mixed
TYPE_PSR_LOGGER
= 4
TYPE_TRACK_DEPRECATIONS
private
mixed
TYPE_TRACK_DEPRECATIONS
= 1
TYPE_TRIGGER_ERROR
private
mixed
TYPE_TRIGGER_ERROR
= 2
Properties
$deduplication
private
static bool
$deduplication
= true
$ignoredLinks
private
static array<string, bool>
$ignoredLinks
= []
$ignoredPackages
private
static array<string, bool>
$ignoredPackages
= []
$logger
private
static LoggerInterface|null
$logger
$triggeredDeprecations
private
static array<string, int>
$triggeredDeprecations
= []
$type
private
static mixed
$type
int-mask-ofself::TYPE_*|null
Methods
disable()
public
static disable() : void
Return values
void —enableTrackingDeprecations()
public
static enableTrackingDeprecations() : void
Return values
void —enableWithPsrLogger()
public
static enableWithPsrLogger(LoggerInterface $logger) : void
Parameters
- $logger : LoggerInterface
Return values
void —enableWithTriggerError()
public
static enableWithTriggerError() : void
Return values
void —getTriggeredDeprecations()
Returns each triggered deprecation link identifier and the amount of occurrences.
public
static getTriggeredDeprecations() : array<string, int>
Return values
array<string, int> —getUniqueTriggeredDeprecationsCount()
public
static getUniqueTriggeredDeprecationsCount() : int
Return values
int —ignoreDeprecations()
public
static ignoreDeprecations(string ...$links) : void
Parameters
- $links : string
Return values
void —ignorePackage()
public
static ignorePackage(string $packageName) : void
Parameters
- $packageName : string
Return values
void —trigger()
Trigger a deprecation for the given package and identfier.
public
static trigger(string $package, string $link, string $message, float|int|string ...$args) : void
The link should point to a Github issue or Wiki entry detailing the deprecation. It is additionally used to de-duplicate the trigger of the same deprecation during a request.
Parameters
- $package : string
- $link : string
- $message : string
- $args : float|int|string
Return values
void —triggerIfCalledFromOutside()
Trigger a deprecation for the given package and identifier when called from outside.
public
static triggerIfCalledFromOutside(string $package, string $link, string $message, float|int|string ...$args) : void
"Outside" means we assume that $package is currently installed as a dependency and the caller is not a file in that package. When $package is installed as a root package then deprecations triggered from the tests folder are also considered "outside".
This deprecation method assumes that you are using Composer to install the dependency and are using the default /vendor/ folder and not a Composer plugin to change the install location. The assumption is also that $package is the exact composer packge name.
Compared to this method causes some overhead when deprecation tracking is enabled even during deduplication, because it needs to call
Parameters
- $package : string
- $link : string
- $message : string
- $args : float|int|string
Return values
void —withoutDeduplication()
public
static withoutDeduplication() : void
Return values
void —basename()
A non-local-aware version of PHPs basename function.
private
static basename(string $filename) : string
Parameters
- $filename : string
Return values
string —delegateTriggerToBackend()
private
static delegateTriggerToBackend(string $message, array<int, array{function: string, line?: int, file?: string, class?: class-string, type?: string, args?: array, object?: object}> $backtrace, string $link, string $package) : void
Parameters
- $message : string
- $backtrace : array<int, array{function: string, line?: int, file?: string, class?: class-string, type?: string, args?: array, object?: object}>
- $link : string
- $package : string
Return values
void —getTypeFromEnv()
private
static getTypeFromEnv() : int