Skip to content

Commit 6d49292

Browse files
authored
Remove deprecated APIs (#468)
1 parent e29955f commit 6d49292

File tree

12 files changed

+14
-1382
lines changed

12 files changed

+14
-1382
lines changed

UPGRADE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Upgrade from 1.0.x to 2.0.x
22

3-
`DocLexer::peek()` and `DocLexer::glimpse` now return
3+
- `DocLexer::peek()` and `DocLexer::glimpse` now return
44
`Doctrine\Common\Lexer\Token` objects. When using `doctrine/lexer` 2, these
55
implement `ArrayAccess` as a way for you to still be able to treat them as
66
arrays in some ways.
7+
- `CachedReader` and `FileCacheReader` have been removed.
8+
- `AnnotationRegistry` method related to registering annotations instead of
9+
using autoloading have been removed.

docs/en/annotations.rst

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,11 @@ with Doctrine Annotations requires this setup:
7979
.. code-block:: php
8080
8181
use Doctrine\Common\Annotations\AnnotationReader;
82-
use Doctrine\Common\Annotations\AnnotationRegistry;
83-
84-
AnnotationRegistry::registerFile("/path/to/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
85-
AnnotationRegistry::registerAutoloadNamespace("Symfony\Component\Validator\Constraint", "/path/to/symfony/src");
86-
AnnotationRegistry::registerAutoloadNamespace("MyProject\Annotations", "/path/to/myproject/src");
8782
8883
$reader = new AnnotationReader();
8984
AnnotationReader::addGlobalIgnoredName('dummy');
9085
91-
The second block with the annotation registry calls registers all the
92-
three different annotation namespaces that are used.
93-
Doctrine Annotations saves all its annotations in a single file, that is
94-
why ``AnnotationRegistry#registerFile`` is used in contrast to
95-
``AnnotationRegistry#registerAutoloadNamespace`` which creates a PSR-0
96-
compatible loading mechanism for class to file names.
97-
98-
In the third block, we create the actual ``AnnotationReader`` instance.
86+
We create the actual ``AnnotationReader`` instance.
9987
Note that we also add ``dummy`` to the global list of ignored
10088
annotations for which we do not throw exceptions. Setting this is
10189
necessary in our example case, otherwise ``@dummy`` would trigger an
@@ -165,57 +153,6 @@ class name you can wrap the reader in an ``IndexedReader``:
165153
indexed or numeric keys, otherwise your code may experience failures
166154
due to caching in a numerical or indexed format.
167155

168-
Registering Annotations
169-
~~~~~~~~~~~~~~~~~~~~~~~
170-
171-
As explained in the introduction, Doctrine Annotations uses its own
172-
autoloading mechanism to determine if a given annotation has a
173-
corresponding PHP class that can be autoloaded. For annotation
174-
autoloading you have to configure the
175-
``Doctrine\Common\Annotations\AnnotationRegistry``. There are three
176-
different mechanisms to configure annotation autoloading:
177-
178-
- Calling ``AnnotationRegistry#registerFile($file)`` to register a file
179-
that contains one or more annotation classes.
180-
- Calling ``AnnotationRegistry#registerNamespace($namespace, $dirs =
181-
null)`` to register that the given namespace contains annotations and
182-
that their base directory is located at the given $dirs or in the
183-
include path if ``NULL`` is passed. The given directories should *NOT*
184-
be the directory where classes of the namespace are in, but the base
185-
directory of the root namespace. The AnnotationRegistry uses a
186-
namespace to directory separator approach to resolve the correct path.
187-
- Calling ``AnnotationRegistry#registerLoader($callable)`` to register
188-
an autoloader callback. The callback accepts the class as first and
189-
only parameter and has to return ``true`` if the corresponding file
190-
was found and included.
191-
192-
.. note::
193-
194-
Loaders have to fail silently, if a class is not found even if it
195-
matches for example the namespace prefix of that loader. Never is a
196-
loader to throw a warning or exception if the loading failed
197-
otherwise parsing doc block annotations will become a huge pain.
198-
199-
A sample loader callback could look like:
200-
201-
.. code-block:: php
202-
203-
use Doctrine\Common\Annotations\AnnotationRegistry;
204-
use Symfony\Component\ClassLoader\UniversalClassLoader;
205-
206-
AnnotationRegistry::registerLoader(function($class) {
207-
$file = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
208-
209-
if (file_exists("/my/base/path/" . $file)) {
210-
// file_exists() makes sure that the loader fails silently
211-
require "/my/base/path/" . $file;
212-
}
213-
});
214-
215-
$loader = new UniversalClassLoader();
216-
AnnotationRegistry::registerLoader(array($loader, "loadClass"));
217-
218-
219156
Ignoring missing exceptions
220157
~~~~~~~~~~~~~~~~~~~~~~~~~~~
221158

docs/en/custom.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Custom Annotation Classes
22
=========================
33

44
If you want to define your own annotations, you just have to group them
5-
in a namespace and register this namespace in the ``AnnotationRegistry``.
5+
in a namespace.
66
Annotation classes have to contain a class-level docblock with the text
77
``@Annotation``:
88

@@ -58,10 +58,10 @@ Optional: Constructors with Named Parameters
5858

5959
Starting with Annotations v1.11 a new annotation instantiation strategy
6060
is available that aims at compatibility of Annotation classes with the PHP 8
61-
attribute feature. You need to declare a constructor with regular parameter
61+
attribute feature. You need to declare a constructor with regular parameter
6262
names that match the named arguments in the annotation syntax.
6363

64-
To enable this feature, you can tag your annotation class with
64+
To enable this feature, you can tag your annotation class with
6565
``@NamedArgumentConstructor`` (available from v1.12) or implement the
6666
``Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation`` interface
6767
(available from v1.11 and deprecated as of v1.12).
@@ -75,8 +75,8 @@ Usage with the ``@NamedArgumentConstructor`` tag
7575
7676
namespace MyCompany\Annotations;
7777
78-
/**
79-
* @Annotation
78+
/**
79+
* @Annotation
8080
* @NamedArgumentConstructor
8181
*/
8282
class Bar implements NamedArgumentConstructorAnnotation
@@ -99,8 +99,8 @@ you can simplify this to:
9999
100100
namespace MyCompany\Annotations;
101101
102-
/**
103-
* @Annotation
102+
/**
103+
* @Annotation
104104
* @NamedArgumentConstructor
105105
*/
106106
class Bar implements NamedArgumentConstructorAnnotation
@@ -109,7 +109,7 @@ you can simplify this to:
109109
}
110110
111111
112-
Usage with the
112+
Usage with the
113113
``Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation``
114114
interface (v1.11, deprecated as of v1.12):
115115
.. code-block:: php

