8000 [DoctrineBundle] moved Doctrine proxy commands to their own sub-names… · lacyrhoades/symfony@03f7049 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03f7049

Browse files
committed
[DoctrineBundle] moved Doctrine proxy commands to their own sub-namespace
1 parent 6edb644 commit 03f7049

16 files changed

+105
-132
lines changed

src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@
1212
namespace Symfony\Bundle\DoctrineBundle\Command;
1313

1414
use Symfony\Bundle\FrameworkBundle\Command\Command;
15-
use Symfony\Component\Console\Input\ArrayInput;
16-
use Symfony\Component\Console\Input\InputArgument;
17-
use Symfony\Component\Console\Input\InputOption;
18-
use Symfony\Component\Console\Input\InputInterface;
19-
use Symfony\Component\Console\Output\OutputInterface;
20-
use Symfony\Component\Console\Output\Output;
21-
use Symfony\Bundle\FrameworkBundle\Console\Application;
2215
use Symfony\Component\HttpKernel\Bundle\Bundle;
23-
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
24-
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
2516
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
2617
use Doctrine\ORM\Mapping\ClassMetadata;
2718
use Doctrine\ORM\Mapping\ClassMetadataInfo;
@@ -30,33 +21,10 @@
3021
/**
3122
* Base class for Doctrine console commands to extend from.
3223
*
33-
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles
34-
* and multiple connections/entity managers.
35-
*
3624
* @author Fabien Potencier <fabien@symfony.com>
3725
*/
3826
abstract class DoctrineCommand extends Command
3927
{
40-
/**
41-
* Convenience method to push the helper sets of a given entity manager into the application.
42-
*
43-
* @param string $emName
44-
*/
45-
public function setApplicationEntityManager($emName)
46-
{
47-
$em = self::getEntityManager($emName);
48-
$helperSet = $this->getApplication()->getHelperSet();
49-
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
50-
$helperSet->set(new EntityManagerHelper($em), 'em');
51-
}
52-
53-
public function setApplicationConnection($connName)
54-
{
55-
$connection = $this->getDoctrineConnection($connName);
56-
$helperSet = $this->getApplication()->getHelperSet();
57-
$helperSet->set(new ConnectionHelper($connection), 'db');
58-
}
59-
6028
protected function getEntityGenerator()
6129
{
6230
$entityGenerator = new EntityGenerator();

src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7474
$exporter->setEntityGenerator($entityGenerator);
7575
}
7676

77-
$this->setApplicationEntityManager($input->getOption('em'));
78-
$em = $this->getHelper('em')->getEntityManager();
77+
$em = $this->getEntityManager($input->getOption('em'));
78+
7979
$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
8080
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
8181

src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
4747
{
4848
$entityManagerName = $input->getOption('em') ? $input->getOption('em') : $this->container->getParameter('doctrine.orm.default_entity_manager');
4949

50-
$this->setApplicationEntityManager($input->getOption('em'));
5150
/* @var $entityManager Doctrine\ORM\EntityManager */
52-
$entityManager = $this->getHelper('em')->getEntityManager();
51+
$entityManager = $this->getEntityManager($input->getOption('em'));
5352

5453
$entityClassNames = $entityManager->getConfiguration()
5554
->getMetadataDriverImpl()

src/Symfony/Bundle/DoctrineBundle/Command/ClearMetadataCacheDoctrineCommand.php renamed to src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearMetadataCacheDoctrineCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\DoctrineBundle\Command;
12+
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
1313

1414
use Symfony\Component\Console\Input\InputOption;
1515
use Symfony\Component\Console\Input\InputInterface;
@@ -46,7 +46,7 @@ protected function configure()
4646

4747
protected function execute(InputInterface $input, OutputInterface $output)
4848
{
49-
$this->setApplicationEntityManager($input->getOption('em'));
49+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
5050

5151
return parent::execute($input, $output);
5252
}

src/Symfony/Bundle/DoctrineBundle/Command/ClearQueryCacheDoctrineCommand.php renamed to src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearQueryCacheDoctrineCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\DoctrineBundle\Command;
12+
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
1313

1414
use Symfony\Component\Console\Input\InputOption;
1515
use Symfony\Component\Console\Input\InputInterface;
@@ -46,7 +46,7 @@ protected function configure()
4646

4747
protected function execute(InputInterface $input, OutputInterface $output)
4848
{
49-
$this->setApplicationEntityManager($input->getOption('em'));
49+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
5050

5151
return parent::execute($input, $output);
5252
}

src/Symfony/Bundle/DoctrineBundle/Command/ClearResultCacheDoctrineCommand.php renamed to src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearResultCacheDoctrineCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\DoctrineBundle\Command;
12+
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
1313

1414
use Symfony\Component\Console\Input\InputOption;
1515
use Symfony\Component\Console\Input\InputInterface;
@@ -58,7 +58,7 @@ protected function configure()
5858

5959
protected function execute(InputInterface $input, OutputInterface $output)
6060
{
61-
$this->setApplicationEntityManager($input->getOption('em'));
61+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
6262

6363
return parent::execute($input, $output);
6464
}

src/Symfony/Bundle/DoctrineBundle/Command/ConvertMappingDoctrineCommand.php renamed to src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ConvertMappingDoctrineCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\DoctrineBundle\Command;
12+
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
1313

1414
use Symfony\Component\Console\Input\InputArgument;
1515
use Symfony\Component\Console\Input\InputOption;
@@ -43,7 +43,7 @@ protected function configure()
4343

4444
protected function execute(InputInterface $input, OutputInterface $output)
4545
{
46-
$this->setApplicationEntityManager($input->getOption('em'));
46+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
4747

4848
return parent::execute($input, $output);
4949
}

src/Symfony/Bundle/DoctrineBundle/Command/CreateSchemaDoctrineCommand.php renamed to src/Symfony/Bundle/DoctrineBundle/Command/Proxy/CreateSchemaDoctrineCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\DoctrineBundle\Command;
12+
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
1313

1414
use Symfony\Component\Console\Input\InputArgument;
1515
use Symfony\Component\Console\Input\InputOption;
@@ -47,7 +47,7 @@ protected function configure()
4747

4848
protected function execute(InputInterface $input, OutputInterface $output)
4949
{
50-
$this->setApplicationEntityManager($input->getOption('em'));
50+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
5151

5252
parent::execute($input, $output);
5353
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
13+
14+
use Symfony\Component\Console\Application;
15+
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
16+
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
17+
18+
/**
19+
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles
20+
* and multiple connections/entity managers.
21+
*
22+
* @author Fabien Potencier <fabien@symfony.com>
23+
*/
24+
abstract class DoctrineCommandHelper
25+
{
26+
/**
27+
* Convenience method to push the helper sets of a given entity manager into the application.
28+
*
29+
* @param string $emName
30+
*/
31+
static public function setApplicationEntityManager(Application $application, $emName)
32+
{
33+
$em = self::getEntityManager($application, $emName);
34+
$helperSet = $application->getHelperSet();
35+
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
36+
$helperSet->set(new EntityManagerHelper($em), 'em');
37+
}
38+
39+
static public function setApplicationConnection(Application $application, $connName)
40+
{
41+
$connection = self::getDoctrineConnection($application, $connName);
42+
$helperSet = $application->getHelperSet();
43+
$helperSet->set(new ConnectionHelper($connection), 'db');
44+
}
45+
46+
static protected function getEntityManager(Application $application, $name)
47+
{
48+
$container = $application->getKernel()->getContainer();
49+
50+
$name = $name ?: $container->getParameter('doctrine.orm.default_entity_manager');
51+
52+
$ems = $container->getParameter('doctrine.orm.entity_managers');
53+
if (!isset($ems[$name])) {
54+
throw new \InvalidArgumentException(sprintf('Could not find Doctrine EntityManager named "%s"', $name));
55+
}
56+
57+
return $container->get($ems[$name]);
58+
}
59+
60+
/**
61+
* Get a doctrine dbal connection by symfony name.
62+
*
63+
* @param string $name
64+
* @return Doctrine\DBAL\Connection
65+
*/
66+
static protected function getDoctrineConnection(Application $application, $name)
67+
{
68+
$container = $application->getKernel()->getContainer();
69+
70+
$name = $name ?: $container->getParameter('doctrine.dbal.default_connection');
71+
72+
$connections = $container->getParameter('doctrine.dbal.connections');
73+
if (!isset($connections[$name])) {
74+
throw new \InvalidArgumentException(sprintf('<error>Could not find a connection named <comment>%s</comment></error>', $name));
75+
}
76+
77+
return $container->get($connections[$name]);
78+
}
79+
}

src/Symfony/Bundle/DoctrineBundle/Command/DropSchemaDoctrineCommand.php renamed to src/Symfony/Bundle/DoctrineBundle/Command/Proxy/DropSchemaDoctrineCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\DoctrineBundle\Command;
12+
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
1313

1414
use Symfony\Component\Console\Input\InputArgument;
1515
use Symfony\Component\Console\Input\InputOption;
@@ -47,7 +47,7 @@ protected function configure()
4747

4848
protected function execute(InputInterface $input, OutputInterface $output)
4949
{
50-
$this->setApplicationEntityManager($input->getOption('em'));
50+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
5151

5252
parent::execute($input, $output);
5353
}

0 commit comments

Comments
 (0)
0