-
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
Implement colocated mapping driver #9587
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 |
---|---|---|
|
@@ -5,13 +5,16 @@ | |
namespace Doctrine\ORM\Mapping\Driver; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Doctrine\Common\Annotations\Reader; | ||
use Doctrine\Deprecations\Deprecation; | ||
use Doctrine\ORM\Events; | ||
use Doctrine\ORM\Mapping; | ||
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; | ||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Doctrine\ORM\Mapping\MappingException; | ||
use Doctrine\Persistence\Mapping\ClassMetadata; | ||
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver; | ||
use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver; | ||
use Doctrine\Persistence\Mapping\Driver\MappingDriver; | ||
use ReflectionClass; | ||
use ReflectionMethod; | ||
use ReflectionProperty; | ||
|
@@ -29,8 +32,19 @@ | |
/** | ||
* The AnnotationDriver reads the mapping metadata from docblock annotations. | ||
*/ | ||
class AnnotationDriver extends AbstractAnnotationDriver | ||
class AnnotationDriver implements MappingDriver | ||
{ | ||
use ColocatedMappingDriver; | ||
|
||
/** | ||
* The annotation reader. | ||
* | ||
* @internal this property will be private in 3.0 | ||
* | ||
* @var Reader | ||
*/ | ||
protected $reader; | ||
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. Shall we flag the property as 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. Shouldn't we deprecate |
||
|
||
/** | ||
* @var int[] | ||
* @psalm-var array<class-string, int> | ||
|
@@ -40,6 +54,20 @@ class AnnotationDriver extends AbstractAnnotationDriver | |
Mapping\MappedSuperclass::class => 2, | ||
]; | ||
|
||
/** | ||
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading | ||
* docblock annotations. | ||
* | ||
* @param Reader $reader The AnnotationReader to use | ||
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. why not using an actual parameter type ? 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. That would be a BC break. The old constructor explicitly mentioned the possibility of duck-typed annotation readers. |
||
* @param string|string[]|null $paths One or multiple paths where mapping classes can be found. | ||
*/ | ||
public function __construct($reader, $paths = null) | ||
{ | ||
$this->reader = $reader; | ||
|
||
$this->addPaths((array) $paths); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
@@ -786,6 +814,39 @@ private function columnToArray(string $fieldName, Mapping\Column $column): array | |
return $mapping; | ||
} | ||
|
||
/** | ||
* Retrieve the current annotation reader | ||
* | ||
* @return Reader | ||
*/ | ||
public function getReader() | ||
{ | ||
Deprecation::trigger( | ||
'doctrine/orm', | ||
'https://github.com/doctrine/orm/pull/9587', | ||
'%s is deprecated with no replacement', | ||
__METHOD__ | ||
); | ||
|
||
return $this->reader; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function isTransient($className) | ||
{ | ||
$classAnnotations = $this->reader->getClassAnnotations(new ReflectionClass($className)); | ||
|
||
foreach ($classAnnotations as $annot) { | ||
if (isset($this->entityAnnotationClasses[get_class($annot)])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Factory method for the Annotation Driver. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,15 @@ | |
|
||
namespace Doctrine\ORM\Mapping\Driver; | ||
|
||
use Doctrine\Deprecations\Deprecation; | ||
use Doctrine\ORM\Events; | ||
use Doctrine\ORM\Mapping; | ||
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; | ||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Doctrine\ORM\Mapping\MappingException; | ||
use Doctrine\Persistence\Mapping\ClassMetadata; | ||
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver; | ||
use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver; | ||
use Doctrine\Persistence\Mapping\Driver\MappingDriver; | ||
use LogicException; | ||
use ReflectionClass; | ||
use ReflectionMethod; | ||
|
@@ -25,8 +27,10 @@ | |
|
||
use const PHP_VERSION_ID; | ||
|
||
class AttributeDriver extends AnnotationDriver | ||
class AttributeDriver implements MappingDriver | ||
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. Ah, I should implement |
||
{ | ||
use ColocatedMappingDriver; | ||
|
||
/** @var array<string,int> */ | ||
// @phpcs:ignore | ||
protected $entityAnnotationClasses = [ | ||
|
@@ -37,6 +41,8 @@ class AttributeDriver extends AnnotationDriver | |
/** | ||
* The annotation reader. | ||
* | ||
* @internal this property will be private in 3.0 | ||
* | ||
* @var AttributeReader | ||
*/ | ||
protected $reader; | ||
|
@@ -57,6 +63,25 @@ public function __construct(array $paths) | |
$this->addPaths($paths); | ||
} | ||
|
||
/** | ||
* Retrieve the current annotation reader | ||
* | ||
* @deprecated no replacement planned. | ||
* | ||
* @return AttributeReader | ||
*/ | ||
public function getReader() | ||
{ | ||
Deprecation::trigger( | ||
'doctrine/orm', | ||
'https://github.com/doctrine/orm/pull/9587', | ||
'%s is deprecated with no replacement', | ||
__METHOD__ | ||
); | ||
|
||
return $this->reader; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
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.
This BC break needs to be reverted, and moved to the next major.
Ref: #9668