From b32d49a9721cfb17fa80b19f5a150af035057309 Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Thu, 5 Aug 2021 16:07:06 +0800 Subject: [PATCH] update Indexes annotation and fix missing types --- .../Mapping/Annotations/AbstractIndex.php | 2 +- .../Mapping/Annotations/File/ChunkSize.php | 4 +- .../MongoDB/Mapping/Annotations/Indexes.php | 17 ++++++- .../Mapping/Annotations/Inheritance.php | 45 ------------------- .../Mapping/Annotations/ReferenceMany.php | 3 -- .../Mapping/Driver/AnnotationDriver.php | 8 +--- .../Mapping/Driver/AttributeDriver.php | 2 - 7 files changed, 20 insertions(+), 61 deletions(-) delete mode 100644 lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Inheritance.php diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractIndex.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractIndex.php index ee27544797..53d91cd742 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractIndex.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractIndex.php @@ -9,7 +9,7 @@ abstract class AbstractIndex implements Annotation /** @var string[] */ public $keys; - /** @var string */ + /** @var string|null */ public $name; /** @var bool|null */ diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/ChunkSize.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/ChunkSize.php index ad09a80b4a..0043be358a 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/ChunkSize.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/ChunkSize.php @@ -15,8 +15,8 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class ChunkSize extends AbstractField { - public function __construct(?string $name = 'chunkSize') + public function __construct() { - parent::__construct($name, 'int', false, [], null, true); + parent::__construct('chunkSize', 'int', false, [], null, true); } } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Indexes.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Indexes.php index 0874f012f3..91099c2909 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Indexes.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Indexes.php @@ -5,7 +5,9 @@ namespace Doctrine\ODM\MongoDB\Mapping\Annotations; use Attribute; -use Doctrine\Common\Annotations\Annotation as BaseAnnotation; +use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; + +use function is_array; /** * Specifies a list of indexes for a document @@ -13,8 +15,19 @@ * @deprecated class was deprecated in doctrine/mongodb-odm 2.2 and will be removed in 3.0. Specify all Index and UniqueIndex annotations on a class level. * * @Annotation + * @NamedArgumentConstructor */ #[Attribute(Attribute::TARGET_CLASS)] -final class Indexes extends BaseAnnotation implements Annotation +final class Indexes implements Annotation { + /** @var Index[] */ + public $value; + + /** + * @param Index[]|Index $value + */ + public function __construct($value = []) + { + $this->value = is_array($value) ? $value : [$value]; + } } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Inheritance.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Inheritance.php deleted file mode 100644 index 11b2c626fa..0000000000 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Inheritance.php +++ /dev/null @@ -1,45 +0,0 @@ -type = $type; - $this->discriminatorMap = $discriminatorMap; - $this->discriminatorField = $discriminatorField; - $this->defaultDiscriminatorValue = $defaultDiscriminatorValue; - } -} diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/ReferenceMany.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/ReferenceMany.php index a0976dae88..26478ac325 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/ReferenceMany.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/ReferenceMany.php @@ -63,9 +63,6 @@ final class ReferenceMany extends AbstractField /** @var int|null */ public $skip; - /** @var string */ - public $strategy; - /** @var string|null */ public $collectionClass; diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php index 92e5d8c897..04c8b277ea 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php @@ -82,8 +82,7 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C 'The "@Indexes" annotation used in class "%s" is deprecated. Specify all "@Index" and "@UniqueIndex" annotations on the class.', $className ); - $value = $annot->value; - foreach (is_array($value) ? $value : [$value] as $index) { + foreach ($annot->value as $index) { $this->addIndex($metadata, $index); } } elseif ($annot instanceof ODM\InheritanceType) { @@ -218,10 +217,7 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C } if ($annot instanceof ODM\Indexes) { - // Setting the type to mixed is a workaround until https://github.com/doctrine/annotations/pull/209 is released. - /** @var mixed $value */ - $value = $annot->value; - foreach (is_array($value) ? $value : [$value] as $index) { + foreach ($annot->value as $index) { $indexes[] = $index; } } elseif ($annot instanceof ODM\AlsoLoad) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php index 25edc3e77d..ecf043560e 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php @@ -28,5 +28,3 @@ public static function create($paths = [], ?Reader $reader = null): AnnotationDr return new self($reader, $paths); } } - -interface_exists(ClassMetadata::class);