/**
  * {@inheritdoc}
  */
 public function register(Container $c)
 {
     $c['migrations.apps'] = function ($c) {
         $apps = new Container();
         foreach ($c['migrations.options'] as $key => $options) {
             $apps[$key] = function () use($c, $key, $options) {
                 $db = $c['dbs'][$key];
                 return $c['migrations.create_app']($c['migrations.create_helpers']($db), $c['migrations.create_commands']($db, $options));
             };
         }
         return $apps;
     };
     $c['migrations.create_app'] = $c->protect(function ($helpers, $commands) {
         return ConsoleRunner::createApplication($helpers, $commands);
     });
     $c['migrations.create_helpers'] = $c->protect(function ($db) {
         return new HelperSet(['db' => new ConnectionHelper($db), 'dialog' => new QuestionHelper()]);
     });
     $c['migrations.create_commands'] = $c->protect(function ($db, $options) {
         $config = new Configuration($db);
         if (isset($options['namespace'])) {
             $config->setMigrationsNamespace($options['namespace']);
         }
         $config->setMigrationsDirectory($options['path']);
         $config->registerMigrationsFromDirectory($options['path']);
         if (isset($options['table'])) {
             $config->setMigrationsTableName($options['table']);
         }
         $commands = [new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()];
         foreach ($commands as $command) {
             $command->setMigrationConfiguration($config);
         }
         return $commands;
     });
 }
Пример #2
0
 public function run()
 {
     $entityManager = null;
     if (is_array($_SERVER['argv'])) {
         foreach ($_SERVER['argv'] as $key => $value) {
             if (substr($value, 0, 5) === '--em=') {
                 $entityManager = substr($value, 5);
                 unset($_SERVER['argv'][$key]);
                 if (is_int($_SERVER['argc'])) {
                     $_SERVER['argc']--;
                 }
                 break;
             }
         }
     }
     $commands = $this->container->getDoctrine()->getCommands();
     $helperSet = $this->container->getDoctrine()->getHelperSet($entityManager);
     if (!$helperSet instanceof HelperSet) {
         foreach ($GLOBALS as $helperSetCandidate) {
             if ($helperSetCandidate instanceof HelperSet) {
                 $helperSet = $helperSetCandidate;
                 break;
             }
         }
     }
     ConsoleRunner::run($helperSet, $commands);
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function onBootstrap(EventInterface $e)
 {
     /* @var $app \Zend\Mvc\ApplicationInterface */
     $app = $e->getTarget();
     $events = $app->getEventManager()->getSharedManager();
     // Attach to helper set event and load the entity manager helper.
     $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
         /* @var $cli \Symfony\Component\Console\Application */
         $cli = $e->getTarget();
         ConsoleRunner::addCommands($cli);
         $cli->addCommands(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()));
         /* @var $sm ServiceLocatorInterface */
         $sm = $e->getParam('ServiceManager');
         /* @var $em \Doctrine\ORM\EntityManager */
         $em = $sm->get('doctrine.entitymanager.orm_default');
         $helperSet = $cli->getHelperSet();
         $helperSet->set(new DialogHelper(), 'dialog');
         $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
         $helperSet->set(new EntityManagerHelper($em), 'em');
     });
     $config = $app->getServiceManager()->get('Config');
     $app->getServiceManager()->get('doctrine.entity_resolver.orm_default');
     if (isset($config['zenddevelopertools']['profiler']['enabled']) && $config['zenddevelopertools']['profiler']['enabled']) {
         $app->getServiceManager()->get('doctrine.sql_logger_collector.orm_default');
     }
 }
 /**
  * Constructor
  *
  * @param Application $console Console
  * @param ContainerInterface $container Container DI
  */
 public function __construct(Application $console, ContainerInterface $container)
 {
     $entityManager = $container->get('EntityManager');
     $helperSet = ConsoleRunner::createHelperSet($entityManager);
     $helperSet->set(new QuestionHelper(), 'dialog');
     $console->setHelperSet($helperSet);
     ConsoleRunner::addCommands($console);
 }
 public function registerCommands(Application $application)
 {
     parent::registerCommands($application);
     //include Doctrine ORM commands if exist
     if (class_exists('Doctrine\\ORM\\Version')) {
         ConsoleRunner::addCommands($application);
     }
 }
