Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->get('entity_manager');
     $helperSet = new HelperSet();
     $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
     $helperSet->set(new EntityManagerHelper($em), 'em');
     $arguments = array();
     if ($input->getOption('dump-sql')) {
         $arguments['--dump-sql'] = $input->getOption('dump-sql');
     }
     $command = new CreateCommand();
     $command->setHelperSet($helperSet);
     $returnCode = $command->run(new ArrayInput($arguments), $output);
     return $returnCode;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $registry = $this->container->getDoctrine();
     $em = $registry->getManager($input->getOption('em'));
     $con = $registry->getConnection($input->getOption('con'));
     $helperSet = $this->getApplication()->getHelperSet();
     $helperSet->set(new EntityManagerHelper($em), 'em');
     parent::execute($input, $output);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
 {
     return parent::executeSchemaCommand($input, new ColoredSqlOutput($output), $schemaTool, $metadatas);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em'));
     parent::execute($input, $output);
 }
 /**
  * {@inheritdoc}
  */
 protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
 {
     parent::executeSchemaCommand($input, $output, $schemaTool, $metadatas);
 }
Exemplo n.º 6
0
<?php

/**
 * Bootstrap script for console
 *
 * This file is a part of Portable ZipCode API
 *
 * @copyright 2013 Kazuyuki Hayashi
 * @license   MIT
 * @author    Kazuyuki Hayashi <*****@*****.**>
 */
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand;
use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand;
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
$app = (require __DIR__ . '/bootstrap.php');
$app->boot();
$console = new \Symfony\Component\Console\Application('kzykhys/zip-finder', '1.0.0');
$console->getHelperSet()->set(new ConnectionHelper($app['db']), 'db');
$console->getHelperSet()->set(new EntityManagerHelper($app['orm.em']), 'em');
$createCommand = new CreateCommand();
$updateCommand = new UpdateCommand();
$dropCommand = new DropCommand();
$console->addCommands(array($createCommand->setName('doctrine:schema:create'), $updateCommand->setName('doctrine:schema:update'), $dropCommand->setName('doctrine:schema:drop'), new \KzykHys\ZipFinder\Command\CSV\ImportCommand($app), new \KzykHys\ZipFinder\Command\Build\PharCommand(), new \KzykHys\ZipFinder\Command\CSV\DownloadCommand(), new \KzykHys\ZipFinder\Command\Build\PackageCommand()));
$console->run();
 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app['orm.default.parameters'] = array('orm.cache.dir' => __DIR__ . '/../../../../../cache/orm', 'orm.entity.path' => array(), 'orm.proxy.dir' => __DIR__ . '/../../../../../cache/proxies', 'orm.proxy.namespace' => 'Doctrine\\ORM\\Proxies');
     foreach ($app['orm.default.parameters'] as $key => $value) {
         if (!isset($app[$key])) {
             $app[$key] = $value;
         }
     }
     /**
      * @param  Application $app
      *
      * @return \Doctrine\Common\Cache\Cache
      */
     $app['orm.cache.driver'] = function (Application $app) {
         if (extension_loaded('apc')) {
             return new ApcCache();
         } else {
             return new FilesystemCache($app['orm.cache.dir']);
         }
     };
     /**
      * @param  Application $app
      *
      * @return \Doctrine\ORM\Configuration
      */
     $app['orm.config'] = $app->share(function (Application $app) {
         $config = new Configuration();
         $config->setMetadataCacheImpl($app['orm.cache.driver']);
         $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($app['orm.entity.path']));
         $config->setQueryCacheImpl($app['orm.cache.driver']);
         $config->setProxyDir($app['orm.proxy.dir']);
         $config->setProxyNamespace($app['orm.proxy.namespace']);
         $config->setAutoGenerateProxyClasses($app['debug']);
         return $config;
     });
     /**
      * @param  Application $app
      *
      * @throws \RuntimeException
      *
      * @return \Doctrine\ORM\EntityManager
      */
     $app['orm.em'] = $app->share(function (Application $app) {
         if (!isset($app['db'])) {
             throw new \RuntimeException('DoctrineServiceProvider is not registered');
         }
         return EntityManager::create($app['db'], $app['orm.config'], $app['db.event_manager']);
     });
     /**
      * @param  Application $app
      *
      * @return \Doctrine\ORM\Tools\SchemaTool
      */
     $app['orm.schema_tool'] = $app->share(function (Application $app) {
         return new SchemaTool($app['orm.em']);
     });
     /*
      * Register console commands for doctrine if `kzykhys/console-service-provider` is registered
      */
     if (isset($app['console.commands'])) {
         $app['console'] = $app->share($app->extend('console', function (Console $console, Application $app) {
             $console->getHelperSet()->set(new ConnectionHelper($app['db']), 'db');
             $console->getHelperSet()->set(new EntityManagerHelper($app['orm.em']), 'em');
             return $console;
         }));
         $app['console.commands'] = $app->share($app->extend('console.commands', function (array $commands) {
             $create = new CreateCommand();
             $update = new UpdateCommand();
             $drop = new DropCommand();
             $generateEntity = new GenerateEntitiesCommand();
             $generateProxy = new GenerateProxiesCommand();
             $commands[] = $create->setName('doctrine:schema:create');
             $commands[] = $update->setName('doctrine:schema:update');
             $commands[] = $drop->setName('doctrine:schema:drop');
             $commands[] = $generateEntity->setName('doctrine:generate:entities');
             $commands[] = $generateProxy->setName('doctrine:generate:proxies');
             return $commands;
         }));
     }
 }