-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add ClassMetadataFactoryInterface to allow switching implementation #11497
base: 3.2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,12 @@ | |
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\ORM\Cache\CacheConfiguration; | ||
use Doctrine\ORM\Exception\InvalidClassMetadataFactory; | ||
use Doctrine\ORM\Exception\InvalidEntityRepository; | ||
use Doctrine\ORM\Internal\Hydration\AbstractHydrator; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Doctrine\ORM\Mapping\ClassMetadataFactory; | ||
use Doctrine\ORM\Mapping\ClassMetadataFactoryInterface; | ||
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver; | ||
use Doctrine\ORM\Mapping\DefaultNamingStrategy; | ||
use Doctrine\ORM\Mapping\DefaultQuoteStrategy; | ||
|
@@ -25,6 +27,7 @@ | |
use Doctrine\Persistence\Mapping\Driver\MappingDriver; | ||
use LogicException; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use ReflectionClass; | ||
|
||
use function class_exists; | ||
use function is_a; | ||
|
@@ -375,6 +378,11 @@ public function addCustomHydrationMode(string $modeName, string $hydrator): void | |
*/ | ||
public function setClassMetadataFactoryName(string $cmfName): void | ||
{ | ||
$reflectionClass = new ReflectionClass($cmfName); | ||
if (! $reflectionClass->implementsInterface(ClassMetadataFactoryInterface::class)) { | ||
throw InvalidClassMetadataFactory::create($cmfName); | ||
} | ||
Comment on lines
+381
to
+384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would introduce an exception when there was not one before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prior to this PR a call with a class different from |
||
|
||
$this->attributes['classMetadataFactoryName'] = $cmfName; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Exception; | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadataFactoryInterface; | ||
use LogicException; | ||
|
||
use function sprintf; | ||
|
||
class InvalidClassMetadataFactory extends LogicException implements ConfigurationException | ||
{ | ||
public static function create(string $className): self | ||
{ | ||
return new self(sprintf("Invalid class metadata factory class '%s'. It must be a %s.", $className, ClassMetadataFactoryInterface::class)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\Persistence\Mapping\ClassMetadataFactory; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
/** @template-extends ClassMetadataFactory<ClassMetadata> */ | ||
interface ClassMetadataFactoryInterface extends ClassMetadataFactory | ||
{ | ||
/** | ||
* Sets the cache for created metadata. | ||
*/ | ||
public function setCache(CacheItemPoolInterface $cache): void; | ||
|
||
/** | ||
* Sets the entity manager owning the factory. | ||
*/ | ||
public function setEntityManager(EntityManagerInterface $em): void; | ||
|
||
/** | ||
* @param A $maybeOwningSide | ||
* | ||
* @return (A is ManyToManyAssociationMapping ? ManyToManyOwningSideMapping : ( | ||
* A is OneToOneAssociationMapping ? OneToOneOwningSideMapping : ( | ||
* A is OneToManyAssociationMapping ? ManyToOneAssociationMapping : ( | ||
* A is ManyToOneAssociationMapping ? ManyToOneAssociationMapping : | ||
* ManyToManyOwningSideMapping|OneToOneOwningSideMapping|ManyToOneAssociationMapping | ||
* )))) | ||
* | ||
* @template A of AssociationMapping | ||
*/ | ||
public function getOwningSide(AssociationMapping $maybeOwningSide): OwningSideMapping; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this excluded from phpcs checks? It's going to be a new interface that you can name without the superflous naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doctrine\ORM\Mapping\ClassMetadataFactory
is already used (is the name of the current implementation).Do you have a better proposal for the name of this interface?