diff options
Diffstat (limited to 'vendor/doctrine/deprecations/README.md')
-rw-r--r-- | vendor/doctrine/deprecations/README.md | 157 |
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 | |||
3 | A 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 | |||
10 | We recommend to collect Deprecations using a PSR logger instead of relying on | ||
11 | the global error handler. | ||
12 | |||
13 | ## Usage from consumer perspective: | ||
14 | |||
15 | Enable Doctrine deprecations to be sent to a PSR3 logger: | ||
16 | |||
17 | ```php | ||
18 | \Doctrine\Deprecations\Deprecation::enableWithPsrLogger($logger); | ||
19 | ``` | ||
20 | |||
21 | Enable Doctrine deprecations to be sent as `@trigger_error($message, E_USER_DEPRECATED)` | ||
22 | messages by setting the `DOCTRINE_DEPRECATIONS` environment variable to `trigger`. | ||
23 | Alternatively, call: | ||
24 | |||
25 | ```php | ||
26 | \Doctrine\Deprecations\Deprecation::enableWithTriggerError(); | ||
27 | ``` | ||
28 | |||
29 | If you only want to enable deprecation tracking, without logging or calling `trigger_error` | ||
30 | then set the `DOCTRINE_DEPRECATIONS` environment variable to `track`. | ||
31 | Alternatively, call: | ||
32 | |||
33 | ```php | ||
34 | \Doctrine\Deprecations\Deprecation::enableTrackingDeprecations(); | ||
35 | ``` | ||
36 | |||
37 | Tracking is enabled with all three modes and provides access to all triggered | ||
38 | deprecations and their individual count: | ||
39 | |||
40 | ```php | ||
41 | $deprecations = \Doctrine\Deprecations\Deprecation::getTriggeredDeprecations(); | ||
42 | |||
43 | foreach ($deprecations as $identifier => $count) { | ||
44 | echo $identifier . " was triggered " . $count . " times\n"; | ||
45 | } | ||
46 | ``` | ||
47 | |||
48 | ### Suppressing Specific Deprecations | ||
49 | |||
50 | Disable triggering about specific deprecations: | ||
51 | |||
52 | ```php | ||
53 | \Doctrine\Deprecations\Deprecation::ignoreDeprecations("https://link/to/deprecations-description-identifier"); | ||
54 | ``` | ||
55 | |||
56 | Disable all deprecations from a package | ||
57 | |||
58 | ```php | ||
59 | \Doctrine\Deprecations\Deprecation::ignorePackage("doctrine/orm"); | ||
60 | ``` | ||
61 | |||
62 | ### Other Operations | ||
63 | |||
64 | When used within PHPUnit or other tools that could collect multiple instances of the same deprecations | ||
65 | the deduplication can be disabled: | ||
66 | |||
67 | ```php | ||
68 | \Doctrine\Deprecations\Deprecation::withoutDeduplication(); | ||
69 | ``` | ||
70 | |||
71 | Disable deprecation tracking again: | ||
72 | |||
73 | ```php | ||
74 | \Doctrine\Deprecations\Deprecation::disable(); | ||
75 | ``` | ||
76 | |||
77 | ## Usage from a library/producer perspective: | ||
78 | |||
79 | When you want to unconditionally trigger a deprecation even when called | ||
80 | from 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 | |||
90 | If variable arguments are provided at the end, they are used with `sprintf` on | ||
91 | the 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 | |||
103 | When you want to trigger a deprecation only when it is called by a function | ||
104 | outside of the current package, but not trigger when the package itself is the cause, | ||
105 | then use: | ||
106 | |||
107 | ```php | ||
108 | \Doctrine\Deprecations\Deprecation::triggerIfCalledFromOutside( | ||
109 | "doctrine/orm", | ||
110 | "https://link/to/deprecations-description", | ||
111 | "message" | ||
112 | ); | ||
113 | ``` | ||
114 | |||
115 | Based on the issue link each deprecation message is only triggered once per | ||
116 | request. | ||
117 | |||
118 | A limited stacktrace is included in the deprecation message to find the | ||
119 | offending location. | ||
120 | |||
121 | Note: A producer/library should never call `Deprecation::enableWith` methods | ||
122 | and leave the decision how to handle deprecations to application and | ||
123 | frameworks. | ||
124 | |||
125 | ## Usage in PHPUnit tests | ||
126 | |||
127 | There is a `VerifyDeprecations` trait that you can use to make assertions on | ||
128 | the occurrence of deprecations within a test. | ||
129 | |||
130 | ```php | ||
131 | use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; | ||
132 | |||
133 | class 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 | |||
155 | An identifier for deprecations is just a link to any resource, most often a | ||
156 | Github Issue or Pull Request explaining the deprecation and potentially its | ||
157 | alternative. | ||