Skip to content

Commit

Permalink
Merge pull request #2563 from franmomu/console_sf_7
Browse files Browse the repository at this point in the history
Support Symfony 7 by adding return types conditionally
  • Loading branch information
malarzm authored Oct 28, 2023
2 parents 14af2cb + ad5b045 commit eabef90
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 63 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,27 @@ jobs:
- "server"
dependencies:
- "highest"
symfony-version:
- "stable"
include:
- dependencies: "lowest"
php-version: "8.1"
mongodb-version: "4.4"
driver-version: "1.11.0"
topology: "server"
symfony-version: "stable"
- topology: "sharded_cluster"
php-version: "8.2"
mongodb-version: "4.4"
driver-version: "stable"
dependencies: "highest"
symfony-version: "stable"
- topology: "server"
php-version: "8.2"
mongodb-version: "6.0"
driver-version: "stable"
dependencies: "highest"
symfony-version: "7"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -78,6 +88,17 @@ jobs:
- name: "Remove phpbench/phpbench"
run: composer remove --no-update --dev phpbench/phpbench

- name: "Configure Symfony v7@dev"
if: "${{ matrix.symfony-version == '7' }}"
run: |
composer config minimum-stability dev
# not yet ready for v7
composer remove --no-update --dev vimeo/psalm
# update symfony deps
composer require --no-update symfony/console:^7@dev
composer require --no-update symfony/var-dumper:^7@dev
composer require --no-update --dev symfony/cache:^7@dev
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Tools\Console\Command\CommandCompatibility;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -19,11 +20,9 @@
*/
class MetadataCommand extends Command
{
/**
* @see \Symfony\Component\Console\Command\Command
*
* @return void
*/
use CommandCompatibility;

/** @return void */
protected function configure()
{
$this
Expand All @@ -36,8 +35,7 @@ protected function configure()
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$dm = $this->getHelper('documentManager')->getDocumentManager();
assert($dm instanceof DocumentManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Doctrine\ODM\MongoDB\Tools\Console\Command;

use ReflectionMethod;
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()) {
/** @internal */
trait CommandCompatibility
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
return $this->doExecute($input, $output);
}
}
} else {
/** @internal */
trait CommandCompatibility
{
/**
* {@inheritDoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->doExecute($input, $output);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use Doctrine\ODM\MongoDB\Tools\Console\MetadataFilter;
use InvalidArgumentException;
use Symfony\Component\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function assert;
use function count;
Expand All @@ -25,13 +27,11 @@
/**
* Command to (re)generate the hydrator classes used by doctrine.
*/
class GenerateHydratorsCommand extends Console\Command\Command
class GenerateHydratorsCommand extends Command
{
/**
* @see Console\Command\Command
*
* @return void
*/
use CommandCompatibility;

/** @return void */
protected function configure()
{
$this
Expand All @@ -56,8 +56,7 @@ protected function configure()
);
}

/** @return int */
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$filter = $input->getOption('filter');
assert(is_array($filter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use Doctrine\ODM\MongoDB\Tools\Console\MetadataFilter;
use InvalidArgumentException;
use Symfony\Component\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function assert;
use function count;
Expand All @@ -25,13 +27,11 @@
/**
* Command to (re)generate the persistent collection classes used by doctrine.
*/
class GeneratePersistentCollectionsCommand extends Console\Command\Command
class GeneratePersistentCollectionsCommand extends Command
{
/**
* @see Console\Command\Command
*
* @return void
*/
use CommandCompatibility;

/** @return void */
protected function configure()
{
$this
Expand All @@ -56,8 +56,7 @@ protected function configure()
);
}

/** @return int */
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$filter = $input->getOption('filter');
assert(is_array($filter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Tools\Console\MetadataFilter;
use InvalidArgumentException;
use Symfony\Component\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function array_filter;
use function assert;
Expand All @@ -29,13 +31,11 @@
/**
* Command to (re)generate the proxy classes used by doctrine.
*/
class GenerateProxiesCommand extends Console\Command\Command
class GenerateProxiesCommand extends Command
{
/**
* @see Console\Command\Command
*
* @return void
*/
use CommandCompatibility;

/** @return void */
protected function configure()
{
$this
Expand All @@ -55,8 +55,7 @@ protected function configure()
);
}

/** @return int */
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$filter = $input->getOption('filter');
assert(is_array($filter));
Expand Down
17 changes: 8 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Doctrine\ODM\MongoDB\Tools\Console\Command;

use LogicException;
use Symfony\Component\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;

Expand All @@ -21,13 +23,11 @@
/**
* Command to query mongodb and inspect the outputted results from your document classes.
*/
class QueryCommand extends Console\Command\Command
class QueryCommand extends Command
{
/**
* @see Console\Command\Command
*
* @return void
*/
use CommandCompatibility;

/** @return void */
protected function configure()
{
$this
Expand Down Expand Up @@ -69,8 +69,7 @@ protected function configure()
);
}

/** @return int */
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$query = $input->getArgument('query');
assert(is_string($query));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use BadMethodCallException;
use Doctrine\ODM\MongoDB\SchemaManager;
use Doctrine\ODM\MongoDB\Tools\Console\Command\CommandCompatibility;
use MongoDB\Driver\WriteConcern;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -19,6 +20,8 @@

class CreateCommand extends AbstractCommand
{
use CommandCompatibility;

/** @var string[] */
private array $createOrder = [self::COLLECTION, self::INDEX];

Expand All @@ -36,8 +39,7 @@ protected function configure()
->setDescription('Create databases, collections and indexes for your documents');
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$create = array_filter($this->createOrder, static fn (string $option): bool => (bool) $input->getOption($option));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\Schema;

use Doctrine\ODM\MongoDB\SchemaManager;
use Doctrine\ODM\MongoDB\Tools\Console\Command\CommandCompatibility;
use MongoDB\Driver\WriteConcern;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -18,6 +19,8 @@

class DropCommand extends AbstractCommand
{
use CommandCompatibility;

/** @var string[] */
private array $dropOrder = [self::INDEX, self::COLLECTION, self::DB];

Expand All @@ -35,8 +38,7 @@ protected function configure()
->setDescription('Drop databases, collections and indexes for your documents');
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$drop = array_filter($this->dropOrder, static fn (string $option): bool => (bool) $input->getOption($option));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use BadMethodCallException;
use Doctrine\ODM\MongoDB\SchemaManager;
use Doctrine\ODM\MongoDB\Tools\Console\Command\CommandCompatibility;
use MongoDB\Driver\WriteConcern;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -17,6 +18,8 @@

class ShardCommand extends AbstractCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
{
Expand All @@ -28,8 +31,7 @@ protected function configure()
->setDescription('Enable sharding for selected documents');
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$class = $input->getOption('class');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use BadMethodCallException;
use Doctrine\ODM\MongoDB\SchemaManager;
use Doctrine\ODM\MongoDB\Tools\Console\Command\CommandCompatibility;
use MongoDB\Driver\WriteConcern;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -17,6 +18,8 @@

class UpdateCommand extends AbstractCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
{
Expand All @@ -29,8 +32,7 @@ protected function configure()
->setDescription('Update indexes and validation rules for your documents');
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$class = $input->getOption('class');
$updateValidators = ! $input->getOption('disable-validators');
Expand Down
Loading

0 comments on commit eabef90

Please sign in to comment.