Skip to content

Commit

Permalink
Remove ContainerAwareInterface and deprecate methods
Browse files Browse the repository at this point in the history
The deprecated methods are not used anymore.
  • Loading branch information
franmomu committed Aug 10, 2021
1 parent 91922fa commit eca62c0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 7 deletions.
77 changes: 72 additions & 5 deletions Command/DoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,83 @@
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper;
use Doctrine\Persistence\ObjectManager;
use InvalidArgumentException;
use LogicException;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use function assert;
use function sprintf;
use function str_replace;
use function strtolower;
use function trigger_deprecation;

use const DIRECTORY_SEPARATOR;

/**
* Base class for Doctrine ODM console commands to extend.
*
* @internal since version 4.4
*/
abstract class DoctrineODMCommand extends Command implements ContainerAwareInterface
abstract class DoctrineODMCommand extends Command
{
use ContainerAwareTrait;
/** @var ContainerInterface|null */
protected $container;

/** @var ManagerRegistry|null */
private $managerRegistry;

public function __construct(?ManagerRegistry $registry = null)
{
parent::__construct(null);
parent::__construct();

$this->managerRegistry = $registry;
}

/**
* @deprecated since version 4.4
*/
public function setContainer(?ContainerInterface $container = null)
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

$this->container = $container;
}

/**
* @deprecated since version 4.4
*
* @return ContainerInterface
*
* @throws LogicException
*/
protected function getContainer()
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

if ($this->container === null) {
$application = $this->getApplication();
if ($application === null) {
throw new LogicException('The container cannot be retrieved as the application instance is not yet set.');
}

assert($application instanceof Application);

$this->container = $application->getKernel()->getContainer();
}

return $this->container;
}

Expand All @@ -59,10 +99,19 @@ public static function setApplicationDocumentManager(Application $application, $
}

/**
* @deprecated since version 4.4
*
* @return ObjectManager[]
*/
protected function getDoctrineDocumentManagers()
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

return $this->getManagerRegistry()->getManagers();
}

Expand All @@ -82,12 +131,21 @@ protected function getManagerRegistry()
}

/**
* @deprecated since version 4.4
*
* @param string $bundleName
*
* @return Bundle
*/
protected function findBundle($bundleName)
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

$foundBundle = false;

$application = $this->getApplication();
Expand All @@ -113,12 +171,21 @@ protected function findBundle($bundleName)
/**
* Transform classname to a path $foundBundle substract it to get the destination
*
* @deprecated since version 4.4
*
* @param Bundle $bundle
*
* @return string
*/
protected function findBasePathForBundle($bundle)
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

$path = str_replace('\\', DIRECTORY_SEPARATOR, $bundle->getNamespace());
$search = str_replace('\\', DIRECTORY_SEPARATOR, $bundle->getPath());
$destination = str_replace(DIRECTORY_SEPARATOR . $path, '', $search, $c);
Expand Down
4 changes: 2 additions & 2 deletions Command/InfoDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ protected function configure()
The <info>doctrine:mongodb:mapping:info</info> shows basic information about which
documents exist and possibly if their mapping information contains errors or not.
<info>./app/console doctrine:mongodb:mapping:info</info>
<info>./bin/console doctrine:mongodb:mapping:info</info>
If you are using multiple document managers you can pick your choice with the <info>--dm</info> option:
<info>./app/console doctrine:mongodb:mapping:info --dm=default</info>
<info>./bin/console doctrine:mongodb:mapping:info --dm=default</info>
EOT
);
}
Expand Down

0 comments on commit eca62c0

Please sign in to comment.