Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DoctrineBundle] moved Doctrine proxy commands to their own sub-names…
…pace
- Loading branch information
Showing
16 changed files
with
105 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Symfony/Bundle/DoctrineBundle/Command/Proxy/DoctrineCommandHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\DoctrineBundle\Command\Proxy; | ||
|
||
use Symfony\Component\Console\Application; | ||
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; | ||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; | ||
|
||
/** | ||
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles | ||
* and multiple connections/entity managers. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
abstract class DoctrineCommandHelper | ||
{ | ||
/** | ||
* Convenience method to push the helper sets of a given entity manager into the application. | ||
* | ||
* @param string $emName | ||
*/ | ||
static public function setApplicationEntityManager(Application $application, $emName) | ||
{ | ||
$em = self::getEntityManager($application, $emName); | ||
$helperSet = $application->getHelperSet(); | ||
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); | ||
$helperSet->set(new EntityManagerHelper($em), 'em'); | ||
} | ||
|
||
static public function setApplicationConnection(Application $application, $connName) | ||
{ | ||
$connection = self::getDoctrineConnection($application, $connName); | ||
$helperSet = $application->getHelperSet(); | ||
$helperSet->set(new ConnectionHelper($connection), 'db'); | ||
} | ||
|
||
static protected function getEntityManager(Application $application, $name) | ||
{ | ||
$container = $application->getKernel()->getContainer(); | ||
|
||
$name = $name ?: $container->getParameter('doctrine.orm.default_entity_manager'); | ||
|
||
$ems = $container->getParameter('doctrine.orm.entity_managers'); | ||
if (!isset($ems[$name])) { | ||
throw new \InvalidArgumentException(sprintf('Could not find Doctrine EntityManager named "%s"', $name)); | ||
} | ||
|
||
return $container->get($ems[$name]); | ||
} | ||
|
||
/** | ||
* Get a doctrine dbal connection by symfony name. | ||
* | ||
* @param string $name | ||
* @return Doctrine\DBAL\Connection | ||
*/ | ||
static protected function getDoctrineConnection(Application $application, $name) | ||
{ | ||
$container = $application->getKernel()->getContainer(); | ||
|
||
$name = $name ?: $container->getParameter('doctrine.dbal.default_connection'); | ||
|
||
$connections = $container->getParameter('doctrine.dbal.connections'); | ||
if (!isset($connections[$name])) { | ||
throw new \InvalidArgumentException(sprintf('<error>Could not find a connection named <comment>%s</comment></error>', $name)); | ||
} | ||
|
||
return $container->get($connections[$name]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
03f7049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, the commit log shows everything being moved to Command/Proxy not just the proxy commands?
03f7049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Proxy sub-namespace is for commands that are just proxies to the ones from the Doctrine project.