Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the mapping driver deprecations more obvious #10161

Merged
merged 4 commits into from
Oct 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,10 @@
Please switch to one of the other mapping drivers. Native attributes which PHP
supports since version 8.0 are probably your best option.

As a consequence, the following methods are deprecated:
- `ORMSetup::createAnnotationMetadataConfiguration`
- `ORMSetup::createDefaultAnnotationDriver`

## Deprecated `Doctrine\ORM\Proxy\Proxy` interface.

Use `Doctrine\Persistence\Proxy` instead to check whether proxies are initialized.
6 changes: 4 additions & 2 deletions docs/en/reference/advanced-configuration.rst
Original file line number Diff line number Diff line change
@@ -114,11 +114,13 @@ classes.
There are currently 5 available implementations:


- ``Doctrine\ORM\Mapping\Driver\AnnotationDriver``
- ``Doctrine\ORM\Mapping\Driver\AttributeDriver``
- ``Doctrine\ORM\Mapping\Driver\XmlDriver``
- ``Doctrine\ORM\Mapping\Driver\YamlDriver``
- ``Doctrine\ORM\Mapping\Driver\DriverChain``
- ``Doctrine\ORM\Mapping\Driver\AnnotationDriver`` (deprecated and will
be removed in ``doctrine/orm`` 3.0)
- ``Doctrine\ORM\Mapping\Driver\YamlDriver`` (deprecated and will be
removed in ``doctrine/orm`` 3.0)

Throughout the most part of this manual the AttributeDriver is
used in the examples. For information on the usage of the
3 changes: 2 additions & 1 deletion docs/en/reference/basic-mapping.rst
Original file line number Diff line number Diff line change
@@ -45,9 +45,10 @@ Doctrine provides several different ways to specify object-relational
mapping metadata:

- :doc:`Attributes <attributes-reference>`
- :doc:`Docblock Annotations <annotations-reference>`
- :doc:`XML <xml-mapping>`
- :doc:`PHP code <php-mapping>`
- :doc:`Docblock Annotations <annotations-reference>` (deprecated and
will be removed in ``doctrine/orm`` 3.0)
- :doc:`YAML <yaml-mapping>` (deprecated and will be removed in ``doctrine/orm`` 3.0.)

This manual will usually show mapping metadata via attributes, though
22 changes: 13 additions & 9 deletions docs/en/reference/metadata-drivers.rst
Original file line number Diff line number Diff line change
@@ -13,11 +13,16 @@ metadata:


- **XML files** (XmlDriver)
- **Class DocBlock Annotations** (AnnotationDriver)
- **Attributes** (AttributeDriver)
- **YAML files** (YamlDriver)
- **PHP Code in files or static functions** (PhpDriver)

There are also two deprecated ways to do this:

- **Class DocBlock Annotations** (AnnotationDriver)
- **YAML files** (YamlDriver)

They will be removed in 3.0, make sure to avoid them.

Something important to note about the above drivers is they are all
an intermediate step to the same end result. The mapping
information is populated to ``Doctrine\ORM\Mapping\ClassMetadata``
@@ -40,8 +45,9 @@ an entity.


If you want to use one of the included core metadata drivers you need to
configure it. If you pick the annotation driver, you will additionally
need to install ``doctrine/annotations``. All the drivers are in the
configure it. If you pick the annotation driver despite it being
deprecated, you will additionally need to install
``doctrine/annotations``. All the drivers are in the
``Doctrine\ORM\Mapping\Driver`` namespace:

.. code-block:: php
@@ -120,17 +126,17 @@ the ``FileDriver`` implementation for you to extend from:
* {@inheritdoc}
*/
protected $_fileExtension = '.dcm.ext';

/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$data = $this->_loadMappingFile($file);

// populate ClassMetadata instance from $data
}

/**
* {@inheritdoc}
*/
@@ -198,5 +204,3 @@ iterate over them:
foreach ($class->fieldMappings as $fieldMapping) {
echo $fieldMapping['fieldName'] . "\n";
}


2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public function __construct($reader, $paths = null)
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/10096',
'https://github.com/doctrine/orm/issues/10098',
'The annotation mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to the attribute or XML driver.'
);
$this->reader = $reader;
16 changes: 16 additions & 0 deletions lib/Doctrine/ORM/ORMSetup.php
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@ final class ORMSetup
/**
* Creates a configuration with an annotation metadata driver.
*
* @deprecated Use another mapping driver.
*
* @param string[] $paths
*/
public static function createAnnotationMetadataConfiguration(
@@ -39,6 +41,12 @@ public static function createAnnotationMetadataConfiguration(
?string $proxyDir = null,
?CacheItemPoolInterface $cache = null
): Configuration {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/10098',
'%s is deprecated and will be removed in Doctrine ORM 3.0',
__METHOD__
);
$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
$config->setMetadataDriverImpl(self::createDefaultAnnotationDriver($paths));

@@ -48,12 +56,20 @@ public static function createAnnotationMetadataConfiguration(
/**
* Adds a new default annotation driver with a correctly configured annotation reader.
*
* @deprecated Use another mapping driver.
*
* @param string[] $paths
*/
public static function createDefaultAnnotationDriver(
array $paths = [],
?CacheItemPoolInterface $cache = null
): AnnotationDriver {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/10098',
'%s is deprecated and will be removed in Doctrine ORM 3.0',
__METHOD__
);
if (! class_exists(AnnotationReader::class)) {
throw new LogicException(sprintf(
'The annotation metadata driver cannot be enabled because the "doctrine/annotations" library'
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@
<referencedMethod name="Doctrine\ORM\Configuration::newDefaultAnnotationDriver"/>
<referencedMethod name="Doctrine\ORM\Id\AbstractIdGenerator::generate"/>
<referencedMethod name="Doctrine\ORM\ORMInvalidArgumentException::invalidEntityName"/>
<referencedMethod name="Doctrine\ORM\ORMSetup::createDefaultAnnotationDriver"/>
<referencedMethod name="Doctrine\ORM\Query\TreeWalkerAdapter::_getQueryComponents"/>
<file name="lib/Doctrine/ORM/Query/TreeWalkerChain.php"/>
</errorLevel>