本文整理汇总了PHP中Doctrine\ORM\Tools\Console\ConsoleRunner::createApplication方法的典型用法代码示例。如果您正苦于以下问题:PHP ConsoleRunner::createApplication方法的具体用法?PHP ConsoleRunner::createApplication怎么用?PHP ConsoleRunner::createApplication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\Console\ConsoleRunner
的用法示例。
在下文中一共展示了ConsoleRunner::createApplication方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* {@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: testCreateApplication
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());
}
示例3: registerEntityManager
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]));
});
}
示例4: DbCredentials
//$diff->setMigrationConfiguration($configuration);
//$exec->setMigrationConfiguration($configuration);
//$gen->setMigrationConfiguration($configuration);
//$migrate->setMigrationConfiguration($configuration);
//$status->setMigrationConfiguration($configuration);
//$ver->setMigrationConfiguration($configuration);
//
//$cli = ConsoleRunner::createApplication($helperSet,[
// $diff, $exec, $gen, $migrate, $status, $ver
//]);
//
//return $cli->run();
use Del\Common\Command\Migration;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Del\Common\ContainerService;
use Del\Common\Config\DbCredentials;
$credentials = new DbCredentials();
$container = ContainerService::getInstance()->setDbCredentials($credentials)->addEntityPath('src/Entity')->getContainer();
/** @var Doctrine\ORM\EntityManager $em*/
$em = $container['doctrine.entity_manager'];
$helperSet = ConsoleRunner::createHelperSet($em);
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
$cli = ConsoleRunner::createApplication($helperSet, []);
return $cli->run();
示例5: buildConsole
/**
* Create Doctrine's console application
*
* @return void
*/
public function buildConsole($key = null)
{
$em = $this->proxyEntityManager->on($key);
$helperSet = ConsoleRunner::createHelperSet($em);
return $this->console = ConsoleRunner::createApplication($helperSet);
}
示例6: array
$dcConfig->setProxyNamespace('Orm\\Proxies');
$dcConfig->setEntityNamespaces(array('Orm\\Entity'));
$dcConfig->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\StaticPHPDriver(realpath(BASE_PATH . '/library/Orm/Entity')));
// create db connection (use Zend_Db like at bootstrap)
require_once 'Zend/Db.php';
$dbConfig = $cmsConfig['db'];
$dbAdapter = \Zend_Db::factory($dbConfig['adapter'], $dbConfig);
$connectionOptions = array('pdo' => $dbAdapter->getConnection(), 'dbname' => $dbConfig['dbname']);
// create entity manager
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $dcConfig, new Doctrine\Common\EventManager());
// Create OutputWriter
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$migrationOutputWriter = new \Doctrine\DBAL\Migrations\OutputWriter(function ($message) use($output) {
$output->writeln($message);
});
// create migration commands
$migrationCommands = array(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(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand());
// set config to migration commands
$configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($em->getConnection(), $migrationOutputWriter);
$configuration->setMigrationsTableName('migrations');
$configuration->setMigrationsNamespace('Orm\\Migrations');
$configuration->setMigrationsDirectory(BASE_PATH . '/library/Orm/Migrations/');
$configuration->registerMigrationsFromDirectory(BASE_PATH . '/library/Orm/Migrations/');
foreach ($migrationCommands as $command) {
$command->setMigrationConfiguration($configuration);
}
// Create and run ConsoleRunner
$helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
$cli = \Doctrine\ORM\Tools\Console\ConsoleRunner::createApplication($helperSet, $migrationCommands);
$cli->run(null, $output);
示例7: DbCredentials
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Del\Common\ContainerService;
use Del\Common\Config\DbCredentials;
$credentials = new DbCredentials();
$container = ContainerService::getInstance()->setDbCredentials($credentials)->addEntityPath('src/Entity')->getContainer();
// Fetch the entity Manager
$em = $container['doctrine.entity_manager'];
// Create the helperset
$helperSet = ConsoleRunner::createHelperSet($em);
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
/** Migrations setup */
$configuration = new Configuration($em->getConnection());
$configuration->setMigrationsDirectory('migrations');
$configuration->setMigrationsNamespace('migrations');
$configuration->setMigrationsTableName('Migration');
//$delmigrate = new Migration();
$diff = new DiffCommand();
$exec = new ExecuteCommand();
$gen = new GenerateCommand();
$migrate = new MigrateCommand();
$status = new StatusCommand();
$ver = new VersionCommand();
$diff->setMigrationConfiguration($configuration);
$exec->setMigrationConfiguration($configuration);
$gen->setMigrationConfiguration($configuration);
$migrate->setMigrationConfiguration($configuration);
$status->setMigrationConfiguration($configuration);
$ver->setMigrationConfiguration($configuration);
$cli = ConsoleRunner::createApplication($helperSet, [$diff, $exec, $gen, $migrate, $status, $ver]);
return $cli->run();
示例8: doDoctrine
/**
* Execute the Doctrine CLI tool.
*
* @param array $command The Doctrine command to be executed
*
* @return string The commands output
*/
protected function doDoctrine(array $command = array())
{
try {
// create a local naming directory instance
/** \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */
$namingDirectory = $this->getNamingDirectory();
// the first arguement has to be the application name
$applicationName = array_shift($command);
// try to load the application
/** \AppserverIo\Psr\Application\ApplicationInterface $application */
$application = $namingDirectory->search(sprintf('php:global/%s/env/ApplicationInterface', $applicationName));
// the second arguement has to be the persistence unit name
$persistenUnitName = array_shift($command);
// try to load the application's entity manager
/** \Doctrine\ORM\EntityManagerInterface $entityManager */
$entityManager = $application->search($persistenUnitName);
// initialize the helper set with the entity manager instance
/** \Symfony\Component\Console\Helper\HelperSet $helperSet */
$helperSet = ConsoleRunner::createHelperSet($entityManager);
// create the Symfony Console application
/** \Symfony\Component\Console\Application $app */
$app = \Doctrine\ORM\Tools\Console\ConsoleRunner::createApplication($helperSet);
$app->setAutoExit(false);
// register the applications class loaders
$application->registerClassLoaders();
// as Doctrine CLI uses Symfony Console component, we've to simulate the commandline args
$argv = array('doctrine');
$argv = array_merge($argv, $command);
// create a new instance of the commandline args
$argvInput = new \Symfony\Component\Console\Input\ArgvInput($argv);
// run the Symfony Console application
$app->run($argvInput, $buffer = new BufferedOutput());
// log a debug message with the output
$this->getSystemLogger()->debug($result = $buffer->fetch());
// return the output
return $result;
} catch (\Exception $e) {
// log the exception
$this->getSystemLogger()->error($e->__toString());
// return the stack trace
return $e->getMessage() . PHP_EOL;
}
}
示例9:
<?php
require __DIR__ . '/vendor/autoload.php';
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Jgut\Slim\Doctrine\EntityManagerBuilder;
$settings = (include 'app/settings.php');
$settings = $settings['settings']['doctrine'];
$entityManager = EntityManagerBuilder::build($settings);
$helperSet = ConsoleRunner::createHelperSet($entityManager);
$cli = ConsoleRunner::createApplication($helperSet, [new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand()]);
return $cli->run();