From 6e8cb4306d68435743b503347c3cd409d279a61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 3 Nov 2025 16:47:46 -0500 Subject: [PATCH 1/3] Require PHP 8.4 and ext-mongodb 2 --- .github/workflows/atlas-ci.yml | 9 +---- .github/workflows/continuous-integration.yml | 37 ++++---------------- .github/workflows/performance.yml | 2 +- composer.json | 2 +- 4 files changed, 9 insertions(+), 41 deletions(-) diff --git a/.github/workflows/atlas-ci.yml b/.github/workflows/atlas-ci.yml index ff9225f9a..4ed38d4da 100644 --- a/.github/workflows/atlas-ci.yml +++ b/.github/workflows/atlas-ci.yml @@ -18,14 +18,7 @@ jobs: symfony: - "stable" proxy: - - "lazy-ghost" - include: - # Test with ProxyManager - - php-version: "8.1" - symfony: "6.4" - proxy: "proxy-manager" - os: "ubuntu-latest" - + - "native" steps: - name: "Checkout" uses: "actions/checkout@v5" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 75160f7af..be6110538 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,9 +19,6 @@ jobs: fail-fast: false matrix: php-version: - - "8.1" - - "8.2" - - "8.3" - "8.4" mongodb-version: - "8.0" @@ -35,64 +32,43 @@ jobs: - "highest" symfony-version: - "stable" - proxy: - - "lazy-ghost" include: # Test against lowest dependencies - dependencies: "lowest" - php-version: "8.1" + php-version: "8.4" mongodb-version: "6.0" driver-version: "2.1.0" topology: "server" symfony-version: "stable" - proxy: "lazy-ghost" # Test with Symfony 6.4 - topology: "server" - php-version: "8.1" + php-version: "8.4" mongodb-version: "6.0" driver-version: "stable" dependencies: "highest" symfony-version: "6.4" - proxy: "lazy-ghost" # Test with a 6.0 replica set - topology: "replica_set" - php-version: "8.2" + php-version: "8.4" mongodb-version: "6.0" driver-version: "stable" dependencies: "highest" symfony-version: "stable" - proxy: "lazy-ghost" # Test with a 8.0 replica set - topology: "replica_set" - php-version: "8.2" + php-version: "8.4" mongodb-version: "8.0" driver-version: "stable" dependencies: "highest" symfony-version: "stable" - proxy: "lazy-ghost" - # Test with ProxyManager - - php-version: "8.2" - mongodb-version: "6.0" - driver-version: "stable" - dependencies: "highest" - symfony-version: "stable" - proxy: "proxy-manager" - # Test with Native Lazy Objects - - php-version: "8.4" - mongodb-version: "8.0" - driver-version: "stable" - dependencies: "highest" - symfony-version: "stable" - proxy: "native" # Test with a sharded cluster # Currently disabled due to a bug where MongoDB reports "sharding status unknown" # - topology: "sharded_cluster" -# php-version: "8.2" +# php-version: "8.4" # mongodb-version: "6.0" # driver-version: "stable" # dependencies: "highest" # symfony-version: "stable" -# proxy: "lazy-ghost" steps: - name: "Checkout" @@ -161,6 +137,5 @@ jobs: run: "vendor/bin/phpunit --exclude-group=atlas ${{ matrix.dependencies == 'lowest' && '--do-not-fail-on-deprecation --do-not-fail-on-warning --do-not-fail-on-notice' || '' }}" env: DOCTRINE_MONGODB_SERVER: ${{ steps.setup-mongodb.outputs.cluster-uri }} - USE_LAZY_GHOST_OBJECT: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }} - USE_NATIVE_LAZY_OBJECT: ${{ matrix.proxy == 'native' && '1' || '0' }} + USE_NATIVE_LAZY_OBJECT: 1 CRYPT_SHARED_LIB_PATH: ${{ steps.setup-mongodb.outputs.crypt-shared-lib-path }} diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index 7ebbf01f3..8827fe5a4 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: php-version: - - "8.1" + - "8.4" services: mongodb: diff --git a/composer.json b/composer.json index 0903aa810..e4c723636 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "docs": "composer update -d docs && ./docs/vendor/bin/build-docs.sh @additional_args" }, "require": { - "php": "^8.1", + "php": "^8.4", "ext-mongodb": "^2.0", "composer-runtime-api": "^2.0", "doctrine/cache": "^1.11 || ^2.0", From 4692659c0e4299bfee78e51db22c3dc89cfe6ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 4 Nov 2025 06:46:52 -0500 Subject: [PATCH 2/3] Remove PHP_VERSION_ID checks --- src/Configuration.php | 8 +------- src/Hydrator/HydratorFactory.php | 5 +---- src/Mapping/ClassMetadata.php | 8 +++----- src/Mapping/ClassMetadataFactory.php | 6 ------ src/Mapping/PropertyAccessors/PropertyAccessorFactory.php | 6 +----- .../PropertyAccessors/RawValuePropertyAccessor.php | 6 ------ src/Proxy/Factory/NativeLazyObjectFactory.php | 6 ------ src/UnitOfWork.php | 4 +--- 8 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index 6b38f5076..54f30f239 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -47,8 +47,6 @@ use function trigger_deprecation; use function trim; -use const PHP_VERSION_ID; - /** * Configuration class for the DocumentManager. When setting up your DocumentManager * you can optionally specify an instance of this class as the second argument. @@ -713,17 +711,13 @@ public function isLazyGhostObjectEnabled(): bool public function setUseNativeLazyObject(bool $nativeLazyObject): void { - if (PHP_VERSION_ID < 80400 && $nativeLazyObject) { - throw new LogicException('Native lazy objects require PHP 8.4 or higher.'); - } - $this->nativeLazyObject = $nativeLazyObject; $this->lazyGhostObject = ! $nativeLazyObject || $this->lazyGhostObject; } public function isNativeLazyObjectEnabled(): bool { - if (PHP_VERSION_ID >= 80400 && ! $this->nativeLazyObject) { + if (! $this->nativeLazyObject) { trigger_deprecation('doctrine/mongodb-odm', '2.14', 'Not using native lazy objects is deprecated and will be impossible in Doctrine MongoDB ODM 3.0.'); } diff --git a/src/Hydrator/HydratorFactory.php b/src/Hydrator/HydratorFactory.php index 5a821677f..0611c6c26 100644 --- a/src/Hydrator/HydratorFactory.php +++ b/src/Hydrator/HydratorFactory.php @@ -33,7 +33,6 @@ use function uniqid; use const DIRECTORY_SEPARATOR; -use const PHP_VERSION_ID; /** * The HydratorFactory class is responsible for instantiating a correct hydrator @@ -451,9 +450,7 @@ public function hydrate(object $document, array $data, array $hints = []): array } } - if (PHP_VERSION_ID >= 80400) { - $metadata->reflClass->markLazyObjectAsInitialized($document); - } + $metadata->reflClass->markLazyObjectAsInitialized($document); if ($document instanceof InternalProxy) { // Skip initialization to not load any object data diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index e724f2605..c3d41f848 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -63,8 +63,6 @@ use function strtoupper; use function trigger_deprecation; -use const PHP_VERSION_ID; - /** * A ClassMetadata instance holds all the object-document mapping metadata * of a document and it's references. @@ -1992,7 +1990,7 @@ public function setFieldValue(object $document, string $field, $value): void $document->__load(); } elseif ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { $document->initializeProxy(); - } elseif (PHP_VERSION_ID >= 80400) { + } else { $this->reflClass->initializeLazyObject($document); } @@ -2010,7 +2008,7 @@ public function getFieldValue(object $document, string $field) $document->__load(); } elseif ($document instanceof GhostObjectInterface && $field !== $this->identifier && ! $document->isProxyInitialized()) { $document->initializeProxy(); - } elseif (PHP_VERSION_ID >= 80400 && $field !== $this->identifier && $this->reflClass->isUninitializedLazyObject($document)) { + } elseif ($field !== $this->identifier && $this->reflClass->isUninitializedLazyObject($document)) { $this->reflClass->initializeLazyObject($document); } @@ -2587,7 +2585,7 @@ public function mapField(array $mapping): array $accessor = PropertyAccessorFactory::createPropertyAccessor($this->name, $mapping['fieldName']); - if (PHP_VERSION_ID >= 80400 && $accessor->getUnderlyingReflector()->isVirtual()) { + if ($accessor->getUnderlyingReflector()->isVirtual()) { throw MappingException::mappingVirtualPropertyNotAllowed($this->name, $mapping['fieldName']); } diff --git a/src/Mapping/ClassMetadataFactory.php b/src/Mapping/ClassMetadataFactory.php index 6f02bde63..b34dda788 100644 --- a/src/Mapping/ClassMetadataFactory.php +++ b/src/Mapping/ClassMetadataFactory.php @@ -31,8 +31,6 @@ use function trigger_deprecation; use function ucfirst; -use const PHP_VERSION_ID; - /** * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the * metadata mapping informations of a class which describes how a class should be mapped @@ -119,10 +117,6 @@ protected function getDriver(): MappingDriver protected function wakeupReflection(ClassMetadataInterface $class, ReflectionService $reflService): void { - if (PHP_VERSION_ID < 80400) { - return; - } - foreach ($class->propertyAccessors as $propertyAccessor) { $property = $propertyAccessor->getUnderlyingReflector(); diff --git a/src/Mapping/PropertyAccessors/PropertyAccessorFactory.php b/src/Mapping/PropertyAccessors/PropertyAccessorFactory.php index 5b7aef171..cbf368f9c 100644 --- a/src/Mapping/PropertyAccessors/PropertyAccessorFactory.php +++ b/src/Mapping/PropertyAccessors/PropertyAccessorFactory.php @@ -6,8 +6,6 @@ use ReflectionProperty; -use const PHP_VERSION_ID; - /** @internal */ class PropertyAccessorFactory { @@ -16,9 +14,7 @@ public static function createPropertyAccessor(string $className, string $propert { $reflectionProperty = new ReflectionProperty($className, $propertyName); - $accessor = PHP_VERSION_ID >= 80400 - ? RawValuePropertyAccessor::fromReflectionProperty($reflectionProperty) - : ObjectCastPropertyAccessor::fromReflectionProperty($reflectionProperty); + $accessor = RawValuePropertyAccessor::fromReflectionProperty($reflectionProperty); if ($reflectionProperty->hasType() && ! $reflectionProperty->getType()->allowsNull()) { $accessor = new TypedNoDefaultPropertyAccessor($accessor, $reflectionProperty); diff --git a/src/Mapping/PropertyAccessors/RawValuePropertyAccessor.php b/src/Mapping/PropertyAccessors/RawValuePropertyAccessor.php index d84beb852..eb7d6f092 100644 --- a/src/Mapping/PropertyAccessors/RawValuePropertyAccessor.php +++ b/src/Mapping/PropertyAccessors/RawValuePropertyAccessor.php @@ -5,14 +5,11 @@ namespace Doctrine\ODM\MongoDB\Mapping\PropertyAccessors; use Doctrine\ODM\MongoDB\Proxy\InternalProxy; -use LogicException; use ProxyManager\Proxy\GhostObjectInterface; use ReflectionProperty; use function ltrim; -use const PHP_VERSION_ID; - /** * This is a PHP 8.4 and up only class and replaces {@see ObjectCastPropertyAccessor}. * @@ -39,9 +36,6 @@ public static function fromReflectionProperty(ReflectionProperty $reflectionProp private function __construct(private ReflectionProperty $reflectionProperty, private string $key) { - if (PHP_VERSION_ID < 80400) { - throw new LogicException('This class requires PHP 8.4 or higher.'); - } } public function setValue(object $object, mixed $value): void diff --git a/src/Proxy/Factory/NativeLazyObjectFactory.php b/src/Proxy/Factory/NativeLazyObjectFactory.php index 35552cfb6..4624dc1b2 100644 --- a/src/Proxy/Factory/NativeLazyObjectFactory.php +++ b/src/Proxy/Factory/NativeLazyObjectFactory.php @@ -16,8 +16,6 @@ use function count; -use const PHP_VERSION_ID; - /** @internal */ class NativeLazyObjectFactory implements ProxyFactory { @@ -30,10 +28,6 @@ class NativeLazyObjectFactory implements ProxyFactory public function __construct( DocumentManager $documentManager, ) { - if (PHP_VERSION_ID < 80400) { - throw new LogicException('Native lazy objects require PHP 8.4 or higher.'); - } - $this->unitOfWork = $documentManager->getUnitOfWork(); $this->lifecycleEventManager = new LifecycleEventManager($documentManager, $this->unitOfWork, $documentManager->getEventManager()); } diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 153c490ea..9fa61a158 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -52,8 +52,6 @@ use function sprintf; use function trigger_deprecation; -use const PHP_VERSION_ID; - /** * The UnitOfWork is responsible for tracking changes to objects during an * "object-level" transaction and for writing out changes to the database @@ -3065,7 +3063,7 @@ public function initializeObject(object $obj): void $obj->initializeProxy(); } elseif ($obj instanceof PersistentCollectionInterface) { $obj->initialize(); - } elseif (PHP_VERSION_ID >= 80400) { + } else { $this->dm->getClassMetadata($obj::class)->reflClass->initializeLazyObject($obj); } } From 81f1a4ef06035733488cdd351d8f89bfa5548cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 4 Nov 2025 06:54:21 -0500 Subject: [PATCH 3/3] ext-mongodb 2.1 is required by mongodb/mongodb 2.1.1 --- .github/workflows/continuous-integration.yml | 1 + composer.json | 2 +- src/Proxy/Factory/LazyGhostProxyFactory.php | 4 +--- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index be6110538..f6ef2b968 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -137,5 +137,6 @@ jobs: run: "vendor/bin/phpunit --exclude-group=atlas ${{ matrix.dependencies == 'lowest' && '--do-not-fail-on-deprecation --do-not-fail-on-warning --do-not-fail-on-notice' || '' }}" env: DOCTRINE_MONGODB_SERVER: ${{ steps.setup-mongodb.outputs.cluster-uri }} + USE_LAZY_GHOST_OBJECT: 0 USE_NATIVE_LAZY_OBJECT: 1 CRYPT_SHARED_LIB_PATH: ${{ steps.setup-mongodb.outputs.crypt-shared-lib-path }} diff --git a/composer.json b/composer.json index e4c723636..e4418af3e 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "php": "^8.4", - "ext-mongodb": "^2.0", + "ext-mongodb": "^2.1", "composer-runtime-api": "^2.0", "doctrine/cache": "^1.11 || ^2.0", "doctrine/collections": "^1.5 || ^2.0", diff --git a/src/Proxy/Factory/LazyGhostProxyFactory.php b/src/Proxy/Factory/LazyGhostProxyFactory.php index d19f885fa..a8e5246a3 100644 --- a/src/Proxy/Factory/LazyGhostProxyFactory.php +++ b/src/Proxy/Factory/LazyGhostProxyFactory.php @@ -28,10 +28,8 @@ use function file_exists; use function file_put_contents; use function filemtime; -use function get_debug_type; use function is_dir; use function is_int; -use function is_scalar; use function is_writable; use function ltrim; use function mkdir; @@ -115,7 +113,7 @@ public function __construct( } if (is_int($autoGenerate) && ($autoGenerate < 0 || $autoGenerate > 4)) { - throw new InvalidArgumentException(sprintf('Invalid auto generate mode "%s" given.', is_scalar($autoGenerate) ? (string) $autoGenerate : get_debug_type($autoGenerate))); + throw new InvalidArgumentException(sprintf('Invalid auto generate mode "%d" given.', $autoGenerate)); } $this->uow = $dm->getUnitOfWork();