當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ConsoleCommandEvent::getCommand方法代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Event\ConsoleCommandEvent::getCommand方法的典型用法代碼示例。如果您正苦於以下問題:PHP ConsoleCommandEvent::getCommand方法的具體用法?PHP ConsoleCommandEvent::getCommand怎麽用?PHP ConsoleCommandEvent::getCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Console\Event\ConsoleCommandEvent的用法示例。


在下文中一共展示了ConsoleCommandEvent::getCommand方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: mergeDefinitions

 private function mergeDefinitions(ConsoleCommandEvent $event)
 {
     $inputDefinition = $event->getCommand()->getApplication()->getDefinition();
     $inputDefinition->addOption(new InputOption('log-memory', null, InputOption::VALUE_NONE, 'Output information about memory usage', null));
     $inputDefinition->addOption(new InputOption('daemonize', null, InputOption::VALUE_NONE, 'Output information about memory usage', null));
     $event->getCommand()->mergeApplicationDefinition();
     return true;
 }
開發者ID:skedone,項目名稱:DaemonsBundle,代碼行數:8,代碼來源:DaemonizeEventListener.php

示例2: setDefaultValues

 /**
  * @param ConsoleCommandEvent $event
  */
 public function setDefaultValues(ConsoleCommandEvent $event)
 {
     /* @var Command $command */
     $command = $event->getCommand();
     $application = $command->getApplication();
     $config = $application->getConfig();
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     $input = $command->getDefinition();
     $options = $input->getOptions();
     foreach ($options as $key => $option) {
         $defaultOption = sprintf('application.default.commands.%s.options.%s', str_replace(':', '.', $command->getName()), $key);
         $defaultValue = $config->get($defaultOption);
         if ($defaultValue) {
             $option->setDefault($defaultValue);
         }
     }
     $arguments = $input->getArguments();
     foreach ($arguments as $key => $argument) {
         $defaultArgument = sprintf('application.default.commands.%s.arguments.%s', str_replace(':', '.', $command->getName()), $key);
         $defaultValue = $config->get($defaultArgument);
         if ($defaultValue) {
             $argument->setDefault($defaultValue);
         }
     }
 }
開發者ID:mnico,項目名稱:DrupalConsole,代碼行數:30,代碼來源:DefaultValueEventListener.php

示例3: listenForServerRunCommand

 public function listenForServerRunCommand(ConsoleCommandEvent $event)
 {
     if (!$event->getCommand() instanceof ServerRunCommand) {
         return;
     }
     $argv = $_SERVER['argv'];
     if (count($argv) < 3) {
         return;
     }
     // strip the application name
     array_shift($argv);
     // strip the command name
     array_shift($argv);
     $address = $argv[0];
     if (0 !== strpos($address, '0.0.0.0')) {
         return;
     }
     $address = str_replace('0.0.0.0', $this->getLocalIp(), $address);
     $output = $event->getOutput();
     $output->writeln(sprintf('If you are in a container you would probably prefer to use: <info>http://%s</info>', $address));
     if (function_exists('uprofiler_enable')) {
         $output->writeln(sprintf('XHProf UI: <info>http://%s/xhprof</info>', $address));
     }
     $output->writeln('');
 }
開發者ID:blackfireio,項目名稱:blackfire-workshop,代碼行數:25,代碼來源:ServerRunListener.php

示例4: onConsoleCommand

 /**
  * @param ConsoleCommandEvent $event
  *
  * @return void
  * @throws CommandAlreadyRunningException
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     // generate pid file name
     $commandName = $event->getCommand()->getName();
     // check for exceptions
     if (in_array($commandName, $this->exceptionsList)) {
         return;
     }
     $clearedCommandName = $this->cleanString($commandName);
     $pidFile = $this->pidFile = $this->pidDirectory . "/{$clearedCommandName}.pid";
     // check if command is already executing
     if (file_exists($pidFile)) {
         $pidOfRunningCommand = file_get_contents($pidFile);
         $elements = explode(":", $pidOfRunningCommand);
         if ($elements[0] == gethostname()) {
             if (posix_getpgid($elements[1]) !== false) {
                 throw (new CommandAlreadyRunningException())->setCommandName($commandName)->setPidNumber($pidOfRunningCommand);
             } else {
                 // pid file exist but the process is not running anymore
                 unlink($pidFile);
             }
         } else {
             throw (new CommandAlreadyRunningException())->setCommandName($commandName)->setPidNumber($pidOfRunningCommand);
         }
     }
     // if is not already executing create pid file
     //file_put_contents($pidFile, getmypid());
     // Añadimos hostname para verificar desde que frontal se estan ejecutando
     $string = gethostname() . ":" . getmypid();
     file_put_contents($pidFile, $string);
     // register shutdown function to remove pid file in case of unexpected exit
     register_shutdown_function(array($this, 'shutDown'), null, $pidFile);
 }
開發者ID:jordigracia,項目名稱:command-lock-bundle,代碼行數:39,代碼來源:CommandLockEventListener.php

示例5: validateDependencies

 /**
  * @param ConsoleCommandEvent $event
  */
 public function validateDependencies(ConsoleCommandEvent $event)
 {
     /**
      * @var \Drupal\AppConsole\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     $application = $command->getApplication();
     $messageHelper = $application->getHelperSet()->get('message');
     /**
      * @var TranslatorHelper
      */
     $translatorHelper = $application->getHelperSet()->get('translator');
     if (!$command instanceof Command) {
         return;
     }
     $dependencies = $command->getDependencies();
     if ($dependencies) {
         foreach ($dependencies as $dependency) {
             if (\Drupal::moduleHandler()->moduleExists($dependency) === false) {
                 $errorMessage = sprintf($translatorHelper->trans('commands.common.errors.module-dependency'), $dependency);
                 $messageHelper->showMessage($output, $errorMessage, 'error');
                 $event->disableCommand();
             }
         }
     }
 }
