Wildkat-YiiExt-DoctrineOrm
[ class tree: Wildkat-YiiExt-DoctrineOrm ] [ index: Wildkat-YiiExt-DoctrineOrm ] [ all elements ]

Source for file DoctrineORMCommand.php

Documentation is available at DoctrineORMCommand.php

  1. <?php
  2.  
  3. use Symfony\Component\Console\Helper\HelperSet,
  4.     Symfony\Component\Console\Helper\DialogHelper,
  5.     Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper,
  6.     Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
  7. /**
  8.  * DoctrineCommand.
  9.  *
  10.  * This command adds the Doctrine 2 CLI to the list of options in the yiic tool. You must
  11.  * configure protected/config/console.php with the same information as set out in your
  12.  * main.php including the component and Wildkat alias.
  13.  *
  14.  * This command file should then live in protected/commands
  15.  *
  16.  * @category YiiExtensions
  17.  * @package  Wildkat\YiiExt\DoctrineOrm
  18.  * @author   Kevin Bradwick <kevin@wildk.at>
  19.  * @license  New BSD http://www.opensource.org/licenses/bsd-license.php
  20.  * @version  Release: ##VERSION##
  21.  * @link     http://www.wildk.at
  22.  */
  23. class DoctrineOrmCommand extends CConsoleCommand
  24. {
  25.     /**
  26.      * This gets executed when the command runs
  27.      *
  28.      * @return null 
  29.      */
  30.     public function run()
  31.     {
  32.         unset($_SERVER['argv'][1]);
  33.  
  34.         $cli $this->getCli();
  35.  
  36.         $cmd new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand();
  37.         $cli->add($cmd);
  38.         $cmd new \Doctrine\DBAL\Tools\Console\Command\ImportCommand();
  39.         $cli->add($cmd);
  40.         $cmd new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand();
  41.         $cli->add($cmd);
  42.         $cmd new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand();
  43.         $cli->add($cmd);
  44.         $cmd new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand();
  45.         $cli->add($cmd);
  46.         $cmd new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand();
  47.         $cli->add($cmd);
  48.         $cmd new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand();
  49.         $cli->add($cmd);
  50.         $cmd new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand();
  51.         $cli->add($cmd);
  52.         $cmd new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand();
  53.         $cli->add($cmd);
  54.         $cmd new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand();
  55.         $cli->add($cmd);
  56.         $cmd new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand();
  57.         $cli->add($cmd);
  58.         $cmd new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand();
  59.         $cli->add($cmd);
  60.         $cmd new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand();
  61.         $cli->add($cmd);
  62.         $cmd new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand();
  63.         $cli->add($cmd);
  64.         $cmd new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand();
  65.         $cli->add($cmd);
  66.  
  67.         $cli->run();
  68.  
  69.     }//end run()
  70.  
  71.     /**
  72.      * Returns the default entity manager
  73.      *
  74.      * @return Doctrine\ORM\EntityManager 
  75.      */
  76.     protected function getEntityManager()
  77.     {
  78.         return Yii::app()->doctrine->getEntityManager();
  79.  
  80.     }//end getEntityManager()
  81.  
  82.     /**
  83.      * Get the cli object
  84.      *
  85.      * @return Symfony\component\Console\Application 
  86.      */
  87.     protected function getCli()
  88.     {
  89.         $em $this->getEntityManager();
  90.  
  91.         $helperSet new HelperSet(
  92.             array(
  93.                 'db'     => new ConnectionHelper($em->getConnection()),
  94.                 'em'     => new EntityManagerHelper($em),
  95.                 'dialog' => new DialogHelper(),
  96.             )
  97.         );
  98.  
  99.         $cli new Symfony\Component\Console\Application(
  100.             'Doctrine Command Line Interface',
  101.             Doctrine\Common\Version::VERSION
  102.         );
  103.  
  104.         $cli->setHelperSet($helperSet);
  105.         $cli->setCatchExceptions(true);
  106.  
  107.         return $cli;
  108.  
  109.     }//end getCli()
  110. }//end class

Documentation generated on Fri, 13 May 2011 14:16:01 +0100 by phpDocumentor 1.4.3