docs/en/index.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ annotations of a class. A common one is
7373
.. code-block:: php
7474
7575
use Doctrine\Common\Annotations\AnnotationReader;
76-
use Doctrine\Common\Annotations\AnnotationRegistry;
77-
78-
// Deprecated and will be removed in 2.0 but currently needed
79-
AnnotationRegistry::registerLoader('class_exists');
8076
8177
$reflectionClass = new ReflectionClass(Foo::class);
8278
$property = $reflectionClass->getProperty('bar');
@@ -89,10 +85,6 @@ annotations of a class. A common one is
8985
9086
echo $myAnnotation->myProperty; // result: "value"
9187
92-
Note that ``AnnotationRegistry::registerLoader('class_exists')`` only works
93-
if you already have an autoloader configured (i.e. composer autoloader).
94-
Otherwise, :ref:`please take a look to the other annotation autoload mechanisms <annotations>`.
95-
9688
A reader has multiple methods to access the annotations of a class or
9789
function.
9890

lib/Doctrine/Common/Annotations/AnnotationRegistry.php

Lines changed: 1 addition & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -3,131 +3,20 @@
33
namespace Doctrine\Common\Annotations;
44

55
use function array_key_exists;
6-
use function array_merge;
76
use function class_exists;
8-
use function in_array;
9-
use function is_file;
10-
use function str_replace;
11-
use function stream_resolve_include_path;
12-
use function strpos;
13-
14-
use const DIRECTORY_SEPARATOR;
157

