/**
  * @param \Nette\DI\Container
  * @param \Symfony\Component\Console\Helper\HelperSet
  * @return \Symfony\Component\Console\Application
  */
 public static function createConsole(\Nette\DI\Container $container, \Symfony\Component\Console\Helper\HelperSet $helperSet = NULL)
 {
     $console = new \Symfony\Component\Console\Application(Framework::NAME . " Command Line Interface", Framework::VERSION);
     if (!$helperSet) {
         $helperSet = new \Symfony\Component\Console\Helper\HelperSet();
         $helperSet->set(new \Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper($container->documentManager), 'dm');
         $helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
     }
     $console->setHelperSet($helperSet);
     $console->setCatchExceptions(FALSE);
     $commands = array();
     foreach (array_keys($container->findByTag('consoleCommand')) as $name) {
         $commands[] = $container->getService($name);
     }
     $console->addCommands($commands);
     return $console;
 }
예제 #2
0
<?php

chdir('..');
require_once 'Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
$classLoader->register();
//$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';
$configFile = 'bin/cli-config.php';
$helperSet = null;
if (file_exists($configFile)) {
    if (!is_readable($configFile)) {
        trigger_error('Configuration file [' . $configFile . '] does not have read permission.', E_ERROR);
    }
    require $configFile;
    foreach ($GLOBALS as $helperSetCandidate) {
        if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
            $helperSet = $helperSetCandidate;
            break;
        }
    }
}
$helperSet = $helperSet ?: new \Symfony\Component\Console\Helper\HelperSet();
$cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\ORM\Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
$cli->addCommands(array(new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand()));
$cli->run();
예제 #3
0
파일: Doctrine.php 프로젝트: ncud/sagalaya
 public function run($args = array())
 {
     $defaults = array('proxy' => array('auto' => true, 'path' => LITHIUM_APP_PATH . '/resources/tmp/cache/Doctrine/Proxies', 'namespace' => 'Doctrine\\Proxies'), 'useModelDriver' => true, 'mapping' => array('class' => null, 'path' => LITHIUM_APP_PATH . '/models'), 'configuration' => null, 'eventManager' => null);
     if ($this->request->params['action'] != 'run') {
         $args = $this->request->argv;
     }
     // Check if we need to add the migration configuration file
     $migrationCommand = false;
     $migrationConfig = true;
     $migration = false;
     $conn = Connections::get($this->connection);
     $conn->_config = $conn->_config + $defaults;
     $i = 0;
     foreach ($args as &$arg) {
         if (strstr($arg, 'migrations:')) {
             $migrationCommand = true;
         }
         if (strstr($arg, 'migrations')) {
             $migration = true;
         }
         if (strstr($arg, '--configuration=')) {
             $migrationConfig = false;
         }
         if (strstr($arg, '--connection')) {
             unset($args[$i]);
         }
         $i++;
     }
     if ($migrationCommand && $migrationConfig) {
         $args[] = '--configuration=' . LITHIUM_APP_PATH . '/config/migrations.yml';
     }
     $input = new \Symfony\Component\Console\Input\ArgvInput($args);
     if (!$conn || !$conn instanceof \app\extensions\data\source\Doctrine) {
         $error = "Error: Could not get Doctrine proxy object from Connections, using";
         $error .= " configuration '{$this->connection}'. Please add the connection or choose";
         $error .= " an alternate configuration using the `--connection` flag.";
         $this->error($error);
         return;
     }
     /*
      * New Doctrine ORM Configuration
      * TODO: load multiple drivers [Annotations, YAML & XML]
      * 
      */
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     //Annotation Driver
     $driver = $config->newDefaultAnnotationDriver(array(LITHIUM_APP_PATH . '/models'));
     $config->setMetadataDriverImpl($driver);
     //Proxy configuration
     $config->setProxyDir($conn->_config['proxy']['path']);
     $config->setProxyNamespace($conn->_config['proxy']['namespace']);
     //EntityManager
     $em = \Doctrine\ORM\EntityManager::create($conn->_config, $config);
     $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em), 'dialog' => new \Symfony\Component\Console\Helper\DialogHelper()));
     //CLI
     $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', \Doctrine\Common\Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->register('doctrine');
     $cli->setHelperSet($helperSet);
     $cli->addCommands(array(new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand()));
     // If command called is a doctrine migration command
     if ($migration) {
         $cli->addCommands(array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()));
     }
     $cli->run($input);
 }
예제 #4
0
 public function executeDoctrine(array $arguments)
 {
     $_SERVER['argv'] = array_slice($arguments, 1);
     $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', \Doctrine\Common\Version::VERSION);
     $cli->setCatchExceptions(true);
     $helperSet = $cli->getHelperSet();
     $helpers = array('em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($this->cx->getDb()->getEntityManager()));
     foreach ($helpers as $name => $helper) {
         $helperSet->set($helper, $name);
     }
     $cli->addCommands(array(new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand()));
     $cli->setAutoExit(false);
     return $cli->run();
 }
예제 #5
0
	/**
	 * @param \Nette\DI\Container
	 * @return \Symfony\Component\Console\Application
	 */
	public static function createServiceConsole(Container $container)
	{
		$commands = $container->consoleCommands;
        if ($commands instanceof \Nella\FreezableArray) {
        	$commands->freeze();
			$commands = $commands->iterator->getArrayCopy();
        }

        $cli = new \Symfony\Component\Console\Application(
			Framework::NAME . " Command Line Interface", Framework::VERSION
		);
        $cli->setCatchExceptions(FALSE);
        $cli->setHelperSet($container->consoleHelpers);
		$cli->addCommands($commands);
        return $cli;
	}