Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-8327] Deprecate EntityManagerHelper for a provider abstraction. #8524

Merged
merged 18 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"doctrine/cache": "^1.9.1",
"doctrine/collections": "^1.5",
"doctrine/common": "^3.0.3",
"doctrine/dbal": "^2.10.0",
"doctrine/dbal": "^2.13.0-dev",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.1",
"doctrine/inflector": "^1.4|^2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Doctrine\ORM\Tools\Console\Command;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Console\EntityManagerProvider;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;

abstract class AbstractEntityManagerCommand extends Command
{
/** @var EntityManagerProvider|null */
private $entityManagerProvider;

public function __construct(?EntityManagerProvider $entityManagerProvider = null)
{
parent::__construct();

$this->entityManagerProvider = $entityManagerProvider;
}

protected function getEntityManager(InputInterface $input): EntityManagerInterface
beberlei marked this conversation as resolved.
Show resolved Hide resolved
{
// This is a backwards compatibility required check for commands extending Doctrine ORM commands
if (! $input->hasOption('entity-manager') || $this->entityManagerProvider === null) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/8327',
'Not passing EntityManagerProvider as a dependency to command class "%s" is deprecated',
$this->getName()
);

return $this->getHelper('em')->getEntityManager();
}

return $this->entityManagerProvider->getManager($input->getOption('entity-manager'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

use Doctrine\ORM\Cache;
use Doctrine\ORM\Cache\Region\DefaultRegion;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -38,7 +38,7 @@
/**
* Command to clear a collection cache region.
*/
class CollectionRegionCommand extends Command
class CollectionRegionCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -50,6 +50,7 @@ protected function configure()
->addArgument('owner-class', InputArgument::OPTIONAL, 'The owner entity name.')
->addArgument('association', InputArgument::OPTIONAL, 'The association collection name.')
->addArgument('owner-id', InputArgument::OPTIONAL, 'The owner identifier.')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.')
->setHelp(<<<EOT
Expand Down Expand Up @@ -86,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);
$ownerClass = $input->getArgument('owner-class');
$assoc = $input->getArgument('association');
$ownerId = $input->getArgument('owner-id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

use Doctrine\ORM\Cache;
use Doctrine\ORM\Cache\Region\DefaultRegion;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -38,7 +38,7 @@
/**
* Command to clear a entity cache region.
*/
class EntityRegionCommand extends Command
class EntityRegionCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -49,6 +49,7 @@ protected function configure()
->setDescription('Clear a second-level cache entity region')
->addArgument('entity-class', InputArgument::OPTIONAL, 'The entity name.')
->addArgument('entity-id', InputArgument::OPTIONAL, 'The entity identifier.')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.')
->setHelp(<<<EOT
Expand Down Expand Up @@ -85,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);
$entityClass = $input->getArgument('entity-class');
$entityId = $input->getArgument('entity-id');
$cache = $em->getCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use LogicException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -35,7 +35,7 @@
*
* @link www.doctrine-project.org
*/
class MetadataCommand extends Command
class MetadataCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -44,6 +44,7 @@ protected function configure()
{
$this->setName('orm:clear-cache:metadata')
->setDescription('Clear all metadata cache of the various cache drivers')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
->setHelp(<<<EOT
The <info>%command.name%</info> command is meant to clear the metadata cache of associated Entity Manager.
Expand Down Expand Up @@ -72,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);
$cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();

if (! $cacheDriver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use LogicException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -35,7 +35,7 @@
*
* @link www.doctrine-project.org
*/
class QueryCommand extends Command
class QueryCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -44,6 +44,7 @@ protected function configure()
{
$this->setName('orm:clear-cache:query')
->setDescription('Clear all query cache of the various cache drivers')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
->setHelp(<<<EOT
The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.
Expand Down Expand Up @@ -72,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);
$cacheDriver = $em->getConfiguration()->getQueryCacheImpl();

if (! $cacheDriver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

use Doctrine\ORM\Cache;
use Doctrine\ORM\Cache\Region\DefaultRegion;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -38,7 +38,7 @@
/**
* Command to clear a query cache region.
*/
class QueryRegionCommand extends Command
class QueryRegionCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -48,6 +48,7 @@ protected function configure()
$this->setName('orm:clear-cache:region:query')
->setDescription('Clear a second-level cache query region')
->addArgument('region-name', InputArgument::OPTIONAL, 'The query region to clear.')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all query regions will be deleted/invalidated.')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.')
->setHelp(<<<EOT
Expand Down Expand Up @@ -84,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);
$name = $input->getArgument('region-name');
$cache = $em->getCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use LogicException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -35,7 +35,7 @@
*
* @link www.doctrine-project.org
*/
class ResultCommand extends Command
class ResultCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -44,6 +44,7 @@ protected function configure()
{
$this->setName('orm:clear-cache:result')
->setDescription('Clear all result cache of the various cache drivers')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
->setHelp(<<<EOT
The <info>%command.name%</info> command is meant to clear the result cache of associated Entity Manager.
Expand Down Expand Up @@ -72,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);
$cacheDriver = $em->getConfiguration()->getResultCacheImpl();

if (! $cacheDriver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Doctrine\ORM\Tools\Export\Driver\AbstractExporter;
use Doctrine\ORM\Tools\Export\Driver\AnnotationExporter;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -48,7 +47,7 @@
*
* @link www.doctrine-project.org
*/
class ConvertMappingCommand extends Command
class ConvertMappingCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -60,6 +59,7 @@ protected function configure()
->setDescription('Convert mapping information between supported formats')
->addArgument('to-type', InputArgument::REQUIRED, 'The mapping type to be converted.')
->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your entities classes.')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.')
->addOption('from-database', null, null, 'Whether or not to convert mapping information from existing database.')
Expand Down Expand Up @@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);

if ($input->getOption('from-database') === true) {
$databaseDriver = new DatabaseDriver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace Doctrine\ORM\Tools\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -32,7 +31,7 @@
*
* @link www.doctrine-project.org
*/
class EnsureProductionSettingsCommand extends Command
class EnsureProductionSettingsCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -41,6 +40,7 @@ protected function configure()
{
$this->setName('orm:ensure-production-settings')
->setDescription('Verify that Doctrine is properly configured for a production environment')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('complete', null, InputOption::VALUE_NONE, 'Flag to also inspect database connection existence.')
->setHelp('Verify that Doctrine is properly configured for a production environment.');
}
Expand All @@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);

try {
$em->getConfiguration()->ensureProductionSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\EntityGenerator;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -43,7 +42,7 @@
*
* @link www.doctrine-project.org
*/
class GenerateEntitiesCommand extends Command
class GenerateEntitiesCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
Expand All @@ -54,6 +53,7 @@ protected function configure()
->setAliases(['orm:generate:entities'])
->setDescription('Generate entity classes and method stubs from your mapping information')
->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.')
->addOption('entity-manager', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on', 'default')
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.')
->addOption('generate-annotations', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should generate annotation metadata on entities.', false)
->addOption('generate-methods', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should generate stub methods on entities.', true)
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$ui = new SymfonyStyle($input, $output);
$ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.');

$em = $this->getHelper('em')->getEntityManager();
$em = $this->getEntityManager($input);

$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
Expand Down
Loading