Пример #6
0
 public function testCreateApplication()
 {
     $helperSet = new HelperSet();
     $app = ConsoleRunner::createApplication($helperSet);
     $this->assertInstanceOf('Symfony\\Component\\Console\\Application', $app);
     $this->assertSame($helperSet, $app->getHelperSet());
     $this->assertEquals(Version::VERSION, $app->getVersion());
 }
Пример #7
0
 /**
  * {@inheritDoc}
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $this->setHelperSet(ConsoleRunner::createHelperSet($this->app->get('doctrine.orm.entity_manager')));
     $this->getHelperSet()->set(new QuestionHelper());
     $this->getHelperSet()->set(new DialogHelper());
     $this->registerCommands();
     $this->io = new ConsoleIO($input, $output, $this->getHelperSet());
     return parent::doRun($input, $output);
 }
Пример #8
0
 /**
  * Run console with the given helperset.  Use the in-built Doctrine commands, plus Flextrine specific ones.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
  * @return void
  */
 public static function run(HelperSet $helperSet)
 {
     $cli = new Application('Doctrine Command Line Interface', \Doctrine\ORM\Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     parent::addCommands($cli);
     self::addCommands($cli);
     $cli->run();
 }
Пример #9
0
 public function route_model()
 {
     // GET ENTITY MANAGER
     $em = $this->doctrine->getEntityManager();
     // CALL CONSOLE RUNNER
     $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)));
     // GET CONSOLE RUNNER
     return \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
 }
Пример #10
0
 public function __construct()
 {
     parent::__construct(static::NAME, static::VERSION);
     //Add Doctrine support to console
     $em = Configuration::getEntityManager();
     $doctrineHelperSet = new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]);
     $this->setHelperSet($doctrineHelperSet);
     ConsoleRunner::addCommands($this);
     $this->addCommands([new Command\ModuleUpdateCommand()]);
 }
 private function registerEntityManager(Application $app, $serviceName, Connection $connection, Configuration $metadataConfig)
 {
     $app[$serviceName] = $app->share(function () use($app, $connection, $metadataConfig) {
         return EntityManager::create($connection, $metadataConfig);
     });
     // create a console for every manager
     $consoleServiceName = sprintf('%s.console', $serviceName);
     $app[$consoleServiceName] = $app->share(function () use($app, $serviceName) {
         return ConsoleRunner::createApplication(ConsoleRunner::createHelperSet($app[$serviceName]));
     });
 }
Пример #12
0
 /**
  * @param $orm
  */
 public function ormCommands($orm)
 {
     if (is_array($orm) && in_array('doctrine', $orm)) {
         /** @var EntityManager $em */
         $em = Model::orm('doctrine')->getOrm();
         $helperSet = ConsoleRunner::createHelperSet($em);
         $this->cli->setCatchExceptions(true);
         $this->cli->setHelperSet($helperSet);
         ConsoleRunner::addCommands($this->cli);
     }
 }
Пример #13
0
 public function actionIndex()
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = ApplicationConsole::app()->db->doctrine;
     $helperSet = new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]);
     //unset($_SERVER['argv'][0]);
     unset($_SERVER['argv'][1]);
     $_SERVER['argv'] = array_values($_SERVER['argv']);
     \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
 }
Пример #14
0
 protected function _before()
 {
     $credentials = new DbCredentials();
     $container = ContainerService::getInstance()->setDbCredentials($credentials)->addEntityPath('src/Entity')->getContainer();
     $em = $container['doctrine.entity_manager'];
     $helperSet = ConsoleRunner::createHelperSet($em);
     $helperSet->set(new DialogHelper(), 'dialog');
     $this->app = new Application();
     $gen = new GenerateProxy();
     $gen->setHelperSet($helperSet);
     $this->app->add($gen);
     $this->app->add(new VersionCommand());
 }
Пример #15
0
 protected function _before()
 {
     $credentials = new DbCredentials();
     $container = ContainerService::getInstance()->setDbCredentials($credentials)->addEntityPath('src/Entity')->getContainer();
     $em = $container['doctrine.entity_manager'];
     $helperSet = ConsoleRunner::createHelperSet($em);
     $helperSet->set(new DialogHelper(), 'dialog');
     $configuration = new Configuration($em->getConnection());
     $configuration->setMigrationsNamespace('Migrations');
     $configuration->setMigrationsTableName('Migration');
     $this->app = new Application();
     $mig = new Migration();
     $mig->setMigrationConfiguration($configuration);
     $this->app->add($mig);
     $this->app->add(new VersionCommand());
 }
