|
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 Application $application |
|
30 * @param string $emName |
|
31 */ |
|
32 static public function setApplicationEntityManager(Application $application, $emName) |
|
33 { |
|
34 $em = $application->getKernel()->getContainer()->get('doctrine')->getEntityManager($emName); |
|
35 $helperSet = $application->getHelperSet(); |
|
36 $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); |
|
37 $helperSet->set(new EntityManagerHelper($em), 'em'); |
|
38 } |
|
39 |
|
40 static public function setApplicationConnection(Application $application, $connName) |
|
41 { |
|
42 $connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName); |
|
43 $helperSet = $application->getHelperSet(); |
|
44 $helperSet->set(new ConnectionHelper($connection), 'db'); |
|
45 } |
|
46 } |