本文整理汇总了PHP中Symfony\Component\Console\Input\InputInterface::getOption方法的典型用法代码示例。如果您正苦于以下问题:PHP InputInterface::getOption方法的具体用法?PHP InputInterface::getOption怎么用?PHP InputInterface::getOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\InputInterface
的用法示例。
在下文中一共展示了InputInterface::getOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$url = $input->getOption('url');
$email = $input->getOption('email');
$disable = $input->getOption('disable');
$events = $input->getOption('event');
if (!$url && !$email) {
$output->writeln('<error>Must specify either a url or an email address</error>');
return;
}
if ($url && $email) {
$output->writeln('<error>Must specify only a url or an email address</error>');
return;
}
if (!($resource = $this->getResource('webhook', $output))) {
return;
}
if ($url) {
$resource->setUrl($url);
} else {
$resource->setEmail($email);
}
$resource->setEventTypes($events ? $events : Webhook::$events);
$this->getApi()->create($resource);
$resource = $this->getApi()->getLastResponse();
$resource = $resource['body']['data'];
$table = $this->getHelperSet()->get('table');
$this->formatTableRow($resource, $table, false);
$output->writeln('<info>Webhook created</info>');
$table->render($output);
}
示例2: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws InvalidArgumentException
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output, true);
if (!$this->initMagento()) {
return;
}
$type = $input->getArgument('type');
$areas = array('global', 'adminhtml', 'frontend', 'crontab');
if ($type === null) {
$type = $this->askForArrayEntry($areas, $output, 'Please select an area:');
}
if (!in_array($type, $areas)) {
throw new InvalidArgumentException('Invalid type! Use one of: ' . implode(', ', $areas));
}
if ($input->getOption('format') === null) {
$this->writeSection($output, 'Observers: ' . $type);
}
$frontendEvents = \Mage::getConfig()->getNode($type . '/events')->asArray();
if (true === $input->getOption('sort')) {
// sorting for Observers is a bad idea because the order in which observers will be called is important.
ksort($frontendEvents);
}
$table = array();
foreach ($frontendEvents as $eventName => $eventData) {
$observerList = array();
foreach ($eventData['observers'] as $observer) {
$observerList[] = $this->getObserver($observer, $type);
}
$table[] = array($eventName, implode("\n", $observerList));
}
$this->getHelper('table')->setHeaders(array('Event', 'Observers'))->setRows($table)->renderByFormat($output, $table, $input->getOption('format'));
}
示例3: listItems
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
{
// only list constants when no Reflector is present.
//
// TODO: make a NamespaceReflector and pass that in for commands like:
//
// ls --constants Foo
//
// ... for listing constants in the Foo namespace
if ($reflector !== null || $target !== null) {
return;
}
// only list constants if we are specifically asked
if (!$input->getOption('constants')) {
return;
}
$category = $input->getOption('user') ? 'user' : $input->getOption('category');
$label = $category ? ucfirst($category) . ' Constants' : 'Constants';
$constants = $this->prepareConstants($this->getConstants($category));
if (empty($constants)) {
return;
}
$ret = array();
$ret[$label] = $constants;
return $ret;
}
示例4: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
$oldCacheDir = $realCacheDir . '_old';
$filesystem = $this->getContainer()->get('filesystem');
if (!is_writable($realCacheDir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
}
if ($filesystem->exists($oldCacheDir)) {
$filesystem->remove($oldCacheDir);
}
$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
if ($input->getOption('no-warmup')) {
$filesystem->rename($realCacheDir, $oldCacheDir);
} else {
// the warmup cache dir name must have the same length than the real one
// to avoid the many problems in serialized resources files
$warmupDir = substr($realCacheDir, 0, -1) . '_';
if ($filesystem->exists($warmupDir)) {
$filesystem->remove($warmupDir);
}
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
$filesystem->rename($realCacheDir, $oldCacheDir);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
sleep(1);
// workaround for windows php rename bug
}
$filesystem->rename($warmupDir, $realCacheDir);
}
$filesystem->remove($oldCacheDir);
}
示例5: execute
/**
* @see \Symfony\Component\Console\Command\Command::execute()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$key = $input->getArgument('key');
if ($input->getOption('file')) {
$file = $input->getOption('file');
} else {
$file = 'config.yml';
}
try {
$yaml = new YamlUpdater($this->app, $file);
$match = $yaml->get($key);
if (!empty($match)) {
$result = sprintf("%s: %s", $key, $match);
} else {
$result = sprintf("<error>The key '%s' was not found in %s.</error>", $key, $file);
}
} catch (FileNotFoundException $e) {
$result = sprintf("<error>Can't read file: %s.</error>", $file);
} catch (ParseException $e) {
$result = sprintf("<error>Invalid YAML in file: %s.</error>", $file);
} catch (FilesystemException $e) {
$result = sprintf('<error>' . $e->getMessage() . '</error>');
}
$output->writeln($result);
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('list')) {
$this->listImport($output);
return;
}
$importRef = $input->getArgument('ref');
$path = $input->getArgument('filePath');
if ($importRef === null || $path === null) {
throw new \RuntimeException('Not enough arguments.' . PHP_EOL . 'If no options are provided, ref and filePath arguments are required.');
}
/** @var \Thelia\Handler\ImportHandler $importHandler */
$importHandler = $this->getContainer()->get('thelia.import.handler');
$import = $importHandler->getImportByRef($importRef);
if ($import === null) {
throw new \RuntimeException($importRef . ' import doesn\'t exist.');
}
$importEvent = $importHandler->import($import, new File($input->getArgument('filePath')), (new LangQuery())->findOneByLocale($input->getOption('locale')));
$formattedLine = $this->getHelper('formatter')->formatBlock('Successfully import ' . $importEvent->getImport()->getImportedRows() . ' row(s)', 'fg=black;bg=green', true);
$output->writeln($formattedLine);
if (count($importEvent->getErrors()) > 0) {
$formattedLine = $this->getHelper('formatter')->formatBlock('With error', 'fg=black;bg=yellow', true);
$output->writeln($formattedLine);
foreach ($importEvent->getErrors() as $error) {
$output->writeln('<comment>' . $error . '</comment>');
}
}
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
foreach ($this->dropOrder as $option) {
if ($input->getOption($option)) {
$drop[] = $option;
}
}
// Default to the full drop order if no options were specified
$drop = empty($drop) ? $this->dropOrder : $drop;
$class = $input->getOption('class');
$sm = $this->getSchemaManager();
$isErrored = false;
foreach ($drop as $option) {
try {
if (isset($class)) {
$this->{'processDocument' . ucfirst($option)}($sm, $class);
} else {
$this->{'process' . ucfirst($option)}($sm);
}
$output->writeln(sprintf('Dropped <comment>%s%s</comment> for <info>%s</info>', $option, isset($class) ? self::INDEX === $option ? '(es)' : '' : (self::INDEX === $option ? 'es' : 's'), isset($class) ? $class : 'all classes'));
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$isErrored = true;
}
}
return $isErrored ? 255 : 0;
}
示例8: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output, $dialog);
}
$input->setOption('module', $module);
// --bundle-name option
$bundle_name = $input->getOption('bundle-name');
if (!$bundle_name) {
$bundle_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.contenttype.questions.bundle-name'), 'default'), function ($bundle_name) {
return $this->validateClassName($bundle_name);
}, false, 'default', null);
}
$input->setOption('bundle-name', $bundle_name);
// --bundle-title option
$bundle_title = $input->getOption('bundle-title');
if (!$bundle_title) {
$bundle_title = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.contenttype.questions.bundle-title'), 'default'), function ($bundle_title) {
return $this->validateClassName($bundle_title);
}, false, 'default', null);
}
$input->setOption('bundle-title', $bundle_title);
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
ini_set('memory_limit', -1);
set_time_limit(0);
$this->output = $output;
$this->em = $this->getContainer()->get('doctrine')->getManager();
$siteId = (int) $input->getOption('site_id');
$this->site = $this->em->getRepository('SudouxCmsSiteBundle:Site')->find($siteId);
if (!isset($this->site)) {
throw new \Exception("Site was not found");
}
$availableFunctions = array('import_branches_from_csv');
$function = $input->getArgument('function');
if (!in_array($function, $availableFunctions)) {
throw new \Exception("Function does not exist");
}
switch ($function) {
case 'import_branches_from_csv':
$csvPath = $input->getOption('csv_path');
if (empty($csvPath)) {
throw new \Exception("Option --csv_path cannot be empty");
}
$this->importBranchesFromCsv($csvPath);
break;
}
}
示例10: execute
/**
* Execute the command.
*
* @param Input $input
* @param Output $output
* @return void
*/
protected function execute(Input $input, Output $output)
{
$name = $input->getArgument("name");
// Validate the name straight away.
if (count($chunks = explode("/", $name)) != 2) {
throw new \InvalidArgumentException("Invalid repository name '{$name}'.");
}
$output->writeln(sprintf("Cloning <comment>%s</comment> into <info>%s/%s</info>...", $name, getcwd(), end($chunks)));
// If we're in a test environment, stop executing.
if (defined("ADVISER_UNDER_TEST")) {
return null;
}
// @codeCoverageIgnoreStart
if (!$this->git->cloneGithubRepository($name)) {
throw new \UnexpectedValueException("Repository https://github.com/{$name} doesn't exist.");
}
// Change the working directory.
chdir($path = getcwd() . "/" . end($chunks));
$output->writeln(sprintf("Changed the current working directory to <comment>%s</comment>.", $path));
$output->writeln("");
// Running "AnalyseCommand"...
$arrayInput = [""];
if (!is_null($input->getOption("formatter"))) {
$arrayInput["--formatter"] = $input->getOption("formatter");
}
$this->getApplication()->find("analyse")->run(new ArrayInput($arrayInput), $output);
// Change back, remove the directory.
chdir(getcwd() . "/..");
$this->removeDirectory($path);
$output->writeln("");
$output->writeln(sprintf("Switching back to <info>%s</info>, removing <comment>%s</comment>...", getcwd(), $path));
// @codeCoverageIgnoreStop
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$noDevMode = (bool) $input->getOption('no-dev');
$optimize = (bool) $input->getOption('optimize-autoloader');
$build = new Build(new ConsoleIO($input, $output, $this->getHelperSet()));
$build->build(getcwd(), $optimize, $noDevMode);
}
示例12: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$suite = $input->getArgument('suite');
$step = $input->getArgument('step');
$config = $this->getSuiteConfig($suite, $input->getOption('config'));
$class = $this->getClassName($step);
$path = $this->buildPath(Configuration::supportDir() . 'Step' . DIRECTORY_SEPARATOR . ucfirst($suite), $step);
$dialog = $this->getHelperSet()->get('question');
$filename = $path . $class . '.php';
$helper = $this->getHelper('question');
$question = new Question("Add action to StepObject class (ENTER to exit): ");
$gen = new StepObjectGenerator($config, ucfirst($suite) . '\\' . $step);
if (!$input->getOption('silent')) {
do {
$question = new Question('Add action to StepObject class (ENTER to exit): ', null);
$action = $dialog->ask($input, $output, $question);
if ($action) {
$gen->createAction($action);
}
} while ($action);
}
$res = $this->save($filename, $gen->produce());
if (!$res) {
$output->writeln("<error>StepObject {$filename} already exists</error>");
exit;
}
$output->writeln("<info>StepObject was created in {$filename}</info>");
}
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Start checking the database!');
$connFile = $input->getOption('config');
$this->conn = file_exists($connFile) ? require_once $connFile : $this->conn;
if (!$this->conn instanceof Connection) {
throw new \Exception('It\'s not available db connection object.');
}
$checker = new SchemaChecker($this->conn);
$structureFile = $input->getOption('structure');
if (!file_exists($structureFile)) {
throw new \Exception('Structure file not exists!');
}
$sql = $checker->getDiffSql($structureFile);
if (empty($sql)) {
$output->writeln('Nothing has changed.');
} else {
$output->writeln('Began to update the database.');
$output->writeln('//sql--------------------');
foreach ($sql as $s) {
$output->writeln($s . ';');
$this->conn->query($s);
}
$output->writeln('\\\\end sql----------------');
$output->writeln('Database has been updated!');
}
}
示例14: getReferences
/**
* finds a list of packages which depend on another package
*
* @param InputInterface $input
* @param OutputInterface $output
* @param Composer $composer
* @return array
* @throws \InvalidArgumentException
*/
private function getReferences(InputInterface $input, OutputInterface $output, Composer $composer)
{
$needle = $input->getArgument('package');
$references = array();
$verbose = (bool) $input->getOption('verbose');
$repos = $composer->getRepositoryManager()->getRepositories();
$types = $input->getOption('link-type');
foreach ($repos as $repository) {
foreach ($repository->getPackages() as $package) {
foreach ($types as $type) {
$type = rtrim($type, 's');
if (!isset($this->linkTypes[$type])) {
throw new \InvalidArgumentException('Unexpected link type: ' . $type . ', valid types: ' . implode(', ', array_keys($this->linkTypes)));
}
foreach ($package->{'get' . $this->linkTypes[$type]}() as $link) {
if ($link->getTarget() === $needle) {
if ($verbose) {
$references[] = array($type, $package, $link);
} else {
$references[$package->getName()] = $package->getPrettyName();
}
}
}
}
}
}
return $references;
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$i = 0;
$kernel = $this->getContainer()->get('kernel');
$doctrine = $this->getContainer()->get('doctrine');
$entityManager = $doctrine->getEntityManager();
$cron = new Cron();
$cron->setTimestamp(time());
$cron->setAction('Observe Alarms Start');
$entityManager->persist($cron);
$entityManager->flush();
$isSandbox = $input->getOption('sandbox');
$isEmulation = $input->getOption('emulate');
$output->writeln('Sandbox: ' . $isSandbox);
$output->writeln('Emulation: ' . $isEmulation);
// operating under the assumption that this thing is executed by a cronjob, this thing needs to be run for just a minute
$intervalSpent = 0;
while ($intervalSpent <= self::CRON_INTERVAL) {
$detector = new AlarmDetector($doctrine);
$detector->detectAlarms($isEmulation);
$output->writeln(PHP_EOL . ++$i . PHP_EOL);
usleep(self::CHECK_INTERVAL);
// 250ms
$intervalSpent += self::CHECK_INTERVAL;
}
}