Пример #16
0
 public function setupDoctrineCommands()
 {
     if (!Core::make('app')->isInstalled()) {
         return;
     }
     $helperSet = ConsoleRunner::createHelperSet(\ORM::entityManager('core'));
     $this->setHelperSet($helperSet);
     $migrationsConfiguration = new MigrationsConfiguration();
     /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand[] $commands */
     $commands = 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());
     foreach ($commands as $migrationsCommand) {
         $migrationsCommand->setMigrationConfiguration($migrationsConfiguration);
         $this->add($migrationsCommand);
     }
     ConsoleRunner::addCommands($this);
 }
Пример #17
0
 /**
  * {@inheritDoc}
  */
 public function init(ModuleManager $e)
 {
     $events = $e->getEventManager()->getSharedManager();
     // Attach to helper set event and load the entity manager helper.
     $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
         /* @var $cli \Symfony\Component\Console\Application */
         $cli = $e->getTarget();
         /* @var $sm ServiceLocatorInterface */
         $sm = $e->getParam('ServiceManager');
         $em = $sm->get('doctrine.entitymanager.orm_default');
         $paths = $sm->get('doctrine.configuration.fixtures');
         $importCommand = new ImportCommand();
         $importCommand->setEntityManager($em);
         $importCommand->setPath($paths);
         ConsoleRunner::addCommands($cli);
         $cli->addCommands(array($importCommand));
     });
 }
Пример #18
0
 public function onBootstrap(EventInterface $e)
 {
     $app = $e->getTarget();
     $events = $app->getEventManager()->getSharedManager();
     // Attach to helper set event and load the entity manager helper.
     $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
         $cli = $e->getTarget();
         ConsoleRunner::addCommands($cli);
         if (class_exists('Doctrine\\DBAL\\Migrations\\Versions')) {
             $cli->add(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()));
         }
         $sm = $e->getParam('ServiceManager');
         $em = $sm->get('doctrine.entitymanager.orm_another');
         $helperSet = $cli->getHelperSet();
         $helperSet->set(new DialogHelper(), 'dialog');
         $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
         $helperSet->set(new EntityManagerHelper($em), 'em');
     });
 }
