Skip to content

Commit d617323

Browse files
authored
Merge pull request #10161 from greg0ire/deprecate-mapping-drivers
Make the mapping driver deprecations more obvious
2 parents 6b61e26 + fba0567 commit d617323

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

UPGRADE.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
Please switch to one of the other mapping drivers. Native attributes which PHP
66
supports since version 8.0 are probably your best option.
77

8+
As a consequence, the following methods are deprecated:
9+
- `ORMSetup::createAnnotationMetadataConfiguration`
10+
- `ORMSetup::createDefaultAnnotationDriver`
11+
812
## Deprecated `Doctrine\ORM\Proxy\Proxy` interface.
913

1014
Use `Doctrine\Persistence\Proxy` instead to check whether proxies are initialized.

docs/en/reference/advanced-configuration.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ classes.
114114
There are currently 5 available implementations:
115115

116116

117-
- ``Doctrine\ORM\Mapping\Driver\AnnotationDriver``
118117
- ``Doctrine\ORM\Mapping\Driver\AttributeDriver``
119118
- ``Doctrine\ORM\Mapping\Driver\XmlDriver``
120-
- ``Doctrine\ORM\Mapping\Driver\YamlDriver``
121119
- ``Doctrine\ORM\Mapping\Driver\DriverChain``
120+
- ``Doctrine\ORM\Mapping\Driver\AnnotationDriver`` (deprecated and will
121+
be removed in ``doctrine/orm`` 3.0)
122+
- ``Doctrine\ORM\Mapping\Driver\YamlDriver`` (deprecated and will be
123+
removed in ``doctrine/orm`` 3.0)
122124

123125
Throughout the most part of this manual the AttributeDriver is
124126
used in the examples. For information on the usage of the

docs/en/reference/basic-mapping.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ Doctrine provides several different ways to specify object-relational
4545
mapping metadata:
4646

4747
- :doc:`Attributes <attributes-reference>`
48-
- :doc:`Docblock Annotations <annotations-reference>`
4948
- :doc:`XML <xml-mapping>`
5049
- :doc:`PHP code <php-mapping>`
50+
- :doc:`Docblock Annotations <annotations-reference>` (deprecated and
51+
will be removed in ``doctrine/orm`` 3.0)
5152
- :doc:`YAML <yaml-mapping>` (deprecated and will be removed in ``doctrine/orm`` 3.0.)
5253

5354
This manual will usually show mapping metadata via attributes, though

docs/en/reference/metadata-drivers.rst

+13-9
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ metadata:
1313

1414

1515
- **XML files** (XmlDriver)
16-
- **Class DocBlock Annotations** (AnnotationDriver)
1716
- **Attributes** (AttributeDriver)
18-
- **YAML files** (YamlDriver)
1917
- **PHP Code in files or static functions** (PhpDriver)
2018

19+
There are also two deprecated ways to do this:
20+
21+
- **Class DocBlock Annotations** (AnnotationDriver)
22+
- **YAML files** (YamlDriver)
23+
24+
They will be removed in 3.0, make sure to avoid them.
25+
2126
Something important to note about the above drivers is they are all
2227
an intermediate step to the same end result. The mapping
2328
information is populated to ``Doctrine\ORM\Mapping\ClassMetadata``
@@ -40,8 +45,9 @@ an entity.
4045
4146
4247
If you want to use one of the included core metadata drivers you need to
43-
configure it. If you pick the annotation driver, you will additionally
44-
need to install ``doctrine/annotations``. All the drivers are in the
48+
configure it. If you pick the annotation driver despite it being
49+
deprecated, you will additionally need to install
50+
``doctrine/annotations``. All the drivers are in the
4551
``Doctrine\ORM\Mapping\Driver`` namespace:
4652

4753
.. code-block:: php
@@ -120,17 +126,17 @@ the ``FileDriver`` implementation for you to extend from:
120126
* {@inheritdoc}
121127
*/
122128
protected $_fileExtension = '.dcm.ext';
123-
129+
124130
/**
125131
* {@inheritdoc}
126132
*/
127133
public function loadMetadataForClass($className, ClassMetadata $metadata)
128134
{
129135
$data = $this->_loadMappingFile($file);
130-
136+
131137
// populate ClassMetadata instance from $data
132138
}
133-
139+
134140
/**
135141
* {@inheritdoc}
136142
*/
@@ -198,5 +204,3 @@ iterate over them:
198204
foreach ($class->fieldMappings as $fieldMapping) {
199205
echo $fieldMapping['fieldName'] . "\n";
200206
}
201-
202-

lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($reader, $paths = null)
6464
{
6565
Deprecation::trigger(
6666
'doctrine/orm',
67-
'https://github.com/doctrine/orm/issues/10096',
67+
'https://github.com/doctrine/orm/issues/10098',
6868
'The annotation mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to the attribute or XML driver.'
6969
);
7070
$this->reader = $reader;

lib/Doctrine/ORM/ORMSetup.php

+16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ final class ORMSetup
3131
/**
3232
* Creates a configuration with an annotation metadata driver.
3333
*
34+
* @deprecated Use another mapping driver.
35+
*
3436
* @param string[] $paths
3537
*/
3638
public static function createAnnotationMetadataConfiguration(
@@ -39,6 +41,12 @@ public static function createAnnotationMetadataConfiguration(
3941
?string $proxyDir = null,
4042
?CacheItemPoolInterface $cache = null
4143
): Configuration {
44+
Deprecation::trigger(
45+
'doctrine/orm',
46+
'https://github.com/doctrine/orm/issues/10098',
47+
'%s is deprecated and will be removed in Doctrine ORM 3.0',
48+
__METHOD__
49+
);
4250
$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
4351
$config->setMetadataDriverImpl(self::createDefaultAnnotationDriver($paths));
4452

@@ -48,12 +56,20 @@ public static function createAnnotationMetadataConfiguration(
4856
/**
4957
* Adds a new default annotation driver with a correctly configured annotation reader.
5058
*
59+
* @deprecated Use another mapping driver.
60+
*
5161
* @param string[] $paths
5262
*/
5363
public static function createDefaultAnnotationDriver(
5464
array $paths = [],
5565
?CacheItemPoolInterface $cache = null
5666
): AnnotationDriver {
67+
Deprecation::trigger(
68+
'doctrine/orm',
69+
'https://github.com/doctrine/orm/issues/10098',
70+
'%s is deprecated and will be removed in Doctrine ORM 3.0',
71+
__METHOD__
72+
);
5773
if (! class_exists(AnnotationReader::class)) {
5874
throw new LogicException(sprintf(
5975
'The annotation metadata driver cannot be enabled because the "doctrine/annotations" library'

psalm.xml

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<referencedMethod name="Doctrine\ORM\Configuration::newDefaultAnnotationDriver"/>
8080
<referencedMethod name="Doctrine\ORM\Id\AbstractIdGenerator::generate"/>
8181
<referencedMethod name="Doctrine\ORM\ORMInvalidArgumentException::invalidEntityName"/>
82+
<referencedMethod name="Doctrine\ORM\ORMSetup::createDefaultAnnotationDriver"/>
8283
<referencedMethod name="Doctrine\ORM\Query\TreeWalkerAdapter::_getQueryComponents"/>
8384
<file name="lib/Doctrine/ORM/Query/TreeWalkerChain.php"/>
8485
</errorLevel>

0 commit comments

Comments
 (0)