/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); if ($command instanceof HelpCommand) { $command = $this->getCommandFromHelpCommand($command, $event->getInput()); } if (!$command instanceof FormBasedCommand) { return; } $inputDefinition = $this->inputDefinitionFactory->createForFormType($command->formType()); $this->setInputDefinition($command, $event->getInput(), $inputDefinition); }
/** * This function saves the bundle whose routes shall be translated in a global variable to be used in * Zikula\RoutesModule\Translation\DefaultRouteExclusionStrategy later on. * * @param ConsoleCommandEvent $event */ public function checkBundleForTranslatingRoutes(ConsoleCommandEvent $event) { if ($event->getCommand()->getName() !== 'translation:extract') { return; } $GLOBALS['translation_extract_routes'] = true; if ($event->getInput()->hasParameterOption('--bundle')) { $bundle = $event->getInput()->getParameterOption('--bundle'); if ('@' === $bundle[0]) { $bundle = substr($bundle, 1); } $GLOBALS['translation_extract_routes_bundle'] = $bundle; } }
/** * Before a Console command runs, examine the global * commandline options from the event Input, and set * configuration values as appropriate. * * @param ConsoleCommandEvent $event */ public function setGlobalOptions(ConsoleCommandEvent $event) { /* @var Input $input */ $input = $event->getInput(); // TODO: We need a good strategy for managing global options. // $simulate = $input->getOption('simulate'); }
/** * @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); } } }
/** * @param ConsoleCommandEvent $event */ public function onCronStart(ConsoleCommandEvent $event) { if (!$this->isCronCommand($event->getCommand()->getName(), $event->getInput())) { $this->skipped = true; return; } $this->start = microtime(true); }
public function onConsoleCommand(ConsoleCommandEvent $event) { $this->siteAccess->name = $event->getInput()->getParameterOption('--siteaccess', $this->defaultSiteAccessName); $this->siteAccess->matchingType = 'cli'; if (!in_array($this->siteAccess->name, $this->siteAccessList)) { throw new InvalidSiteAccessException($this->siteAccess->name, $this->siteAccessList, $this->siteAccess->matchingType); } $this->eventDispatcher->dispatch(MVCEvents::CONFIG_SCOPE_CHANGE, new ScopeChangeEvent($this->siteAccess)); }
/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $input = $event->getInput(); $this->addOptionsToCommand($command, $input); $listeners = $this->getListenersToDisable($input); if (!empty($listeners)) { $this->listenersManager->disableListeners($listeners); } }
/** * @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()); }
/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); if (!$command instanceof FormBasedCommand) { return; } $input = $event->getInput(); $output = $event->getOutput(); $formData = $this->formQuestionHelper->interactUsingForm($command->formType(), $input, $output); $command->setFormData($formData); }
public function initialize(ConsoleCommandEvent $event) { $command = $event->getCommand(); if (!$command instanceof TableFeature) { return; } $input = $event->getInput(); $layout = $input->getOption('table-layout'); if ($layout && !in_array($layout, $this->validLayouts, true)) { throw new \InvalidArgumentException(sprintf('The table-layout option must be passed one of "%s" but was given "%s"', implode(', ', $this->validLayouts), $layout)); } }
/** * @param ConsoleCommandEvent $event */ public function alterCommandOptions(ConsoleCommandEvent $event) { /* @var Command $command */ $command = $event->getCommand(); $input = $event->getInput(); if ($command->getName() == 'help') { // Symfony 3.x prepares $input for us; Symfony 2.x, on the other // hand, passes it in prior to binding with the command definition, // so we have to go to a little extra work. It may be inadvisable // to do these steps for commands other than 'help'. if (!$input->hasArgument('command_name')) { $command->ignoreValidationErrors(); $command->mergeApplicationDefinition(); $input->bind($command->getDefinition()); } $nameOfCommandToDescribe = $event->getInput()->getArgument('command_name'); $commandToDescribe = $this->application->find($nameOfCommandToDescribe); $this->findAndAddHookOptions($commandToDescribe); } else { $this->findAndAddHookOptions($command); } }
/** * Before a Console command runs, examine the global * commandline options from the event Input, and set * configuration values as appropriate. * * @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event */ public function setGlobalOptions(ConsoleCommandEvent $event) { $config = $this->getConfig(); $input = $event->getInput(); $globalOptions = $config->getGlobalOptionDefaultValues(); foreach ($globalOptions as $option => $default) { $value = $input->hasOption($option) ? $input->getOption($option) : null; // Unfortunately, the `?:` operator does not differentate between `0` and `null` if (!isset($value)) { $value = $default; } $config->set($option, $value); } }
public function initialize(ConsoleCommandEvent $event) { $command = $event->getCommand(); if ($command instanceof TemplateFeature) { $input = $event->getInput(); $template = $input->getOption('template'); if ($template) { $validTemplates = $this->templateHelper->getNamesForDomain($command->getTemplateDomain()); if (!in_array($template, $validTemplates, true)) { throw new \InvalidArgumentException(sprintf('The specified template "%s" does not exist, try one of: ' . PHP_EOL . ' - %s', $template, implode(PHP_EOL . ' - ', $validTemplates))); } } } }
/** * @param ConsoleCommandEvent $event */ public function showMessage(ConsoleCommandEvent $event) { /** * @var \Drupal\Console\Command\Command $command */ $command = $event->getCommand(); $input = $event->getInput(); $output = $event->getOutput(); $output = new DrupalStyle($input, $output); $application = $command->getApplication(); $translatorHelper = $application->getTranslator(); $welcomeMessageKey = 'commands.' . str_replace(':', '.', $command->getName()) . '.welcome'; $welcomeMessage = $translatorHelper->trans($welcomeMessageKey); if ($welcomeMessage != $welcomeMessageKey) { $output->text($welcomeMessage); } }
public function onCommand(ConsoleCommandEvent $event) { /** @var PathHelper $path */ $path = $event->getCommand()->getHelper('path'); $this->old_working_dir = getcwd(); $working_dir = $event->getInput()->getOption('project-path'); $real_working_dir = realpath($working_dir); if (!$real_working_dir) { $event->getOutput()->writeln(sprintf('The specified project-path "%s" does not exist.', $working_dir)); $event->stopPropagation(); $event->disableCommand(); return; } $path->setProjectPath($working_dir); $event->getOutput()->writeln(sprintf("Changing directory to %s", $working_dir)); chdir($real_working_dir); }
public function onConsoleCommand(ConsoleCommandEvent $event) { $input = $event->getInput(); $inputDefinition = $event->getCommand()->getApplication()->getDefinition(); $inputDefinition->addOption(new InputOption('working-dir', null, InputOption::VALUE_REQUIRED, 'The root directory of the project', null)); $inputDefinition->addOption(new InputOption('config-file', null, InputOption::VALUE_REQUIRED, 'The filepath of the configuration file', null)); $event->getCommand()->mergeApplicationDefinition(); $input->bind($event->getCommand()->getDefinition()); // Ignore commands which are not from the project (like the "help command") if (!$event->getCommand() instanceof AbstractCommand) { return; } if (null !== ($workingDir = $input->getOption('working-dir'))) { $this->configurationLoader->setRootDirectory($workingDir); } if (null !== ($configPath = $input->getOption('config-file'))) { $this->configurationLoader->setConfigurationFilepath($configPath); } }
/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $isForced = $event->getInput()->hasParameterOption('--force'); if ($isForced) { $this->isInstalled = false; return; } if ($this->isInstalled) { try { $locale = $this->localeSettings->getLocale(); $language = $this->localeSettings->getLanguage(); } catch (DBALException $exception) { // application is not installed return; } $this->setPhpDefaultLocale($locale); $this->translatableListener->setTranslatableLocale($language); } }
/** * Add option before run command and create PID file * * @param ConsoleCommandEvent $event */ public function onCommand(ConsoleCommandEvent $event) { if (!$this->isPIDRequired($command = $event->getCommand())) { return; } $application = $command->getApplication(); $inputDefinition = $application->getDefinition(); $inputDefinition->addOption(new InputOption(static::PID_OPTION, null, InputOption::VALUE_REQUIRED, 'The location of the PID file that should be created for this process', $this->pidFile)); foreach ($application->getDefinition()->getOptions() as $option) { if (!$command->getDefinition()->hasOption($option->getName())) { $command->getDefinition()->addOption($option); } } $input = $event->getInput(); $input->bind($command->getDefinition()); $pidFile = $input->getOption(static::PID_OPTION); if ($pidFile !== null) { file_put_contents($pidFile, getmypid()); } }
/** * Disabling runs members of chains and launching chains of commands. * * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $commandName = $command->getName(); $application = $command->getApplication(); if (!$this->manager->isInitialized()) { $this->manager->init($application); } if ($this->manager->isMember($commandName)) { $event->disableCommand(); $event->stopPropagation(); $mainCommands = $this->manager->getMainCommands($commandName); $event->getOutput()->writeln(sprintf('<error>Error: "%s" command is a member of %s command%s chain and cannot be executed on its own.</error>', $commandName, implode(', ', array_map(function ($name) { return '"' . $name . '"'; }, $mainCommands)), count($mainCommands) > 1 ? 's' : '')); } if ($this->manager->hasChains($commandName)) { $this->manager->runChain($command, $event->getInput()); $event->disableCommand(); $event->stopPropagation(); } }
/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $input = $event->getInput(); $definition = $command->getApplication()->getDefinition(); $definition->addOption(new InputOption(self::OPTION_USER, null, InputOption::VALUE_REQUIRED, 'ID, username or email of the user that should be used as current user')); $definition->addOption(new InputOption(self::OPTION_ORGANIZATION, null, InputOption::VALUE_REQUIRED, 'ID or name of the organization that should be used as current organization')); $user = $input->getParameterOption('--' . self::OPTION_USER); $organization = $input->getParameterOption('--' . self::OPTION_ORGANIZATION); if (!$user && !$organization) { return; } $token = $this->securityContext->getToken(); if (!$token) { $token = new ConsoleToken(); $this->securityContext->setToken($token); } $this->setUser($user, $token); if ($token instanceof OrganizationContextTokenInterface) { $this->setOrganization($organization, $token); } }
public function onCommand(ConsoleCommandEvent $event) { $composer_json_path = 'composer.json'; if (file_exists($composer_json_path)) { return; } /** @var QuestionHelper $questionHelper */ $questionHelper = $event->getCommand()->getHelper('question'); $question = new ConfirmationQuestion('Composer has not been initialized, initialize composer now? [yes]: ', true); if (!$questionHelper->ask($event->getInput(), $event->getOutput(), $question)) { $event->getOutput()->writeln('Skipping composer init, if the command fails then you should try initializing composer.'); return; } /** @var InitHelper $initHelper */ $initHelper = $event->getCommand()->getHelper('composer init'); if ($initHelper->initComposer($event->getOutput())) { $event->getOutput()->writeln("Composer initialization failed."); $event->getOutput()->writeln("Please initialize a composer package manually before trying again."); $event->disableCommand(); $event->stopPropagation(); } }
/** * @param ConsoleCommandEvent $event * @param string $org * @param string $repo * @param string $adapterName */ private function initializeIssueTracker(ConsoleCommandEvent $event, $org, $repo, $adapterName) { $input = $event->getInput(); $issueOrg = GitHelper::undefinedToDefault($input->getOption('issue-org'), $org); $issueRepo = GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo); $issueAdapterName = $input->getOption('issue-adapter') ?: $adapterName; $input->setOption('issue-org', $issueOrg); $input->setOption('issue-project', $issueRepo); $input->setOption('issue-adapter', $issueAdapterName); $config = $this->application->getConfig()->get(['adapters', $issueAdapterName], Config::CONFIG_SYSTEM); /** @var \Gush\Adapter\BaseIssueTracker $issueTracker */ $issueTracker = $this->application->getAdapterFactory()->createIssueTracker($issueAdapterName, $config, $this->application->getConfig()); $issueTracker->authenticate(); $issueTracker->setRepository($issueRepo)->setUsername($issueOrg); $this->application->setIssueTracker($issueTracker); }
/** * @hook command-event test:hello */ public function commandEventTestHello(ConsoleCommandEvent $event) { // Note that Symfony Console will not allow us to alter the // input from this hook, so we'll just print something to // show that this hook was executed. $input = $event->getInput(); $who = $input->getArgument('who'); $this->output->writeln("Here comes {$who}!"); }
public function onConsoleCommand(ConsoleCommandEvent $event) { $this->input = $event->getInput(); $this->output = $event->getOutput(); }
/** * Before a Console command runs, examine the global * commandline options from the event Input, and set * configuration values as appropriate. * * @param ConsoleCommandEvent $event */ public function setGlobalOptions(ConsoleCommandEvent $event) { $this->getConfig()->setGlobalOptions($event->getInput()); }
/** * @see getSubscribedEvents * * @param ConsoleCommandEvent $event */ public function initializeEventIo(ConsoleCommandEvent $event) { /** @var $helper IoHelper */ $helper = $event->getCommand()->getHelperSet()->get($this->getName()); $helper->initializeIo($event->getInput(), $event->getOutput()); }
/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $this->request = null; $this->command = $event->getCommand(); $this->commandInput = $event->getInput(); if ($this->reportErrors || $this->reportWarnings) { self::_reserveMemory(); $this->setErrorHandlers(); } }
/** * @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event * * @return void */ public function onConsoleCommand(ConsoleCommandEvent $event) { $context = ['arguments' => $event->getInput()->getArguments(), 'options' => $event->getInput()->getOptions()]; $this->getLogger()->info(sprintf('CLI command "%s" started', $event->getCommand()->getName()), $context); }