Пример #19
0
 public function indexAction()
 {
     if ($this->getRequest() instanceof ConsoleRequest) {
         $params = $this->params()->fromRoute();
         switch ($params['api']) {
             case 'doctrine':
                 global $argv;
                 array_shift($argv);
                 // index.php
                 array_shift($argv);
                 // external
                 $_SERVER['argv'] = $argv;
                 $helperSet = ConsoleRunner::createHelperSet($this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'));
                 ConsoleRunner::run($helperSet, array());
                 break;
             default:
                 return 'Could not find an option for external tool: ' . $params['api'];
         }
         return '';
     }
     return new ViewModel();
 }
Пример #20
0
 public function actionIndex()
 {
     unset($_SERVER['argv'][1]);
     $option = '--' . \yii\console\Application::OPTION_APPCONFIG . '=';
     foreach ($_SERVER['argv'] as $key => $param) {
         if (strpos($param, $option) === 0) {
             $keyToUnset = $key;
             break;
         }
     }
     if (isset($keyToUnset)) {
         unset($_SERVER['argv'][$keyToUnset]);
         unset($keyToUnset);
     }
     // Currently, symfony application uses a deprecated class (DialogHelper).
     // Don't throw an exception.
     $currentLevel = error_reporting();
     error_reporting($currentLevel ^ E_USER_DEPRECATED);
     $doctrine = $this->getDoctrineComponent();
     $entityManager = $doctrine->getEntityManager();
     $helperSet = ConsoleRunner::createHelperSet($entityManager);
     $result = ConsoleRunner::run($helperSet);
     return $result;
 }
Пример #21
0
@(include_once __DIR__ . '/../vendor/autoload.php') || @(include_once __DIR__ . '/../../../autoload.php');
$directories = array(getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config');
$configFile = null;
foreach ($directories as $directory) {
    $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php';
    if (file_exists($configFile)) {
        break;
    }
}
if (!file_exists($configFile)) {
    ConsoleRunner::printCliConfigTemplate();
    exit(1);
}
if (!is_readable($configFile)) {
    echo 'Configuration file [' . $configFile . '] does not have read permission.' . "\n";
    exit(1);
}
Type::overrideType(Type::DATETIME, Database::getUTCDateTimeTypeClass());
Type::addType('json', 'Sonata\\Doctrine\\Types\\JsonType');
$commands = 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\LatestCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand());
$helperSet = (require $configFile);
if (!$helperSet instanceof HelperSet) {
    foreach ($GLOBALS as $helperSetCandidate) {
        if ($helperSetCandidate instanceof HelperSet) {
            $helperSet = $helperSetCandidate;
            break;
        }
    }
}
\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands);
Пример #22
0
 /**
  * @return RZ\Roadiz\Core\Kernel $this
  */
 public function runConsole()
 {
     /*
      * Define a request wide timezone
      */
     if (!empty($this->container['config']["timezone"])) {
         date_default_timezone_set($this->container['config']["timezone"]);
     } else {
         date_default_timezone_set("Europe/Paris");
     }
     $application = new Application('Roadiz Console Application', static::$cmsVersion);
     $helperSet = new HelperSet(['db' => new ConnectionHelper($this->container['em']->getConnection()), 'em' => new EntityManagerHelper($this->container['em']), 'question' => new QuestionHelper(), 'solr' => new SolrHelper($this->container['solr']), 'ns-cache' => new CacheProviderHelper($this->container['nodesSourcesUrlCacheProvider'])]);
     $application->setHelperSet($helperSet);
     $application->add(new \RZ\Roadiz\Console\TranslationsCommand());
     $application->add(new \RZ\Roadiz\Console\NodeTypesCommand());
     $application->add(new \RZ\Roadiz\Console\NodesSourcesCommand());
     $application->add(new \RZ\Roadiz\Console\NodesCommand());
     $application->add(new \RZ\Roadiz\Console\ThemesCommand());
     $application->add(new \RZ\Roadiz\Console\InstallCommand());
     $application->add(new \RZ\Roadiz\Console\UsersCommand());
     $application->add(new \RZ\Roadiz\Console\RequirementsCommand());
     $application->add(new \RZ\Roadiz\Console\SolrCommand());
     $application->add(new \RZ\Roadiz\Console\CacheCommand());
     $application->add(new \RZ\Roadiz\Console\ConfigurationCommand());
     $application->add(new \RZ\Roadiz\Console\ThemeInstallCommand());
     // Use default Doctrine commands
     ConsoleRunner::addCommands($application);
     $application->run();
     $this->container['stopwatch']->stop('global');
     return $this;
 }
<?php

// replace with file to your own project bootstrap
require_once "vendor/autoload.php";
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$dbParams = array('driver' => 'pdo_mysql', 'user' => 'blockchain', 'password' => 'blockchain', 'dbname' => 'blockchain', 'host' => 'multichain-mysql.docker');
$isDevMode = true;
$paths = array("./yml");
$config = \Doctrine\ORM\Tools\Setup::createYAMLMetadataConfiguration($paths, $isDevMode);
$entityManager = \Doctrine\ORM\EntityManager::create($dbParams, $config);
return ConsoleRunner::createHelperSet($entityManager);
Пример #24
0
<?php

require_once '../../Library/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';
$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();
\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
Пример #25
0
<?php

$entityManager = (require __DIR__ . '/../bootstrap.php');
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
Пример #26
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet((new Lw\Infrastructure\Ui\Web\Silex\Application())->bootstrap()['em']);
Пример #27
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
$app = new Domora\TvGuide\Application();
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($app['orm.em']);
Пример #28
0
<?php

use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
$app = (include "core/app.php");
return ConsoleRunner::createHelperSet($app['em']);
 /**
  * @Route('/console/createhelpers')
  * @Method('GET')
  * @Name('console.createhelpers')
  */
 public function CreateHelpers()
 {
     ConsoleRunner::createHelperSet($this->getApp()->getEntityManager());
 }
Пример #30
0
<?php

namespace Project;

use Doctrine\ORM\Tools\Console\ConsoleRunner;
chdir(__DIR__);
$autoloader = (require 'vendor/autoload.php');
$app = new Application($autoloader);
$app->loadConfig('app/config');
ob_start();
$app->run();
ob_get_clean();
$em = $app->getServicesFactory()->get('doctrine.em.default');
return ConsoleRunner::createHelperSet($em);