本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Console\Application类的典型用法代码示例。如果您正苦于以下问题:PHP Application类的具体用法?PHP Application怎么用?PHP Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: report
private function report(Application $application)
{
$output = new BufferedOutput();
$arguments = array('this will be ignored', 'nucleus_migration:report');
$application->run(new ArgvInput($arguments), $output);
return $output->fetch();
}
示例2: setUpBeforeClass
public static function setUpBeforeClass()
{
@unlink(__DIR__ . '/../Fixtures/Test/TestBundle/Resources/config/routing.rest.yml');
@unlink(__DIR__ . '/../Fixtures/Test/TestBundle/Controller/CarController.php');
@unlink(__DIR__ . '/../Fixtures/Test/TestBundle/Controller/OrderController.php');
$kernel = new \AppKernel('test', true);
$app = new Application($kernel);
$app->addCommands(array(new GenerateRestControllerCommand()));
$kernel->boot();
$command = $app->find('generate:rest:controller');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName(), '--controller' => 'TestTestBundle:Order', '--entity' => 'TestTestBundle:Order', '--mongo' => true), array('interactive' => false));
$kernel->shutdown();
$kernel = new \AppKernel('test', true);
$app = new Application($kernel);
$app->addCommands(array(new GenerateRestControllerCommand()));
$kernel->boot();
$command = $app->find('generate:rest:controller');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName(), '--controller' => 'TestTestBundle:Car', '--entity' => 'TestTestBundle:Car'), array('interactive' => false));
$kernel->shutdown();
@unlink(__DIR__ . '/../app/cache/test/appTestUrlGenerator.php.meta');
@unlink(__DIR__ . '/../app/cache/test/appTestUrlGenerator.php');
@unlink(__DIR__ . '/../app/cache/test/appTestUrlMatcher.php.meta');
@unlink(__DIR__ . '/../app/cache/test/appTestUrlMatcher.php');
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$locator = $this->getContainer()->get('campaignchain.core.module.locator');
$bundles = $locator->getAvailableBundles();
$selectedBundle = $this->selectBundle($bundles);
$generateOutput = new BufferedOutput();
$application = new Application($this->getContainer()->get('kernel'));
$application->setAutoExit(false);
$application->run(new ArrayInput(['command' => $this->getDoctrineMigrationsCommand(), '--no-interaction' => true]), $generateOutput);
preg_match('/Generated new migration class to "(.*)"/', $generateOutput->fetch(), $matches);
if (count($matches) < 2) {
//error
return;
}
$pathForMigrationFile = $matches[1];
preg_match('/Version.*.php/', $pathForMigrationFile, $fileNames);
if (!count($fileNames)) {
return;
}
$schemaFile = $this->getContainer()->getParameter('kernel.root_dir') . DIRECTORY_SEPARATOR . '..';
$schemaFile .= DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $selectedBundle->getName();
$schemaFile .= str_replace('/', DIRECTORY_SEPARATOR, $this->getContainer()->getParameter('campaignchain_update.bundle.schema_dir'));
$schemaFile .= DIRECTORY_SEPARATOR . $fileNames[0];
$fs = new Filesystem();
$fs->copy($pathForMigrationFile, $schemaFile);
$fs->remove($pathForMigrationFile);
$this->io->success('Generation finished. You can find the file here:');
$this->io->text($schemaFile);
}
示例4: initDatabase
private static function initDatabase()
{
$console = new Application(static::$kernel);
$console->setAutoExit(false);
/**
* SQLite is not supported yet
*
* @link https://github.com/doctrine/dbal/pull/2402
*/
$commands = ['doctrine:database:create' => ['--if-not-exists' => true], 'doctrine:schema:drop' => ['--full-database' => true, '--force' => true], 'doctrine:migrations:migrate' => [], 'doctrine:fixtures:load' => []];
foreach ($commands as $command => $args) {
/** apply common commands options */
$args['--env'] = 'test';
$args['--quiet'] = true;
$args['--no-interaction'] = true;
$args['command'] = $command;
try {
$console->setCatchExceptions(false);
$console->run(new ArrayInput($args));
} catch (\Exception $e) {
echo PHP_EOL . $e->getMessage() . PHP_EOL;
echo PHP_EOL . $e->getTraceAsString() . PHP_EOL;
throw $e;
}
}
}
示例5: iRunSyliusInstallSampleDataCommand
/**
* @Given I run Sylius Install Load Sample Data command
*/
public function iRunSyliusInstallSampleDataCommand()
{
$this->application = new Application($this->kernel);
$this->application->add(new InstallSampleDataCommand());
$this->command = $this->application->find('sylius:install:sample-data');
$this->tester = new CommandTester($this->command);
}
示例6: executeCommand
/**
* Executor which runs a command.
*
* @param string $name
* @param array $args
*
* @return CommandTester
*/
protected function executeCommand(string $name, array $args = []) : CommandTester
{
$application = new Application($this->getKernel());
$tester = new CommandTester($application->get($name));
$tester->execute($args, ['interactive' => false]);
return $tester;
}
示例7: setUp
/**
* Set up test
*/
public function setUp()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
static::$application = new Application(static::$kernel);
static::$application->setAutoExit(false);
}
示例8: executeCommand
function executeCommand(Application $app, $cmd, array $options = [])
{
$options['--env'] = 'test';
$options['--quiet'] = true;
$options['command'] = $cmd;
$app->run(new ArrayInput($options));
}
示例9: cleanDB
/**
* @BeforeScenario @cleanDB
* @AfterScenario @cleanDB
*/
public function cleanDB()
{
$application = new Application($this->getKernel());
$application->setAutoExit(false);
$application->run(new StringInput("doctrine:schema:drop --force -n -q"));
$application->run(new StringInput("doctrine:schema:create -n -q"));
}
示例10: clearCache
/**
* Clear the application cache and run the warmup routine for the current environment
*
* @param bool $noWarmup Skips the warmup routine
*
* @return void
*/
public function clearCache($noWarmup = false)
{
$this->clearSessionItems();
// Force a refresh of enabled addon bundles so they are picked up by the events
$addonHelper = $this->factory->getHelper('addon');
$addonHelper->buildAddonCache();
ini_set('memory_limit', '128M');
//attempt to squash command output
ob_start();
$env = $this->factory->getEnvironment();
$args = array('console', 'cache:clear', '--env=' . $env);
if ($env == 'prod') {
$args[] = '--no-debug';
}
if ($noWarmup) {
$args[] = '--no-warmup';
}
$input = new ArgvInput($args);
$application = new Application($this->factory->getKernel());
$application->setAutoExit(false);
$output = new NullOutput();
$application->run($input, $output);
if (ob_get_length() > 0) {
ob_end_clean();
}
}
示例11: runCommand
public function runCommand($commandServiceId, array $input = array())
{
$this->errorCode = null;
$this->commandTester = null;
$command = $this->grabServiceFromContainer($commandServiceId);
$application = new Application($this->kernel);
$application->add($command);
$commandTester = new CommandTester($command);
try {
$commandTester->execute(array('command' => $command->getName()) + $input, array('interactive' => false));
} catch (\Exception $e) {
$exitCode = $e->getCode();
if (is_numeric($exitCode)) {
$exitCode = (int) $exitCode;
if (0 === $exitCode) {
$exitCode = 1;
}
} else {
$exitCode = 1;
}
$this->errorCode = $exitCode;
$this->debug((string) $e);
return;
}
$this->debug($commandTester->getDisplay());
$this->commandTester = $commandTester;
}
示例12: testCacheIsFreshAfterCacheClearedWithWarmup
public function testCacheIsFreshAfterCacheClearedWithWarmup()
{
$input = new ArrayInput(array('cache:clear'));
$application = new Application($this->kernel);
$application->setCatchExceptions(false);
$application->doRun($input, new NullOutput());
// Ensure that all *.meta files are fresh
$finder = new Finder();
$metaFiles = $finder->files()->in($this->kernel->getCacheDir())->name('*.php.meta');
// simply check that cache is warmed up
$this->assertGreaterThanOrEqual(1, count($metaFiles));
foreach ($metaFiles as $file) {
$configCache = new ConfigCache(substr($file, 0, -5), true);
$this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file));
}
// check that app kernel file present in meta file of container's cache
$containerRef = new \ReflectionObject($this->kernel->getContainer());
$containerFile = $containerRef->getFileName();
$containerMetaFile = $containerFile . '.meta';
$kernelRef = new \ReflectionObject($this->kernel);
$kernelFile = $kernelRef->getFileName();
/** @var ResourceInterface[] $meta */
$meta = unserialize(file_get_contents($containerMetaFile));
$found = false;
foreach ($meta as $resource) {
if ((string) $resource === $kernelFile) {
$found = true;
break;
}
}
$this->assertTrue($found, 'Kernel file should present as resource');
}
示例13: testPromotion
public function testPromotion()
{
$kernel = $this->createKernel();
$command = new PromoteSuperAdminCommand();
$application = new Application($kernel);
$application->setAutoExit(false);
$tester = new ApplicationTester($application);
$username = 'test_username';
$password = 'test_password';
$email = 'test_email@email.org';
$userManager = $kernel->getContainer()->get('fos_user.user_manager');
$user = $userManager->createUser();
$user->setUsername($username);
$user->setEmail($email);
$user->setPlainPassword($password);
$userManager->updateUser($user);
$this->assertFalse($user->hasRole('ROLE_SUPERADMIN'));
$tester->run(array(
'command' => $command->getFullName(),
'username' => $username,
), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
$userManager = $this->getService('fos_user.user_manager');
$user = $userManager->findUserByUsername($username);
$this->assertTrue($user instanceof User);
$this->assertTrue($user->hasRole('ROLE_SUPERADMIN'));
$userManager->deleteUser($user);
}
示例14: coreTest
protected function coreTest(array $arguments)
{
$input = new ArrayInput($arguments);
$application = new Application(static::$kernel);
$application->setCatchExceptions(false);
$application->doRun($input, new NullOutput());
// Ensure that all *.meta files are fresh
$finder = new Finder();
$metaFiles = $finder->files()->in(static::$kernel->getCacheDir())->name('*.php.meta');
// simply check that cache is warmed up
$this->assertGreaterThanOrEqual(1, count($metaFiles));
foreach ($metaFiles as $file) {
$configCache = new ConfigCache(substr($file, 0, -5), true);
$this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file));
}
// check that app kernel file present in meta file of container's cache
$containerRef = new \ReflectionObject(static::$kernel->getContainer());
$containerFile = $containerRef->getFileName();
$containerMetaFile = $containerFile . '.meta';
$kernelRef = new \ReflectionObject(static::$kernel);
$kernelFile = $kernelRef->getFileName();
/** @var ResourceInterface[] $meta */
$meta = unserialize(file_get_contents($containerMetaFile));
$found = false;
foreach ($meta as $resource) {
if ((string) $resource === $kernelFile) {
$found = true;
break;
}
}
$this->assertTrue($found, 'Kernel file should present as resource');
$this->assertRegExp(sprintf('/\'kernel.name\'\\s*=>\\s*\'%s\'/', static::$kernel->getName()), file_get_contents($containerFile), 'kernel.name is properly set on the dumped container');
$this->assertEquals(ini_get('memory_limit'), '1024M');
}
示例15: testFileSaveUpload
/**
* test saving entity with file property from parent abstract uploadable class
*/
public function testFileSaveUpload()
{
$client = $this->createClient();
$this->importDatabaseSchema();
$file = new File();
$existsFile = new \Symfony\Component\HttpFoundation\File\File(__DIR__ . '/../Fixtures/files/text.txt');
$file->setTitle('new file')->setDate(new \DateTime('2013-04-04'))->setFile($existsFile);
$this->getEntityManager()->persist($file);
$this->getEntityManager()->flush();
$this->assertSame($file->getFile(), array('fileName' => '/File/file/2013/1.txt', 'originalName' => 'text.txt', 'mimeType' => 'text/plain', 'size' => 9, 'path' => '/file/File/file/2013/1.txt'));
unset($file);
$this->getEntityManager()->clear();
$this->getKernel()->shutdown();
$client = $this->createClient(array('config' => 'default_newfilepath.yml'));
$application = new Application($client->getKernel());
$application->add(new RepairFileDataCommand());
$command = $application->find('iphp:filestore:repair');
$commandTester = new CommandTester($command);
//using web directory setted in config/default.yml
$commandTester->execute(array('command' => $command->getName(), '--entity' => 'TestXmlConfigBundle:File', '--field' => 'file', '--force' => 1, '--webdir' => realpath($this->getContainer()->getParameter('kernel.test_env_dir') . '/web/')));
$newFile = $this->getEntityManager()->getRepository('TestXmlConfigBundle:File')->findOneByTitle('new file');
$this->assertSame($newFile->getFile(), array('fileName' => '/1/new-file.txt', 'originalName' => 'text.txt', 'mimeType' => 'text/plain', 'size' => 9, 'path' => '/other/uploads/1/new-file.txt'));
unset($newFile);
unset($commandTester);
unset($command);
unset($application);
$this->getEntityManager()->clear();
$this->getKernel()->shutdown();
}