開發者ID:nateswart,項目名稱:DrupalConsole,代碼行數:30,代碼來源:ValidateDependenciesListener.php

示例6: onConsoleCommand

 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     $input = $event->getInput();
     if (in_array($command->getName(), $this->ignoredCommands)) {
         $this->interactor->ignoreTransaction();
     }
     if ($this->newRelic->getName()) {
         $this->interactor->setApplicationName($this->newRelic->getName(), $this->newRelic->getLicenseKey(), $this->newRelic->getXmit());
     }
     $this->interactor->setTransactionName($command->getName());
     $this->interactor->enableBackgroundJob();
     // send parameters to New Relic
     foreach ($input->getOptions() as $key => $value) {
         $key = '--' . $key;
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 $this->interactor->addCustomParameter($key . '[' . $k . ']', $v);
             }
         } else {
             $this->interactor->addCustomParameter($key, $value);
         }
     }
     foreach ($input->getArguments() as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 $this->interactor->addCustomParameter($key . '[' . $k . ']', $v);
             }
         } else {
             $this->interactor->addCustomParameter($key, $value);
         }
     }
 }
開發者ID:Aerendir,項目名稱:EkinoNewRelicBundle,代碼行數:36,代碼來源:CommandListener.php

示例7: setDefaultValues

 /**
  * @param ConsoleCommandEvent $event
  */
 public function setDefaultValues(ConsoleCommandEvent $event)
 {
     /** @var \Drupal\AppConsole\Command\Command $command */
     $command = $event->getCommand();
     /** @var \Drupal\AppConsole\Console\Application $command */
     $application = $command->getApplication();
     /** @var \Drupal\AppConsole\Config $config */
     $config = $application->getConfig();
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     $input = $command->getDefinition();
     $options = $input->getOptions();
     foreach ($options as $key => $option) {
         $defaultOption = 'commands.' . str_replace(':', '.', $command->getName()) . '.options.' . $key;
         $defaultValue = $config->get($defaultOption);
         if ($defaultValue) {
             $option->setDefault($defaultValue);
         }
     }
     $arguments = $input->getArguments();
     foreach ($arguments as $key => $argument) {
         $defaultArgument = 'commands.' . str_replace(':', '.', $command->getName()) . '.arguments.' . $key;
         $defaultValue = $config->get($defaultArgument);
         if ($defaultValue) {
             $argument->setDefault($defaultValue);
         }
     }
 }
開發者ID:amira2r,項目名稱:DrupalConsole,代碼行數:32,代碼來源:DefaultValueEventListener.php

示例8: showGenerateDoc

 /**
  * @param ConsoleCommandEvent $event
  * @return void
  */
 public function showGenerateDoc(ConsoleCommandEvent $event)
 {
     /**
      * @var \Drupal\Console\Command\Command $command
      */
     $command = $event->getCommand();
     /**
      * @var \Drupal\Console\Console\Application $command
      */
     $application = $command->getApplication();
     /**
      * @var \Drupal\Console\Config $config
      */
     $config = $application->getConfig();
     $input = $command->getDefinition();
     $options = $input->getOptions();
     $arguments = $input->getArguments();
     if (isset($options['generate-doc']) && $options['generate-doc'] == 1) {
         foreach ($this->skipOptions as $remove_option) {
             unset($options[$remove_option]);
         }
         $parameters = ['options' => $options, 'arguments' => $arguments, 'command' => $command->getName(), 'description' => $command->getDescription(), 'aliases' => $command->getAliases()];
         $renderedDoc = $application->getHelperSet()->get('renderer')->render('gitbook/generate-doc.md.twig', $parameters);
         $output = $event->getOutput();
         $output->writeln($renderedDoc);
         $event->disableCommand();
     }
 }
