summaryrefslogtreecommitdiff
path: root/vendor/doctrine/deprecations/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/deprecations/README.md')
-rw-r--r--vendor/doctrine/deprecations/README.md157
1 files changed, 157 insertions, 0 deletions
diff --git a/vendor/doctrine/deprecations/README.md b/vendor/doctrine/deprecations/README.md
new file mode 100644
index 0000000..93caf83
--- /dev/null
+++ b/vendor/doctrine/deprecations/README.md
@@ -0,0 +1,157 @@
1# Doctrine Deprecations
2
3A small (side-effect free by default) layer on top of
4`trigger_error(E_USER_DEPRECATED)` or PSR-3 logging.
5
6- no side-effects by default, making it a perfect fit for libraries that don't know how the error handler works they operate under
7- options to avoid having to rely on error handlers global state by using PSR-3 logging
8- deduplicate deprecation messages to avoid excessive triggering and reduce overhead
9
10We recommend to collect Deprecations using a PSR logger instead of relying on
11the global error handler.
12
13## Usage from consumer perspective:
14
15Enable Doctrine deprecations to be sent to a PSR3 logger:
16
17```php
18\Doctrine\Deprecations\Deprecation::enableWithPsrLogger($logger);
19```
20
21Enable Doctrine deprecations to be sent as `@trigger_error($message, E_USER_DEPRECATED)`
22messages by setting the `DOCTRINE_DEPRECATIONS` environment variable to `trigger`.
23Alternatively, call:
24
25```php
26\Doctrine\Deprecations\Deprecation::enableWithTriggerError();
27```
28
29If you only want to enable deprecation tracking, without logging or calling `trigger_error`
30then set the `DOCTRINE_DEPRECATIONS` environment variable to `track`.
31Alternatively, call:
32
33```php
34\Doctrine\Deprecations\Deprecation::enableTrackingDeprecations();
35```
36
37Tracking is enabled with all three modes and provides access to all triggered
38deprecations and their individual count:
39
40```php
41$deprecations = \Doctrine\Deprecations\Deprecation::getTriggeredDeprecations();
42
43foreach ($deprecations as $identifier => $count) {
44 echo $identifier . " was triggered " . $count . " times\n";
45}
46```
47
48### Suppressing Specific Deprecations
49
50Disable triggering about specific deprecations:
51
52```php
53\Doctrine\Deprecations\Deprecation::ignoreDeprecations("https://link/to/deprecations-description-identifier");
54```
55
56Disable all deprecations from a package
57
58```php
59\Doctrine\Deprecations\Deprecation::ignorePackage("doctrine/orm");
60```
61
62### Other Operations
63
64When used within PHPUnit or other tools that could collect multiple instances of the same deprecations
65the deduplication can be disabled:
66
67```php
68\Doctrine\Deprecations\Deprecation::withoutDeduplication();
69```
70
71Disable deprecation tracking again:
72
73```php
74\Doctrine\Deprecations\Deprecation::disable();
75```
76
77## Usage from a library/producer perspective:
78
79When you want to unconditionally trigger a deprecation even when called
80from the library itself then the `trigger` method is the way to go:
81
82```php
83\Doctrine\Deprecations\Deprecation::trigger(
84 "doctrine/orm",
85 "https://link/to/deprecations-description",
86 "message"
87);
88```
89
90If variable arguments are provided at the end, they are used with `sprintf` on
91the message.
92
93```php
94\Doctrine\Deprecations\Deprecation::trigger(
95 "doctrine/orm",
96 "https://github.com/doctrine/orm/issue/1234",
97 "message %s %d",
98 "foo",
99 1234
100);
101```
102
103When you want to trigger a deprecation only when it is called by a function
104outside of the current package, but not trigger when the package itself is the cause,
105then use:
106
107```php
108\Doctrine\Deprecations\Deprecation::triggerIfCalledFromOutside(
109 "doctrine/orm",
110 "https://link/to/deprecations-description",
111 "message"
112);
113```
114
115Based on the issue link each deprecation message is only triggered once per
116request.
117
118A limited stacktrace is included in the deprecation message to find the
119offending location.
120
121Note: A producer/library should never call `Deprecation::enableWith` methods
122and leave the decision how to handle deprecations to application and
123frameworks.
124
125## Usage in PHPUnit tests
126
127There is a `VerifyDeprecations` trait that you can use to make assertions on
128the occurrence of deprecations within a test.
129
130```php
131use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
132
133class MyTest extends TestCase
134{
135 use VerifyDeprecations;
136
137 public function testSomethingDeprecation()
138 {
139 $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issue/1234');
140
141 triggerTheCodeWithDeprecation();
142 }
143
144 public function testSomethingDeprecationFixed()
145 {
146 $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/issue/1234');
147
148 triggerTheCodeWithoutDeprecation();
149 }
150}
151```
152
153## What is a deprecation identifier?
154
155An identifier for deprecations is just a link to any resource, most often a
156Github Issue or Pull Request explaining the deprecation and potentially its
157alternative.