Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ jobs:
dependencies: "highest"
symfony-version: "stable"
proxy: "lazy-ghost"
# Test with upcoming Symfony 7.4
- topology: "server"
php-version: "8.2"
mongodb-version: "8.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "7.4"
proxy: "lazy-ghost"
# Test with upcoming Symfony 8.0
- topology: "server"
php-version: "8.4"
mongodb-version: "8.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "8.0"
proxy: "lazy-ghost"
# Test with a sharded cluster
# Currently disabled due to a bug where MongoDB reports "sharding status unknown"
# - topology: "sharded_cluster"
Expand Down Expand Up @@ -140,6 +156,10 @@ jobs:
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 }}
if dpkg --compare-versions "${{ matrix.symfony-version }}" lt "8.0"; then
# LazyGhostTrait was removed from symfony/var-exporter >= 8.0
composer require --no-update --dev symfony/var-exporter:^${{ matrix.symfony-version }}
fi

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
"mongodb/mongodb": "^1.21 || ^2.0@dev",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/console": "^5.4 || ^6.4 || ^7.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",
"symfony/var-exporter": "^6.4 || ^7.0"
},
"require-dev": {
"ext-bcmath": "*",
Expand All @@ -49,7 +49,7 @@
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.4",
"squizlabs/php_codesniffer": "^3.5",
"symfony/cache": "^5.4 || ^6.0 || ^7.0"
"symfony/cache": "^5.4 || ^6.4 || ^7.0"
},
"conflict": {
"doctrine/annotations": "<1.12 || >=3.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/console-commands.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,32 @@
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();
}
Comment on lines +17 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm missing something but I don't think we need this trait here.
Since we already require PHP 8.1+, we should be able to use void in child classes as per: https://3v4l.org/Mv3oq

I did something similar in https://github.com/IonBazan/composer-diff/blob/8907711f0bf74677041f7b356da2367afea44a53/src/Command/BaseTypedCommand.php#L9-L14 but that's only needed to support different PHP versions.

If the parent does not declare a return type then the child is allowed to declare one.

See: https://wiki.php.net/rfc/return_types


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);
Expand All @@ -22,6 +44,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @internal */
trait CommandCompatibility
{
/** @return void */
protected function configure()
{
$this->doConfigure();
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class GenerateHydratorsCommand extends Command
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:generate:hydrators')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class GenerateProxiesCommand extends Command
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:generate:proxies')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class QueryCommand extends Command
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:query')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You remove the call to parent::configure() here but it's not included in any of the new implementations in AbstractCommandCompatibility. Does that mean this parent call was never required?


$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.')
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class ShardCommand extends AbstractCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
parent::configure();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class UpdateCommand extends AbstractCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
parent::configure();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class ValidateCommand extends Command
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this
->setName('odm:schema:validate')
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>lib/Doctrine/ODM/MongoDB/Mapping/Driver/CompatibilityAnnotationDriver.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ODM/MongoDB/Tools/Console/Command/CommandCompatibility.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/AbstractCommandCompatibility.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ODM/MongoDB/Tools/Console/Helper/DocumentManagerHelper.php</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
Expand Down