vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     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;
       
    13 
       
    14 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
       
    15 use Doctrine\ORM\Tools\EntityGenerator;
       
    16 
       
    17 /**
       
    18  * Base class for Doctrine console commands to extend from.
       
    19  *
       
    20  * @author Fabien Potencier <fabien@symfony.com>
       
    21  */
       
    22 abstract class DoctrineCommand extends ContainerAwareCommand
       
    23 {
       
    24     protected function getEntityGenerator()
       
    25     {
       
    26         $entityGenerator = new EntityGenerator();
       
    27         $entityGenerator->setGenerateAnnotations(false);
       
    28         $entityGenerator->setGenerateStubMethods(true);
       
    29         $entityGenerator->setRegenerateEntityIfExists(false);
       
    30         $entityGenerator->setUpdateEntityIfExists(true);
       
    31         $entityGenerator->setNumSpaces(4);
       
    32         $entityGenerator->setAnnotationPrefix('ORM\\');
       
    33 
       
    34         return $entityGenerator;
       
    35     }
       
    36 
       
    37     protected function getEntityManager($name)
       
    38     {
       
    39         return $this->getContainer()->get('doctrine')->getEntityManager($name);
       
    40     }
       
    41 
       
    42     /**
       
    43      * Get a doctrine dbal connection by symfony name.
       
    44      *
       
    45      * @param string $name
       
    46      * @return Doctrine\DBAL\Connection
       
    47      */
       
    48     protected function getDoctrineConnection($name)
       
    49     {
       
    50         return $this->getContainer()->get('doctrine')->getConnection($name);
       
    51     }
       
    52 }