168
final class AnnotationRegistry
179
{
18-
/**
19-
* A map of namespaces to use for autoloading purposes based on a PSR-0 convention.
20-
*
21-
* Contains the namespace as key and an array of directories as value. If the value is NULL
22-
* the include path is used for checking for the corresponding file.
23-
*
24-
* This autoloading mechanism does not utilize the PHP autoloading but implements autoloading on its own.
25-
*
26-
* @var string[][]|string[]|null[]
27-
*/
28-
private static $autoloadNamespaces = [];
29-
30-
/**
31-
* A map of autoloader callables.
32-
*
33-
* @var callable[]
34-
*/
35-
private static $loaders = [];
36-
3710
/**
3811
* An array of classes which cannot be found
3912
*
4013
* @var null[] indexed by class name
4114
*/
4215
private static $failedToAutoload = [];
4316

44-
/**
45-
* Whenever registerFile() was used. Disables use of standard autoloader.
46-
*
47-
* @var bool
48-
*/
49-
private static $registerFileUsed = false;
50-
5117
public static function reset(): void
5218
{
53-
self::$autoloadNamespaces = [];
54-
self::$loaders = [];
55-
self::$failedToAutoload = [];
56-
self::$registerFileUsed = false;
57-
}
58-
59-
/**
60-
* Registers file.
61-
*
62-
* @deprecated This method is deprecated and will be removed in
63-
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
64-
*/
65-
public static function registerFile(string $file): void
66-
{
67-
self::$registerFileUsed = true;
68-
69-
require_once $file;
70-
}
71-
72-
/**
73-
* Adds a namespace with one or many directories to look for files or null for the include path.
74-
*
75-
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
76-
*
77-
* @deprecated This method is deprecated and will be removed in
78-
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
79-
*
80-
* @phpstan-param string|list<string>|null $dirs
81-
*/
82-
public static function registerAutoloadNamespace(string $namespace, $dirs = null): void
83-
{
84-
self::$autoloadNamespaces[$namespace] = $dirs;
85-
}
86-
87-
/**
88-
* Registers multiple namespaces.
89-
*
90-
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
91-
*
92-
* @deprecated This method is deprecated and will be removed in
93-
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
94-
*
95-
* @param string[][]|string[]|null[] $namespaces indexed by namespace name
96-
*/
97-
public static function registerAutoloadNamespaces(array $namespaces): void
98-
{
99-
self::$autoloadNamespaces = array_merge(self::$autoloadNamespaces, $namespaces);
100-
}
101-
102-
/**
103-
* Registers an autoloading callable for annotations, much like spl_autoload_register().
104-
*
105-
* NOTE: These class loaders HAVE to be silent when a class was not found!
106-
* IMPORTANT: Loaders have to return true if they loaded a class that could contain the searched annotation class.
107-
*
108-
* @deprecated This method is deprecated and will be removed in
109-
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
110-
*/
111-
public static function registerLoader(callable $callable): void
112-
{
113-
// Reset our static cache now that we have a new loader to work with
11419
self::$failedToAutoload = [];
115-
self::$loaders[] = $callable;
116-
}
117-
118-
/**
119-
* Registers an autoloading callable for annotations, if it is not already registered
120-
*
121-
* @deprecated This method is deprecated and will be removed in
122-
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
123-
*/
124-
public static function registerUniqueLoader(callable $callable): void
125-
{
126-
if (in_array($callable, self::$loaders, true)) {
127-
return;
128-
}
129-
130-
self::registerLoader($callable);
13120
}
13221

13322
/**
@@ -143,43 +32,7 @@ public static function loadAnnotationClass(string $class): bool
14332
return false;
14433
}
14534

146-
foreach (self::$autoloadNamespaces as $namespace => $dirs) {
147-
if (strpos($class, $namespace) !== 0) {
148-
continue;
149-
}
150-
151-
$file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
152-
153-
if ($dirs === null) {
154-
$path = stream_resolve_include_path($file);
155-
if ($path) {
156-
require $path;
157-
158-
return true;
159-
}
160-
} else {
161-
foreach ((array) $dirs as $dir) {
162-
if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
163-
require $dir . DIRECTORY_SEPARATOR . $file;
164-
165-
return true;
166-
}
167-
}
168-
}
169-
}
170-
171-
foreach (self::$loaders as $loader) {
172-
if ($loader($class) === true) {
173-
return true;
174-
}
175-
}
176-
177-
if (
178-
self::$loaders === [] &&
179-
self::$autoloadNamespaces === [] &&
180-
self::$registerFileUsed === false &&
181-
class_exists($class)
182-
) {
35+
if (class_exists($class)) {
18336
return true;
18437
}
18538

0 commit comments

Comments
 (0)