From 8f195fddbbc94c8811085247dcb78d72fe478d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 1 Sep 2025 14:19:16 +0200 Subject: [PATCH] Allow field strategy to use the constant values instead of their name --- lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractField.php | 2 +- lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Id.php | 2 +- lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractField.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractField.php index 77e9870e17..85f5ccebab 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractField.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractField.php @@ -30,7 +30,7 @@ public function __construct( ?string $type = null, bool $nullable = false, array $options = [], - ?string $strategy = null, + string|int|null $strategy = null, bool $notSaved = false, ) { $this->name = $name; diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Id.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Id.php index ab48d9d8b2..ca12dec4a0 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Id.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Id.php @@ -24,7 +24,7 @@ public function __construct( ?string $type = null, bool $nullable = false, array $options = [], - ?string $strategy = 'auto', + string|int|null $strategy = 'auto', bool $notSaved = false, ) { parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved); diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index 0ab69a6e1d..7e2a62a350 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -2358,7 +2358,7 @@ public function mapField(array $mapping): array $mapping['name'] = '_id'; $this->identifier = $mapping['fieldName']; if (isset($mapping['strategy'])) { - $this->generatorType = constant(self::class . '::GENERATOR_TYPE_' . strtoupper($mapping['strategy'])); + $this->generatorType = is_string($mapping['strategy']) ? constant(self::class . '::GENERATOR_TYPE_' . strtoupper($mapping['strategy'])) : $mapping['strategy']; } $this->generatorOptions = $mapping['options'] ?? [];