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

Migrate to attributes #10113

Merged
merged 6 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/en/reference/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ The attribute driver can be injected in the ``Doctrine\ORM\Configuration``:
.. code-block:: php

<?php
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;

$driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities']);
$config->setMetadataDriverImpl($driverImpl);
Expand Down
806 changes: 0 additions & 806 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

This file was deleted.

69 changes: 0 additions & 69 deletions lib/Doctrine/ORM/ORMSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@

namespace Doctrine\ORM;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use LogicException;
use Psr\Cache\CacheItemPoolInterface;
use Redis;
use RuntimeException;
Expand All @@ -22,74 +17,10 @@
use function class_exists;
use function extension_loaded;
use function md5;
use function sprintf;
use function sys_get_temp_dir;

final class ORMSetup
{
/**
* Creates a configuration with an annotation metadata driver.
*
* @deprecated Use another mapping driver.
*
* @param string[] $paths
*/
public static function createAnnotationMetadataConfiguration(
array $paths,
bool $isDevMode = false,
string|null $proxyDir = null,
CacheItemPoolInterface|null $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));

return $config;
}

/**
* 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|null $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'
. ' is not installed. Please run "composer require doctrine/annotations" or choose a different'
. ' metadata driver.',
));
}

$reader = new AnnotationReader();

if ($cache === null && class_exists(ArrayAdapter::class)) {
$cache = new ArrayAdapter();
}

if ($cache !== null) {
$reader = new PsrCachedReader($reader, $cache);
}

return new AnnotationDriver($reader, $paths);
}

/**
* Creates a configuration with an attribute metadata driver.
*
Expand Down
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:mapEmbedded\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:mapManyToMany\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:mapManyToOne\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:mapOneToMany\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:mapOneToOne\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
Expand Down
30 changes: 0 additions & 30 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,36 +482,6 @@
<code>$class-&gt;associationMappings[$fieldName]['joinColumns']</code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php">
<DocblockTypeContradiction occurrences="1">
<code>new ReflectionClass($metadata-&gt;name)</code>
</DocblockTypeContradiction>
<InvalidArgument occurrences="1"/>
<LessSpecificReturnStatement occurrences="1">
<code>$mapping</code>
</LessSpecificReturnStatement>
<MoreSpecificImplementedParamType occurrences="1">
<code>$metadata</code>
</MoreSpecificImplementedParamType>
<MoreSpecificReturnType occurrences="1"/>
<PossiblyNullArgument occurrences="1">
<code>$listenerClassName</code>
</PossiblyNullArgument>
<PossiblyUndefinedArrayOffset occurrences="2">
<code>$primaryTable['indexes']</code>
<code>$primaryTable['uniqueConstraints']</code>
</PossiblyUndefinedArrayOffset>
<RedundantConditionGivenDocblockType occurrences="1">
<code>$metadata-&gt;getReflectionClass()</code>
</RedundantConditionGivenDocblockType>
<UndefinedInterfaceMethod occurrences="5">
<code>mapEmbedded</code>
<code>mapManyToMany</code>
<code>mapManyToOne</code>
<code>mapOneToMany</code>
<code>mapOneToOne</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php">
<DocblockTypeContradiction occurrences="1">
<code>new ReflectionClass($metadata-&gt;name)</code>
Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/Performance/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Tools\SchemaTool;
Expand All @@ -30,7 +31,7 @@ public static function getEntityManager(array $schemaClassNames): EntityManagerI
$config->setProxyDir(__DIR__ . '/../Tests/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([
$config->setMetadataDriverImpl(new AttributeDriver([
realpath(__DIR__ . '/Models/Cache'),
realpath(__DIR__ . '/Models/GeoNames'),
]));
Expand All @@ -56,7 +57,7 @@ public static function makeEntityManagerWithNoResultsConnection(): EntityManager
$config->setProxyDir(__DIR__ . '/../Tests/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([
$config->setMetadataDriverImpl(new AttributeDriver([
realpath(__DIR__ . '/Models/Cache'),
realpath(__DIR__ . '/Models/Generic'),
realpath(__DIR__ . '/Models/GeoNames'),
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/Mocks/EntityManagerMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\UnitOfWork;
Expand All @@ -26,7 +27,7 @@ public function __construct(Connection $conn, Configuration|null $config = null,
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver());
$config->setMetadataDriverImpl(new AttributeDriver([]));
}

parent::__construct($conn, $config, $eventManager);
Expand Down
40 changes: 10 additions & 30 deletions tests/Doctrine/Tests/Models/CMS/CmsAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,25 @@
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\Table;

/**
* CmsAddress
*
* @Entity
* @Table(name="cms_addresses")
* @EntityListeners({"CmsAddressListener"})
*/
#[ORM\Entity]
#[ORM\Table(name: 'cms_addresses')]
#[ORM\EntityListeners(['CmsAddressListener'])]
class CmsAddress
{
/**
* @var int
* @Column(type="integer")
* @Id
* @GeneratedValue
*/
/** @var int */
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
public $id;

/**
* @var string
* @Column(length=50)
*/
/** @var string */
#[Column(length: 50)]
public $country;

/**
* @var string
* @Column(length=50)
*/
/** @var string */
#[Column(length: 50)]
public $zip;

/**
* @var string
* @Column(length=50)
*/
/** @var string */
#[Column(length: 50)]
public $city;

/**
Expand All @@ -62,11 +44,9 @@ class CmsAddress
*/
public $street;

/**
* @var CmsUser
* @OneToOne(targetEntity="CmsUser", inversedBy="address")
* @JoinColumn(referencedColumnName="id")
*/
/** @var CmsUser */
#[OneToOne(targetEntity: 'CmsUser', inversedBy: 'address')]
#[JoinColumn(referencedColumnName: 'id')]
public $user;

public function getId(): int
Expand Down
50 changes: 18 additions & 32 deletions tests/Doctrine/Tests/Models/CMS/CmsArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,36 @@
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Version;

/**
* @Entity
* @Table(name="cms_articles")
*/
#[Table(name: 'cms_articles')]
#[Entity]
class CmsArticle
{
/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
/** @var int */
#[Id]
#[Column(type: 'integer')]
#[GeneratedValue(strategy: 'AUTO')]
public $id;

/**
* @var string
* @Column(type="string", length=255)
*/
/** @var string */
#[Column(type: 'string', length: 255)]
public $topic;

/**
* @var string
* @Column(type="text")
*/
/** @var string */
#[Column(type: 'text')]
public $text;

/**
* @var CmsUser
* @ManyToOne(targetEntity="CmsUser", inversedBy="articles")
* @JoinColumn(name="user_id", referencedColumnName="id")
*/
/** @var CmsUser */
#[ManyToOne(targetEntity: 'CmsUser', inversedBy: 'articles')]
#[JoinColumn(name: 'user_id', referencedColumnName: 'id')]
public $user;

/**
* @var Collection<int, CmsComment>
* @OneToMany(targetEntity="CmsComment", mappedBy="article")
*/
/** @var Collection<int, CmsComment> */
#[OneToMany(targetEntity: 'CmsComment', mappedBy: 'article')]
public $comments;

/**
* @var int
* @Version
* @Column(type="integer")
*/
/** @var int */
#[Version]
#[Column(type: 'integer')]
public $version;

public function setAuthor(CmsUser $author): void
Expand Down
Loading