開發者ID:janstoeckler,項目名稱:DrupalConsole,代碼行數:32,代碼來源:ShowGenerateDocListener.php

示例9: registerMigrations

 public function registerMigrations(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$this->isMigrationCommand($command)) {
         return;
     }
     $this->configuration->registerMigrationsFromDirectory($this->configuration->getMigrationsDirectory());
 }
開發者ID:DIPcom,項目名稱:Sandmin,代碼行數:8,代碼來源:RegisterMigrationsEventSubscriber.php

示例10: onConsoleCommand

 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if ($this->registry->isChainedCommand($command)) {
         $event->disableCommand();
         $event->getOutput()->writeln('<error>Chained command should not be executed directly</error>');
     }
 }
開發者ID:sergeyz,項目名稱:cc,代碼行數:11,代碼來源:ChainCommandListener.php

示例11: onCronStart

 /**
  * @param ConsoleCommandEvent $event
  */
 public function onCronStart(ConsoleCommandEvent $event)
 {
     if (!$this->isCronCommand($event->getCommand()->getName(), $event->getInput())) {
         $this->skipped = true;
         return;
     }
     $this->start = microtime(true);
 }
開發者ID:Baby-Markt,項目名稱:CronBundle,代碼行數:11,代碼來源:ExecutionReportListener.php

示例12: setOutputWriter

 public function setOutputWriter(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$this->isMigrationCommand($command)) {
         return;
     }
     $this->outputWriter->setConsoleOutput($event->getOutput());
 }
開發者ID:DIPcom,項目名稱:Sandmin,代碼行數:8,代碼來源:SetConsoleOutputEventSubscriber.php

示例13: onCommandStart

 public function onCommandStart(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!in_array($command->getName(), $this->listenedCommands)) {
         return;
     }
     $commandSlug = preg_replace('/[^a-zA-Z0-9_.]/', '', $command->getName());
     $this->watcher->start($commandSlug);
 }
開發者ID:sowbiba,項目名稱:command-watcher-bundle,代碼行數:9,代碼來源:CommandListener.php

示例14: initializeEventIo

 /**
  * @see getSubscribedEvents
  *
  * @param ConsoleCommandEvent $event
  */
 public function initializeEventIo(ConsoleCommandEvent $event)
 {
     $set = $event->getCommand()->getHelperSet();
     if (!$set->has(self::HELPER_NAME)) {
         return;
     }
     /** @var  $helper IoHelper */
     $helper = $set->get(self::HELPER_NAME);
     $helper->initializeIo($event->getInput(), $event->getOutput());
 }
開發者ID:netz98,項目名稱:n98-magerun,代碼行數:15,代碼來源:IoHelper.php

示例15: decorateDefinition

 public function decorateDefinition(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$command instanceof InitCommand) {
         return;
     }
     $adapterName = $this->application->getConfig()->get('repo_adapter', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ADAPTER);
     $issueTracker = $this->application->getConfig()->get('issue_tracker', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ADAPTER);
     $command->addOption('repo-adapter', null, InputOption::VALUE_OPTIONAL, sprintf('Adapter-name of the repository-manager (%s)', $this->getSupportedAdapters(AdapterFactory::SUPPORT_REPOSITORY_MANAGER)), $adapterName)->addOption('issue-adapter', null, InputOption::VALUE_OPTIONAL, sprintf('Adapter-name of the issue-tracker (%s)', $this->getSupportedAdapters(AdapterFactory::SUPPORT_ISSUE_TRACKER)), $issueTracker)->addOption('org', 'o', InputOption::VALUE_REQUIRED, 'Name of the Git organization', $this->application->getConfig()->get('repo_org', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ORG))->addOption('repo', 'r', InputOption::VALUE_REQUIRED, 'Name of the Git repository', $this->application->getConfig()->get('repo_name', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_REPO))->addOption('issue-org', 'io', InputOption::VALUE_REQUIRED, 'Name of the issue-tracker organization', $this->application->getConfig()->getFirstNotNull(['issue_project_org', 'repo_org'], Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ORG))->addOption('issue-project', 'ip', InputOption::VALUE_REQUIRED, 'Repository/Project name of the issue-tracker', $this->application->getConfig()->getFirstNotNull(['issue_project', 'repo_name'], Config::CONFIG_LOCAL, GitHelper::UNDEFINED_REPO));
 }
開發者ID:gushphp,項目名稱:gush,代碼行數:10,代碼來源:CoreInitSubscriber.php


注:本文中的Symfony\Component\Console\Event\ConsoleCommandEvent::getCommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。