DoctrineCommandHelper.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
  11. use Symfony\Component\Console\Application;
  12. use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
  13. use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
  14. /**
  15. * Provides some helper and convenience methods to configure doctrine commands in the context of bundles
  16. * and multiple connections/entity managers.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. abstract class DoctrineCommandHelper
  21. {
  22. /**
  23. * Convenience method to push the helper sets of a given entity manager into the application.
  24. *
  25. * @param string $emName
  26. */
  27. static public function setApplicationEntityManager(Application $application, $emName)
  28. {
  29. $em = $application->getKernel()->getContainer()->get('doctrine')->getEntityManager($emName);
  30. $helperSet = $application->getHelperSet();
  31. $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
  32. $helperSet->set(new EntityManagerHelper($em), 'em');
  33. }
  34. static public function setApplicationConnection(Application $application, $connName)
  35. {
  36. $connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName);
  37. $helperSet = $application->getHelperSet();
  38. $helperSet->set(new ConnectionHelper($connection), 'db');
  39. }
  40. }