Symfony 8.0 support (#2791)

* Symfony 8.0 support
* Use symfony/flex for version constraint in CI
This commit is contained in:
Jérôme Tamarelle
2025-10-28 12:48:23 +01:00
committed by GitHub
parent 2f1298cf6d
commit 257a0a2ab0
18 changed files with 114 additions and 51 deletions

View File

@@ -18,8 +18,13 @@ jobs:
symfony:
- "stable"
proxy:
- "lazy-ghost"
- "native"
include:
# Test with LazyGhostObject
- php-version: "8.2"
symfony: "7.4"
proxy: "lazy-ghost"
os: "ubuntu-latest"
# Test with ProxyManager
- php-version: "8.1"
symfony: "6.4"

View File

@@ -34,7 +34,7 @@ jobs:
dependencies:
- "highest"
symfony-version:
- "stable"
- "locked"
proxy:
- "lazy-ghost"
include:
@@ -44,7 +44,7 @@ jobs:
mongodb-version: "6.0"
driver-version: "1.21.0"
topology: "server"
symfony-version: "stable"
symfony-version: "locked"
proxy: "lazy-ghost"
# Test with Symfony 6.4
- topology: "server"
@@ -60,7 +60,7 @@ jobs:
mongodb-version: "6.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "stable"
symfony-version: "locked"
proxy: "lazy-ghost"
# Test with a 8.0 replica set
- topology: "replica_set"
@@ -68,21 +68,21 @@ jobs:
mongodb-version: "8.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "stable"
symfony-version: "locked"
proxy: "lazy-ghost"
# Test with ProxyManager
- php-version: "8.2"
mongodb-version: "6.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "stable"
symfony-version: "locked"
proxy: "proxy-manager"
# Test with Native Lazy Objects
- php-version: "8.4"
mongodb-version: "8.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "stable"
symfony-version: "locked"
proxy: "native"
# Test with extension 1.21
- topology: "server"
@@ -90,8 +90,24 @@ jobs:
mongodb-version: "8.0"
driver-version: "1.21.0"
dependencies: "highest"
symfony-version: "stable"
symfony-version: "locked"
proxy: "lazy-ghost"
# Test with Symfony 7.4 LTS
- topology: "server"
php-version: "8.2"
mongodb-version: "8.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "7.4"
proxy: "lazy-ghost"
# Test with Symfony 8
- topology: "server"
php-version: "8.4"
mongodb-version: "8.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: false
proxy: "native"
# Test with a sharded cluster
# Currently disabled due to a bug where MongoDB reports "sharding status unknown"
# - topology: "sharded_cluster"
@@ -99,7 +115,7 @@ jobs:
# mongodb-version: "6.0"
# driver-version: "stable"
# dependencies: "highest"
# symfony-version: "stable"
# symfony-version: "locked"
# proxy: "lazy-ghost"
steps:
@@ -127,7 +143,6 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
tools: "pecl"
extensions: "mongodb-${{ matrix.driver-version }}, bcmath"
coverage: "none"
ini-values: "zend.assertions=1"
@@ -135,24 +150,17 @@ jobs:
- name: "Show driver information"
run: "php --ri mongodb"
# Not used, skip transient dependencies
# Not used for tests, skip transient dependencies
- name: "Remove phpbench/phpbench"
run: composer remove --no-update --dev phpbench/phpbench
- name: "Configure Symfony ${{ matrix.symfony-version }}"
if: "${{ matrix.symfony-version != 'stable' }}"
run: |
composer config minimum-stability dev
# update symfony deps
composer require --no-update symfony/console:^${{ matrix.symfony-version }}
composer require --no-update symfony/var-dumper:^${{ matrix.symfony-version }}
composer require --no-update --dev symfony/cache:^${{ matrix.symfony-version }}
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "--prefer-dist"
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
- name: "Install latest Python version"
uses: actions/setup-python@v6

View File

@@ -11,6 +11,8 @@
"mapping",
"object"
],
"minimum-stability": "dev",
"prefer-stable": true,
"homepage": "https://www.doctrine-project.org/projects/mongodb-odm.html",
"license": "MIT",
"authors": [
@@ -35,10 +37,10 @@
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
"mongodb/mongodb": "^1.21.2 || ^2.1.1",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/console": "^5.4 || ^6.4 || ^7.0 || ^8.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0",
"symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
"symfony/var-exporter": "^6.2 || ^7.0"
"symfony/var-dumper": "^5.4 || ^6.4 || ^7.0 || ^8.0",
"symfony/var-exporter": "^6.4 || ^7.0"
},
"require-dev": {
"ext-bcmath": "*",
@@ -52,8 +54,8 @@
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5.58",
"squizlabs/php_codesniffer": "^4",
"symfony/cache": "^5.4 || ^6.0 || ^7.0",
"symfony/uid": "^5.4 || ^6.0 || ^7.0"
"symfony/cache": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/uid": "^5.4 || ^6.0 || ^7.0 || ^8.0"
},
"conflict": {
"doctrine/annotations": "<1.12 || >=3.0"

View File

@@ -1,7 +1,7 @@
Console Commands
================
Doctrine MongoDB ODM offers some console commands, which utilize Symfony2's
Doctrine MongoDB ODM offers some console commands, which utilize Symfony's
Console component, to ease your development process:
- ``odm:clear-cache:metadata`` - Clear all metadata cache of the various cache drivers.

View File

@@ -68,6 +68,7 @@
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>src/Mapping/Driver/CompatibilityAnnotationDriver.php</exclude-pattern>
<exclude-pattern>src/Tools/Console/Command/CommandCompatibility.php</exclude-pattern>
<exclude-pattern>src/Tools/Console/Command/Schema/AbstractCommandCompatibility.php</exclude-pattern>
<exclude-pattern>src/Tools/Console/Helper/DocumentManagerHelper.php</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

View File

@@ -22,8 +22,7 @@ class MetadataCommand extends Command
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:clear-cache:metadata')

View File

@@ -9,10 +9,32 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
// Symfony 8
if ((new ReflectionMethod(Command::class, 'configure'))->hasReturnType()) {
/** @internal */
trait CommandCompatibility
{
protected function configure(): void
{
$this->doConfigure();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
return $this->doExecute($input, $output);
}
}
// Symfony 7
} elseif ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
/** @internal */
trait CommandCompatibility
{
/** @return void */
protected function configure()
{
$this->doConfigure();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
return $this->doExecute($input, $output);
@@ -22,6 +44,12 @@ if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
/** @internal */
trait CommandCompatibility
{
/** @return void */
protected function configure()
{
$this->doConfigure();
}
/**
* {@inheritDoc}
*

View File

@@ -31,8 +31,7 @@ class GenerateHydratorsCommand extends Command
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:generate:hydrators')

View File

@@ -31,8 +31,7 @@ class GeneratePersistentCollectionsCommand extends Command
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:generate:persistent-collections')

View File

@@ -35,8 +35,7 @@ class GenerateProxiesCommand extends Command
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:generate:proxies')

View File

@@ -27,8 +27,7 @@ class QueryCommand extends Command
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:query')

View File

@@ -19,16 +19,15 @@ use function is_string;
abstract class AbstractCommand extends Command
{
use AbstractCommandCompatibility;
public const DB = 'db';
public const COLLECTION = 'collection';
public const INDEX = 'index';
public const SEARCH_INDEX = 'search-index';
/** @return void */
protected function configure()
private function configureCommonOptions(): void
{
parent::configure();
$this
->addOption('maxTimeMs', null, InputOption::VALUE_REQUIRED, 'An optional maxTimeMs that will be used for all schema operations.')
->addOption('w', null, InputOption::VALUE_REQUIRED, 'An optional w option for the write concern that will be used for all schema operations.')

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\Schema;
use ReflectionMethod;
use Symfony\Component\Console\Command\Command;
// Symfony 8
if ((new ReflectionMethod(Command::class, 'configure'))->hasReturnType()) {
/** @internal */
trait AbstractCommandCompatibility
{
protected function configure(): void
{
$this->configureCommonOptions();
}
}
} else {
/** @internal */
trait AbstractCommandCompatibility
{
/** @return void */
protected function configure()
{
$this->configureCommonOptions();
}
}
}

View File

@@ -30,8 +30,7 @@ class CreateCommand extends AbstractCommand
self::SEARCH_INDEX => ['search index(es)', 'search indexes'],
];
/** @return void */
protected function configure()
private function doConfigure(): void
{
parent::configure();

View File

@@ -31,8 +31,7 @@ class DropCommand extends AbstractCommand
self::SEARCH_INDEX => ['search index(es)', 'search indexes'],
];
/** @return void */
protected function configure()
protected function doConfigure(): void
{
parent::configure();

View File

@@ -19,8 +19,7 @@ class ShardCommand extends AbstractCommand
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
parent::configure();

View File

@@ -19,8 +19,7 @@ class UpdateCommand extends AbstractCommand
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
parent::configure();

View File

@@ -19,8 +19,7 @@ class ValidateCommand extends Command
{
use CommandCompatibility;
/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:schema:validate')