本文整理汇总了PHP中Symfony\Component\Console\Input\ArgvInput类的典型用法代码示例。如果您正苦于以下问题:PHP ArgvInput类的具体用法?PHP ArgvInput怎么用?PHP ArgvInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArgvInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor. This is run before any modules are loaded, so we can
* initialise the console here.
*
* @param ContainerInterface $container The service container
* @param array|null $arguments Arguments to pass into the Console component
*
* @todo Change the environment earlier if possible. Can we make the context
* run something before even Cog is bootstrapped?
*/
public function __construct(ContainerInterface $container, array $arguments = null)
{
$this->_services = $container;
$this->_services['console.commands'] = function () {
return new CommandCollection(array(new Command\EventList(), new Command\ModuleList(), new Command\RouteList(), new Command\RouteCollectionTree(), new Command\Setup(), new Command\Status(), new Command\TaskGenerate(), new Command\TaskList(), new Command\TaskRun(), new Command\TaskRunScheduled(), new Command\AssetDump(), new Command\AssetGenerator(), new Command\MigrateInstall(), new Command\MigrateRollback(), new Command\MigrateReset(), new Command\MigrateRefresh(), new Command\MigrateRun(), new Command\DeployEvent(), new Command\DeployPermissions(), new Command\ModuleNamespace(), new Command\CacheClear()));
};
$this->_services['console.app'] = function ($c) {
$app = new Application();
$app->setContainer($c);
$app->getDefinition()->addOption(new InputOption('--' . $app::ENV_OPT_NAME, '', InputOption::VALUE_OPTIONAL, 'The Environment name.'));
// Add the commands
foreach ($c['console.commands'] as $command) {
$app->add($command);
}
return $app;
};
if (null === $arguments) {
$arguments = $_SERVER['argv'];
}
$input = new ArgvInput($arguments);
if ($env = $input->getParameterOption(array('--env'), '')) {
$this->_services['environment']->setWithInstallation($env);
}
// Setup a fake request context
$this->_services['http.request.context'] = function ($c) {
$context = new \Message\Cog\Routing\RequestContext();
return $context;
};
}
示例2: loadCommands
/**
* @param OutputInterface $output
*/
public function loadCommands(OutputInterface $output)
{
// $application is required to be defined in the register_command scripts
$application = $this->application;
require_once \OC::$SERVERROOT . '/core/register_command.php';
if ($this->config->getSystemValue('installed', false)) {
if (!\OCP\Util::needUpgrade()) {
OC_App::loadApps();
foreach (OC_App::getAllApps() as $app) {
$file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
if (file_exists($file)) {
require $file;
}
}
} else {
$output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available");
}
} else {
$output->writeln("ownCloud is not installed - only a limited number of commands are available");
}
$input = new ArgvInput();
if ($input->getFirstArgument() !== 'check') {
$errors = \OC_Util::checkServer(\OC::$server->getConfig());
if (!empty($errors)) {
foreach ($errors as $error) {
$output->writeln($error['error']);
$output->writeln($error['hint']);
$output->writeln('');
}
throw new \Exception("Environment not properly prepared.");
}
}
}
示例3: testExecute_SpecificEntity_Association
/**
* @see FixturesExportCommand::execute
*/
public function testExecute_SpecificEntity_Association()
{
$directoryPath = sys_get_temp_dir();
$dumper = $this->getMockBuilder('\\Cosma\\Bundle\\TestingBundle\\Fixture\\Dumper')->disableOriginalConstructor()->setMethods(['dumpToYaml', 'setAssociation', 'setClassMetadataInfo'])->getMock();
$dumper->expects($this->once())->method('dumpToYaml')->with($directoryPath)->will($this->returnValue($directoryPath . '/table.yml'));
$dumper->expects($this->once())->method('setAssociation')->with(true)->will($this->returnValue(null));
$classMetaDataInfo = $this->getMockBuilder('\\Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
$dumper->expects($this->once())->method('setClassMetadataInfo')->with($classMetaDataInfo)->will($this->returnValue(null));
$metaDataFactory = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\Mapping\\ClassMetadataFactory')->disableOriginalConstructor()->setMethods(['getMetadataFor'])->getMockForAbstractClass();
$metaDataFactory->expects($this->once())->method('getMetadataFor')->with('BundleName:EntityName')->will($this->returnValue($classMetaDataInfo));
$entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['getMetadataFactory'])->getMock();
$entityManager->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metaDataFactory));
$doctrine = $this->getMockBuilder('\\Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->setMethods(['getManager'])->getMock();
$doctrine->expects($this->once())->method('getManager')->will($this->returnValue($entityManager));
$container = new Container();
$container->set('doctrine', $doctrine);
$container->set('cosma_testing.fixture_dumper', $dumper);
$command = $this->getMockBuilder('\\Cosma\\Bundle\\TestingBundle\\Command\\FixturesExportCommand')->disableOriginalConstructor()->setMethods(['getContainer'])->getMock();
$command->expects($this->exactly(2))->method('getContainer')->will($this->returnValue($container));
$reflectionClass = new \ReflectionClass($command);
$dumperProperty = $reflectionClass->getParentClass()->getProperty('dumper');
$dumperProperty->setAccessible(true);
$dumperProperty->setValue($command, $dumper);
$inputDefinition = new InputDefinition([new InputArgument('dumpDirectory', InputArgument::REQUIRED), new InputArgument('entity', InputArgument::OPTIONAL), new InputOption('associations', 'a', InputOption::VALUE_NONE)]);
$input = new ArgvInput(['dummySoInputValidates' => 'dummy', 'dumpDirectory' => $directoryPath, 'entity' => 'BundleName:EntityName'], $inputDefinition);
$input->setOption('associations', true);
$output = new BufferedOutput();
$reflectionClass = new \ReflectionClass($command);
$executeMethod = $reflectionClass->getMethod('execute');
$executeMethod->setAccessible(true);
$executeMethod->invoke($command, $input, $output);
$this->assertContains("successfully dumped in file {$directoryPath}/table.yml", $output->fetch(), 'The entity was not dump successfully');
}
示例4: initComposer
public function initComposer(OutputInterface $output)
{
$input = new ArgvInput(['composer', 'init']);
$input->setInteractive(true);
/** @var InitCommand $command */
$command = $this->getHelperSet()->getCommand()->getApplication()->find('init');
return $this->execute($input, $output, $command);
}
示例5: bin
/**
* `psysh` command line executable.
*
* @return Closure
*/
function bin()
{
return function () {
$usageException = null;
$input = new ArgvInput();
try {
$input->bind(new InputDefinition(array(new InputOption('help', 'h', InputOption::VALUE_NONE), new InputOption('config', 'c', InputOption::VALUE_REQUIRED), new InputOption('version', 'v', InputOption::VALUE_NONE), new InputOption('cwd', null, InputOption::VALUE_REQUIRED), new InputArgument('include', InputArgument::IS_ARRAY))));
} catch (\RuntimeException $e) {
$usageException = $e;
}
$config = array();
// Handle --config
if ($configFile = $input->getOption('config')) {
$config['configFile'] = $configFile;
}
$shell = new Shell(new Configuration($config));
// Handle --help
if ($usageException !== null || $input->getOption('help')) {
if ($usageException !== null) {
echo $usageException->getMessage() . PHP_EOL . PHP_EOL;
}
$version = $shell->getVersion();
$name = basename(reset($_SERVER['argv']));
echo <<<EOL
{$version}
Usage:
{$name} [--version] [--help] [files...]
Options:
--help -h Display this help message.
--config -c Use an alternate PsySH config file location.
--cwd Use an alternate working directory.
--version -v Display the PsySH version.
EOL;
exit($usageException === null ? 0 : 1);
}
// Handle --version
if ($input->getOption('version')) {
echo $shell->getVersion() . PHP_EOL;
exit(0);
}
// Pass additional arguments to Shell as 'includes'
$shell->setIncludes($input->getArgument('include'));
try {
// And go!
$shell->run();
} catch (Exception $e) {
echo $e->getMessage() . PHP_EOL;
// TODO: this triggers the "exited unexpectedly" logic in the
// ForkingLoop, so we can't exit(1) after starting the shell...
// fix this :)
// exit(1);
}
};
}
示例6: __construct
public function __construct(ConsoleOutput $output, ArgvInput $input)
{
$this->output = $output;
$env = $input->getParameterOption(['-e', '--env']);
if (!$env) {
$env = 'dev';
}
$this->kernel($env);
}
示例7: isSafe
public function isSafe(ArgvInput $input, $env)
{
if ('prod' == $env) {
if (in_array($input->getFirstArgument(), $this->productionBlackList)) {
return false;
}
}
return true;
}
示例8: isProfileOption
/**
* We need to add the profile enable option to all commands if we are in
* the parameter mode.
*
* Inspired by
* http://php-and-symfony.matthiasnoback.nl/2013/11/symfony2-add-a-global-option-to-console-commands-and-generate-pid-file/
*
* @param ConsoleCommandEvent $event
* @return mixed
*/
private function isProfileOption(ConsoleCommandEvent $event)
{
$inputDefinition = $event->getCommand()->getApplication()->getDefinition();
$inputDefinition->addOption(new InputOption($this->optionName, null, InputOption::VALUE_NONE, '<info>JnsXhprofBundle</info>: Whether to profile this command with xhprof', null));
// merge the application's input definition
$event->getCommand()->mergeApplicationDefinition();
$input = new ArgvInput();
// we use the input definition of the command
$input->bind($event->getCommand()->getDefinition());
return $input->getOption($this->optionName);
}
示例9: runLocateFile
/**
* Do the locateFile Action
*
* @param $arg
* @param $dir
* @return string
*/
protected function runLocateFile($arg, $dir)
{
chdir($this->baseDir . '/' . $dir);
$definition = new InputDefinition(array(new InputOption('configuration')));
$input = new ArgvInput(array(), $definition);
if ($arg) {
$input->setOption('configuration', $arg);
}
$command = new VoidCommand('void');
return $command->locateConfigFile($input);
}
示例10: __construct
/**
* @param ConsoleOutput $output
* @param ArgvInput $input
*/
public function __construct(ConsoleOutput $output, ArgvInput $input)
{
$this->output = $output;
$env = $input->getParameterOption(['-e', '--env']);
if (!$env) {
$env = 'dev';
}
$this->bootKernel($env);
$schemaHelper = new SchemaHelper($this->container);
$this->productTemplateTable = $schemaHelper->getTableOrCollection('product_template');
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('loading all fixtures...........');
$input = new ArgvInput();
$input->setInteractive(false);
$command = $this->getApplication()->find('doctrine:fixtures:load');
$command->run($input, new NullOutput());
$output->writeln('<info>OK</info>');
$output->write('setting up match fixtures......');
$this->getContainer()->get('oss.league.service.fixture')->createFixtures(1);
$output->writeln('<info>OK</info>');
}
示例12: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$definition = $this->getDefinition();
$arguments = $definition->getArguments();
$arguments['target']->setDefault($this->container->getParameter('kernel.root_dir') . '/../web/');
$definition->setArguments($arguments);
if (count($input->getArguments()) === 0) {
$input = new ArgvInput(null, $definition);
$input->setArgument('target', $this->container->getParameter('kernel.root_dir') . '/../web/');
}
return parent::execute($input, $output);
}
示例13: runCLI
public static function runCLI($environment = 'dev', $debug = true)
{
set_time_limit(0);
$input = new ArgvInput();
$environment = $input->getParameterOption(array('--env', '-e'), $environment);
$debug = !$input->hasParameterOption(array('--no-debug', '')) && $environment !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new static($environment, $debug);
$application = new Application($kernel);
$application->run($input);
}
示例14: console
/**
* Runs Symfony2 in console mode.
*
* @param string $kernelClass Class name for the kernel to be ran.
*/
public static function console($kernelClass)
{
set_time_limit(0);
$input = new ArgvInput();
// decide env and debug info based on cli params
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new $kernelClass($env, $debug);
$application = new Application($kernel);
$application->run($input);
}
示例15: requirePackage
public function requirePackage(OutputInterface $output, $package, $version = null, $dev = true)
{
$packageArg = sprintf("%s%s", $package, $version != null ? ':' . $version : null);
$args = ['composer', 'require'];
if ($dev) {
$args[] = '--dev';
}
$args[] = $packageArg;
$input = new ArgvInput($args);
$input->setInteractive(true);
/** @var RequireCommand $command */
$command = $this->getHelperSet()->getCommand()->getApplication()->find('require');
return $this->execute($input, $output, $command);
}