本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Console\Application::getKernel方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getKernel方法的具体用法?PHP Application::getKernel怎么用?PHP Application::getKernel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Bundle\FrameworkBundle\Console\Application
的用法示例。
在下文中一共展示了Application::getKernel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initDB
/**
* create test db.
*/
public function initDB()
{
static::bootKernel();
$this->application = new Application(static::$kernel);
$this->em = $this->getEntityManager();
// drop the database
$command = new DropDatabaseDoctrineCommand();
$this->application->add($command);
$input = new ArrayInput(array('command' => 'doctrine:database:drop', '--force' => true));
$command->run($input, new NullOutput());
// we have to close the connection after dropping the database so we don't get "No database selected" error
$connection = $this->application->getKernel()->getContainer()->get('doctrine')->getConnection();
if ($connection->isConnected()) {
$connection->close();
}
// create the database
$command = new CreateDatabaseDoctrineCommand();
$this->application->add($command);
$input = new ArrayInput(array('command' => 'doctrine:database:create'));
$command->run($input, new NullOutput());
// create schema
$command = new CreateSchemaDoctrineCommand();
$this->application->add($command);
$input = new ArrayInput(array('command' => 'doctrine:schema:create'));
$command->run($input, new NullOutput());
}
示例2: setUp
protected function setUp()
{
self::bootKernel();
$this->application = new Application(self::$kernel);
// Register doctrine bundles
$this->application->add(new LoadDataFixturesCommand($this->application->getKernel()->getContainer()->get('doctrine'), $this->application->getKernel()->getContainer()->get('hautelook_alice.fixtures.loader'), $this->application->getKernel()->getContainer()->get('hautelook_alice.doctrine.finder')));
$this->doctrineManager = $this->application->getKernel()->getContainer()->get('doctrine')->getManager();
$this->application->setAutoExit(false);
$this->runConsole("doctrine:schema:drop", ["--force" => true]);
$this->runConsole("doctrine:schema:create");
}
示例3: addConsoleHelpers
private function addConsoleHelpers(FrameworkApplication $app)
{
if (!Util::hasQuestionHelper()) {
$helper = $app->getKernel()->getContainer()->get('rj_frontend.console.helper.question_legacy');
$app->getHelperSet()->set($helper, 'question');
}
}
示例4: getLogfileContents
/**
* Wrapper function to get whole contents of a particular log file as a string
*
* @param $name
*
* @return string
* @throws Exception is the logfile does not exist
*/
protected function getLogfileContents($name)
{
if (!$this->doesLogfileExist($name)) {
throw new \Exception('Could not file logfile with name \'' . $name . '\' to read contents from for test');
}
return file_get_contents($this->application->getKernel()->getLogDir() . DIRECTORY_SEPARATOR . $name);
}
示例5: setApplicationDocumentManager
/**
* @param Symfony\Bundle\FrameworkBundle\Console\Application
* @param string $dmName
*/
public static function setApplicationDocumentManager(Application $application, $dmName)
{
/** @var $dm \Doctrine\ODM\DocumentManager */
$alias = sprintf("doctrine_mongodb.odm.%s", $dmName);
$dm = $application->getKernel()->getContainer()->get($alias);
$helperSet = $application->getHelperSet();
$helperSet->set(new DocumentManagerHelper($dm), 'dm');
}
示例6: setApplicationDocumentManager
/**
* Set the document manager on the application.
*
* @param Application $application
* @param string $dmName
*/
public static function setApplicationDocumentManager(Application $application, $dmName)
{
/** @var $registry ManagerRegistry */
$registry = $application->getKernel()->getContainer()->get('doctrine_phpcr');
$documentManager = $registry->getManager($dmName);
$helperSet = $application->getHelperSet();
$helperSet->set(new DocumentManagerHelper(null, $documentManager));
}
示例7: setApplicationHelper
public static function setApplicationHelper(Application $application, InputInterface $input)
{
$doctrine = $application->getKernel()->getContainer()->get('doctrine');
if ($doctrine->getManagerNames()) {
self::setApplicationConnection($application, $input->getOption('db'));
} else {
self::setApplicationEntityManager($application, $input->getOption('em'));
}
}
示例8: configureMigrationsForBundle
public static function configureMigrationsForBundle(Application $application, $bundle, Configuration $configuration)
{
$bundle = $application->getKernel()->getBundle($bundle);
$dir = $bundle->getPath() . '/DoctrineMigrations';
$configuration->setMigrationsNamespace($bundle->getNamespace() . '\\DoctrineMigrations');
$configuration->setMigrationsDirectory($dir);
$configuration->registerMigrationsFromDirectory($dir);
$configuration->setName($bundle->getName() . ' Migrations');
$configuration->setMigrationsTableName(Inflector::tableize($bundle->getName()) . '_migration_versions');
}
示例9: testRunImportCommand
public function testRunImportCommand()
{
$application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
$command = $application->find('wallabag:import');
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'userId' => 1, 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir') . '/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', '--importer' => 'v2']);
$this->assertContains('imported', $tester->getDisplay());
$this->assertContains('already saved', $tester->getDisplay());
}
示例10: resolveBundles
/**
* Looks at all the bundles registered in the application to return the bundles requested. An exception is thrown
* if a bundle has not been found.
*
* @param Application $application Application in which bundles will be looked in.
* @param string[] $names Bundle names.
*
* @return BundleInterface[] Bundles requested.
* @throws \RuntimeException A bundle could not be resolved.
*/
public function resolveBundles(Application $application, array $names)
{
$bundles = $application->getKernel()->getBundles();
$result = [];
foreach ($names as $name) {
if (false === isset($bundles[$name])) {
throw new \RuntimeException(sprintf('The bundle "%s" was not found. Bundles availables are: %s.', $name, implode('", "', array_keys($bundles))));
}
$result[$name] = $bundles[$name];
}
return $result;
}
示例11: setApplicationDocumentManager
public static function setApplicationDocumentManager(Application $application, $dmName)
{
$container = $application->getKernel()->getContainer();
$dmName = $dmName ? $dmName : 'default';
$dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName);
if (!$container->has($dmServiceName)) {
throw new \InvalidArgumentException(sprintf('Could not find Doctrine ODM DocumentManager named "%s"', $dmName));
}
$dm = $container->get($dmServiceName);
$helperSet = $application->getHelperSet();
$helperSet->set(new DocumentManagerHelper($dm), 'dm');
}
示例12: setApplicationXmlEntityManager
public static function setApplicationXmlEntityManager(Application $application, $xemName)
{
$container = $application->getKernel()->getContainer();
$xemName = $xemName ? $xemName : 'default';
$xemServiceName = sprintf('doctrine.oxm.%s_xml_entity_manager', $xemName);
if (!$container->has($xemServiceName)) {
throw new \InvalidArgumentException(sprintf('Could not find Doctrine OXM XmlEntityManager named "%s"', $xemName));
}
$xem = $container->get($xemServiceName);
$helperSet = $application->getHelperSet();
$helperSet->set(new XmlEntityManagerHelper($xem), 'xem');
}
示例13: setApplicationConnection
public static function setApplicationConnection(Application $application, $connName)
{
$container = $application->getKernel()->getContainer();
$connName = $connName ? $connName : $container->getParameter('doctrine.dbal.default_connection');
$connServiceName = sprintf('doctrine.dbal.%s_connection', $connName);
if (!$container->has($connServiceName)) {
throw new \InvalidArgumentException(sprintf('Could not find Doctrine Connection named "%s"', $connName));
}
$connection = $container->get($connServiceName);
$helperSet = $application->getHelperSet();
$helperSet->set(new ConnectionHelper($connection), 'db');
}
示例14: configureMigrationsForBundle
public static function configureMigrationsForBundle(Application $application, $bundle, Configuration $configuration)
{
$configuration->setMigrationsNamespace($bundle . '\\DoctrineMigrations');
$dirs = $application->getKernel()->getBundleDirs();
$tmp = str_replace('\\', '/', $bundle);
$namespace = str_replace('/', '\\', dirname($tmp));
$bundle = basename($tmp);
$dir = $dirs[$namespace] . '/' . $bundle . '/DoctrineMigrations';
$configuration->setMigrationsDirectory($dir);
$configuration->registerMigrationsFromDirectory($dir);
$configuration->setName($bundle . ' Migrations');
$configuration->setMigrationsTableName(Inflector::tableize($bundle) . '_migration_versions');
}
示例15: testRunRedisWorkerCommand
public function testRunRedisWorkerCommand()
{
$application = new Application($this->getClient()->getKernel());
$application->add(new RedisWorkerCommand());
$factory = new RedisMockFactory();
$redisMock = $factory->getAdapter('Predis\\Client', true);
$application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock);
// put a fake message in the queue so the worker will stop after reading that message
// instead of waiting for others
$redisMock->lpush('wallabag.import.readability', '{}');
$command = $application->find('wallabag:import:redis-worker');
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'serviceName' => 'readability', '--maxIterations' => 1]);
$this->assertContains('Worker started at', $tester->getDisplay());
$this->assertContains('Waiting for message', $tester->getDisplay());
}