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(''); }
/** * @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(); } }
/** * @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(); } } } }
public function setOutputWriter(ConsoleCommandEvent $event) { $command = $event->getCommand(); if (!$this->isMigrationCommand($command)) { return; } $this->outputWriter->setConsoleOutput($event->getOutput()); }
/** * @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>'); } }
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); }
/** * @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); }
/** * On Command Event Handler * * Check if the current command requires EE bootstrapping * and throw an exception if EE is not bootstrapped * * @param ConsoleCommandEvent $event * @return void */ public function onCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $output = $event->getOutput(); if (!$this->isCommandExemptFromBootstrap($command)) { if (!$this->canBeBootstrapped()) { throw new \Exception('Your craft path could not be found.'); } $this->bootstrap(); } }
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 */ public function showWelcomeMessage(ConsoleCommandEvent $event) { /* @var Command $command */ $command = $event->getCommand(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $application = $command->getApplication(); $translatorHelper = $application->getTranslator(); $welcomeMessageKey = 'commands.' . str_replace(':', '.', $command->getName()) . '.welcome'; $welcomeMessage = $translatorHelper->trans($welcomeMessageKey); if ($welcomeMessage != $welcomeMessageKey) { $io->text($welcomeMessage); } }
/** * @param ConsoleCommandEvent $event */ public function showMessage(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'); $welcomeMessageKey = 'commands.' . str_replace(':', '.', $command->getName()) . '.welcome'; $welcomeMessage = $translatorHelper->trans($welcomeMessageKey); if ($welcomeMessage != $welcomeMessageKey) { $messageHelper->showMessage($output, $welcomeMessage); } }
/** * @param ConsoleCommandEvent $event */ public function showTips(ConsoleCommandEvent $event) { /* @var Command $command */ $command = $event->getCommand(); $input = $command->getDefinition(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $application = $command->getApplication(); $translatorHelper = $application->getTranslator(); $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; // pick randomly one of the tips (5 tips as maximum). $tips = $this->get_tip($translatorHelper, $command); if ($learning && $tips) { $io->commentBlock($tips); } }
public function onCommand(ConsoleCommandEvent $event) { $output = $event->getOutput(); $input = new ArgvInput(); try { $input->bind($this->getDefinition()); } catch (\RuntimeException $e) { } $delay = filter_var($input->getOption('delay'), FILTER_VALIDATE_INT); if ($delay > 0) { $wakeupAt = time() + mt_rand(1, $delay); $output->writeln('<comment>Waiting until ' . date('Y-m-d H:i:s', $wakeupAt) . ' eRepublik time.</comment>'); time_sleep_until($wakeupAt); } $this->configPath = $input->getOption('config'); $this->loadConfig(); }
/** * @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); } }
/** * @param ConsoleCommandEvent $event * @return void */ public function showGenerateDoc(ConsoleCommandEvent $event) { /* @var \Drupal\Console\Command\Command $command */ $command = $event->getCommand(); $application = $command->getApplication(); $input = $command->getDefinition(); $options = $input->getOptions(); $arguments = $input->getArguments(); if (isset($options['generate-doc'])) { foreach ($this->skipOptions as $remove_option) { unset($options[$remove_option]); } $parameters = ['options' => $options, 'arguments' => $arguments, 'command' => $command->getName(), 'aliases' => $command->getAliases(), 'examples' => [], 'messages' => ['command_description' => sprintf($application->trans('commands.generate.doc.command.command_description'), $command->getName(), $command->getDescription()), 'usage' => $application->trans('commands.generate.doc.command.usage'), 'options' => $application->trans('commands.generate.doc.command.options'), 'option' => $application->trans('commands.generate.doc.command.options'), 'details' => $application->trans('commands.generate.doc.command.details'), 'arguments' => $application->trans('commands.generate.doc.command.arguments'), 'argument' => $application->trans('commands.generate.doc.command.argument')]]; $renderedDoc = $application->getRenderHelper()->render('gitbook/generate-doc.md.twig', $parameters); $output = $event->getOutput(); $output->writeln($renderedDoc); $event->disableCommand(); } }
/** * @param ConsoleCommandEvent $event */ public function validateExecution(ConsoleCommandEvent $event) { /* @var Command $command */ $command = $event->getCommand(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $application = $command->getApplication(); $configuration = $application->getConfig(); $translator = $application->getTranslator(); $mapping = $configuration->get('application.disable.commands') ?: []; if (array_key_exists($command->getName(), $mapping)) { $extra = $mapping[$command->getName()]; $message[] = sprintf($translator->trans('application.messages.disable.command.error'), $command->getName()); if ($extra) { $message[] = sprintf($translator->trans('application.messages.disable.command.extra'), $extra); } $io->commentBlock($message); } }
/** * @param ConsoleCommandEvent $event */ public function validateDependencies(ConsoleCommandEvent $event) { /* @var Command $command */ $command = $event->getCommand(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $application = $command->getApplication(); $translatorHelper = $application->getTranslator(); if (!$command instanceof Command) { return; } if ($dependencies = $command->getDependencies()) { foreach ($dependencies as $dependency) { if (!$application->getValidator()->isModuleInstalled($dependency)) { $errorMessage = sprintf($translatorHelper->trans('commands.common.errors.module-dependency'), $dependency); $io->error($errorMessage); $event->disableCommand(); } } } }
/** * @param ConsoleCommandEvent $event */ public function showWelcomeMessage(ConsoleCommandEvent $event) { /* @var Command $command */ $command = $event->getCommand(); $input = $command->getDefinition(); if ($input->hasOption('generate-doc')) { return; } if ($input->hasOption('no-interaction')) { return; } /* @var DrupalStyle $io */ $io = $event->getOutput(); $application = $command->getApplication(); $translatorHelper = $application->getTranslator(); $welcomeMessageKey = 'commands.' . str_replace(':', '.', $command->getName()) . '.welcome'; $welcomeMessage = $translatorHelper->trans($welcomeMessageKey); if ($welcomeMessage != $welcomeMessageKey) { $io->text($welcomeMessage); } }
/** * 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(); } }
public function handleCommand(ConsoleCommandEvent $event) { $this->outputWriter->setOutputInterface($event->getOutput()); }
/** * Before a command is executed, the handler gets activated and the console output * is set in order to know where to write the logs. * * @param ConsoleCommandEvent $event */ public function onCommand(ConsoleCommandEvent $event) { $output = $event->getOutput(); if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); } $this->setOutput($output); }
public function onConsoleCommand(ConsoleCommandEvent $event) { $this->input = $event->getInput(); $this->output = $event->getOutput(); }
/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $outputFormatter = $event->getOutput()->getFormatter(); $this->styles->applyTo($outputFormatter); }
/** * Adds a message to the console output. * * @param ConsoleCommandEvent $event The event arguments. */ public static function onCommandEvent(ConsoleCommandEvent $event) { $event->getOutput()->writeln('Event listened.'); }
/** * @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()); }
/** * On Command Event Handler * * Check if the current command requires EE bootstrapping * and throw an exception if EE is not bootstrapped * * @param ConsoleCommandEvent $event * @return void */ public function onCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $output = $event->getOutput(); if (!$this->isCommandExemptFromBootstrap($command)) { if (!$this->canBeBootstrapped()) { throw new \Exception('Your system path could not be found.'); } // override EE classes to print errors/messages to console ee()->output = new CodeIgniterConsoleOutput($output); ee()->functions = new Functions($output); } }
/** * On Command Event Handler * * Check if the current command requires EE bootstrapping * and throw an exception if EE is not bootstrapped * * @param ConsoleCommandEvent $event * @return void */ public function onCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $output = $event->getOutput(); if (!$this->isCommandExemptFromBootstrap($command)) { if (!$this->canBeBootstrapped()) { throw new \Exception('Your system path could not be found.'); } // override EE classes to print errors/messages to console ee()->output = new CodeIgniterConsoleOutput($output, $this); ee()->functions = new Functions($output, $this); } if ($this->doesCommandHaveRuntimeOptions($command)) { // we use this to allow the command to access cli arguments // during the getRuntimeOptions call $input = new GlobalArgvInput($event->getCommand()->getDefinition()); foreach ($command->getRuntimeOptions($this, $input) as $option) { $this->getDefinition()->addOption($option); } } }
/** * Before a command is executed, the handler gets activated and the console output * is set in order to know where to write the logs. * * @param ConsoleCommandEvent $event */ public function onCommand(ConsoleCommandEvent $event) { $this->setOutput($event->getOutput()); }
/** * On Command Event Handler * * Check if the current command requires EE bootstrapping * and throw an exception if EE is not bootstrapped * * @param ConsoleCommandEvent $event * @return void */ public function onCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $command->setApplication($this); $output = $event->getOutput(); if (!$this->isCommandExemptFromBootstrap($command)) { if (!$this->canBeBootstrapped()) { throw new \Exception('Your craft path could not be found.'); } $craft = $this->bootstrap(); if ($command instanceof NeedsCraftInterface) { $command->setCraft($craft); $command->setEnvironment(CRAFT_ENVIRONMENT); $command->setAppPath(CRAFT_APP_PATH); $command->setBasePath(CRAFT_BASE_PATH); $command->setConfigPath(CRAFT_CONFIG_PATH); $command->setPluginsPath(CRAFT_PLUGINS_PATH); $command->setStoragePath(CRAFT_STORAGE_PATH); $command->setTemplatesPath(CRAFT_TEMPLATES_PATH); $command->setTranslationsPath(CRAFT_TRANSLATIONS_PATH); } } }