initialize() protected method

This is mainly useful when a lot of commands extends one main command where some things need to be initialized based on the input arguments and options.
protected initialize ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface An InputInterface instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
Beispiel #1
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->io = new SymfonyStyle($input, $output);
     $debug = $output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG;
     $this->cff = new CffClient($debug);
 }
Beispiel #2
0
 /**
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @throws \InvalidArgumentException When the number of messages to consume is less than 0
  * @throws \BadFunctionCallException When the pcntl is not installed and option -s is true
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if (defined('AMQP_WITHOUT_SIGNALS') === false) {
         define('AMQP_WITHOUT_SIGNALS', $input->getOption('without-signals'));
     }
     if (!AMQP_WITHOUT_SIGNALS && extension_loaded('pcntl')) {
         if (!function_exists('pcntl_signal')) {
             throw new \BadFunctionCallException("Function 'pcntl_signal' is referenced in the php.ini 'disable_functions' and can't be called.");
         }
         pcntl_signal(SIGTERM, [$this, 'signalTerm']);
         pcntl_signal(SIGINT, [$this, 'signalInt']);
         pcntl_signal(SIGHUP, [$this, 'signalHup']);
     }
     if (defined('AMQP_DEBUG') === false) {
         define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     }
     if (($this->amount = $input->getOption('messages')) < 0) {
         throw new \InvalidArgumentException("The -m option should be null or greater than 0");
     }
     $this->consumer = $this->connection->getConsumer($input->getArgument('name'));
     if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) {
         $this->consumer->setMemoryLimit($input->getOption('memory-limit'));
     }
     if ($routingKey = $input->getOption('route')) {
         $this->consumer->setRoutingKey($routingKey);
     }
 }
Beispiel #3
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     if (true === $input->hasParameterOption(array('--no-ansi')) && $input->hasOption('no-progress')) {
         $input->setOption('no-progress', true);
     }
     parent::initialize($input, $output);
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->schema->onIndexDropped[] = function ($sm, $index) use($output) {
         $output->writeln(sprintf('<error>Dropped</error> index <info>%s</info>', $index));
     };
     $this->schema->onTypeDropped[] = function ($sm, ClassMetadata $type) use($output) {
         $output->writeln(sprintf('<error>Dropped</error> type <info>%s</info>', $type->getName()));
     };
     $this->schema->onIndexCreated[] = function ($sm, $index) use($output) {
         $output->writeln(sprintf('Created index <info>%s</info>', $index));
     };
     $this->schema->onTypeCreated[] = function ($sm, ClassMetadata $type) use($output) {
         $output->writeln(sprintf('Created type <info>%s</info>', $type->getName()));
     };
     $this->schema->onAliasCreated[] = function ($sm, $original, $alias) use($output) {
         $output->writeln(sprintf('Created alias <info>%s</info> for index <info>%s</info>', $alias, $original));
     };
     $this->schema->onAliasError[] = function ($sm, ResponseException $e, $original, $alias) use($output) {
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     };
     /** @var \Doctrine\Search\ElasticSearch\Client $searchClient */
     $searchClient = $this->searchManager->getClient();
     /** @var Kdyby\ElasticSearch\Client $apiClient */
     $apiClient = $searchClient->getClient();
     $apiClient->onError = [];
     $apiClient->onSuccess = [];
 }
 /**
  * {@inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     // Don't use IO from container, because it contains outer IO which doesn't reflect sub-command calls.
     $this->io = new ConsoleIO($input, $output, $this->getHelperSet());
     $this->prepareDependencies();
 }
Beispiel #6
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->in = $input;
     $this->out = $output;
     $this->io = new SymfonyStyle($this->in, $this->out);
 }
 /**
  * {@inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $factory = new HexFactory();
     $hex = $input->getArgument(self::HEX_ARGUMENT);
     $input->setArgument(self::HEX_ARGUMENT, $factory->make($hex));
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->profileManager = new Manager(null, $output);
     $config = new Config();
     $this->dependencyTracker = new DependencyTracker();
     $this->blueprintFactory = new BlueprintFactory($config, new \StackFormation\ValueResolver\ValueResolver($this->dependencyTracker, $this->profileManager, $config));
 }
 /**
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @throws \InvalidArgumentException When the number of messages to consume is less than 0
  * @throws \BadFunctionCallException When the pcntl is not installed and option -s is true
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if (defined('AMQP_WITHOUT_SIGNALS') === false) {
         define('AMQP_WITHOUT_SIGNALS', $input->getOption('without-signals'));
     }
     if (defined('AMQP_DEBUG') === false) {
         define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     }
     if (($this->amount = $input->getOption('messages')) < 0) {
         throw new \InvalidArgumentException("The -m option should be null or greater than 0");
     }
     $name = $input->getArgument('name');
     try {
         $this->consumer = $this->connection->getConsumer($name);
     } catch (InvalidArgumentException $e) {
         $names = implode(', ', $this->connection->getDefinedConsumers());
         throw new InvalidArgumentException("Unknown consumer {$name}, expecting one of [{$names}]\nIf you added or renamed a consumer, run 'rabbitmq:setup-fabric'");
     }
     if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) {
         $this->consumer->setMemoryLimit($input->getOption('memory-limit'));
     }
     if ($routingKey = $input->getOption('route')) {
         $this->consumer->setRoutingKey($routingKey);
     }
     if (!AMQP_WITHOUT_SIGNALS && extension_loaded('pcntl')) {
         if (!function_exists('pcntl_signal')) {
             throw new \BadFunctionCallException("Function 'pcntl_signal' is referenced in the php.ini 'disable_functions' and can't be called.");
         }
         $this->consumer->onConsume[] = function () {
             pcntl_signal(SIGTERM, function () {
                 if ($this->consumer) {
                     pcntl_signal(SIGTERM, SIG_DFL);
                     $this->consumer->forceStopConsumer();
                 }
             });
             pcntl_signal(SIGINT, function () {
                 if ($this->consumer) {
                     pcntl_signal(SIGINT, SIG_DFL);
                     $this->consumer->forceStopConsumer();
                 }
             });
             pcntl_signal(SIGHUP, function () {
                 if ($this->consumer) {
                     pcntl_signal(SIGHUP, SIG_DFL);
                     $this->consumer->forceStopConsumer();
                 }
                 // TODO: Implement restarting of consumer
             });
         };
         $this->consumer->onConsumeStop[] = function () {
             pcntl_signal(SIGTERM, SIG_DFL);
             pcntl_signal(SIGINT, SIG_DFL);
             pcntl_signal(SIGHUP, SIG_DFL);
         };
     }
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     /** @var \Doctrine\Search\ElasticSearch\Client $searchClient */
     $searchClient = $this->searchManager->getClient();
     /** @var Kdyby\ElasticSearch\Client $apiClient */
     $apiClient = $searchClient->getClient();
     $apiClient->onError = [];
     $apiClient->onSuccess = [];
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $configPath = $input->getOption('config');
     $this->config = $configPath ? Configuration::fromFile($configPath) : Configuration::defaults('php-semver-checker');
     $inputMerger = new InputMerger();
     $inputMerger->merge($input, $this->config);
     // Set overrides
     LevelMapping::setOverrides($this->config->getLevelMapping());
 }
Beispiel #12
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     /** @var OutputFormatterStyleInterface $warningStyle */
     $warningStyle = $this->pimple['console.style.warning'];
     $output->getFormatter()->setStyle('warning', $warningStyle);
     /** @var OutputFormatterStyleInterface $warningStyle */
     $warningStyle = $this->pimple['console.style.success'];
     $output->getFormatter()->setStyle('success', $warningStyle);
 }
Beispiel #13
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->input = $input;
     $this->output = $output;
     // use Console\Dumper for nice debug output
     $this->dumper = new Dumper($this->output);
     // skip if maintenance mode is on and the flag is not set
     if (Admin::isInMaintenanceMode() && !$input->getOption('ignore-maintenance-mode')) {
         throw new \RuntimeException('In maintenance mode - set the flag --ignore-maintenance-mode to force execution!');
     }
 }
Beispiel #14
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->input = $input;
     $this->output = $output;
     $adapter = new Adapter(self::ROOT_DIR);
     $this->fs = new Filesystem($adapter);
     $this->projectName = trim($input->getArgument('projectName'));
     $this->packages = $input->getOption('with');
     $this->projectDir = self::ROOT_DIR . DIRECTORY_SEPARATOR . $this->projectName;
     //$this->setOption($this->option);
     //$this->setPackageOptions($this->packages);
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     if ($host[0] == '/') {
         $host = 'unix:///' . ltrim($host, '/');
         $port = null;
     } elseif (substr($host, 0, 7) != 'unix://') {
         list($host, $port) = array_pad(explode(':', $host, 2), 2, 9000);
     } else {
         $port = null;
     }
     $this->connector = $this->createConnectorInstance($host, $port);
     parent::initialize($input, $output);
 }
Beispiel #16
0
 /**
  * @inheritdoc
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     parent::initialize($input, $output);
     if ($input !== null and $input->getOption('run-from-cron')) {
         $message = '[run-from-cron] [' . (new \DateTime())->format('Y-m-d H:i:s') . ']';
         if ($input instanceof ArgvInput or $input instanceof ArrayInput) {
             $message = $message . ' ' . $input;
         } else {
             $message = $message . ' ' . $this->getName();
         }
         $output->writeln($message);
     }
 }
Beispiel #17
0
 /**
  * Adding custom styles and helper functions here
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->inputInterface = $input;
     $this->outputInterface = $output;
     $isQuietMode = (bool) $input->getOption("quiet");
     $inputVerbosity = (int) $input->getOption("verbose");
     if ($isQuietMode) {
         $verbosityLevel = self::VERBOSITY_LEVEL_QUIET;
     } else {
         $verbosityLevel = $inputVerbosity > $output->getVerbosity() ? $inputVerbosity : $output->getVerbosity();
     }
     $this->verbosityLevel = $verbosityLevel;
     $this->initializeCustomStyles();
     parent::initialize($input, $output);
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $partnerName = $input->getArgument(self::PARTNER_NAME);
     $yourPreviousResponse = $input->getArgument(self::YOUR_PREVIOUS_RESPONSE);
     $partnerPreviousResponse = $input->getArgument(self::PARTNER_PREVIOUS_RESPONSE);
     if ($partnerPreviousResponse && !in_array($partnerPreviousResponse, $this->validResponses)) {
         throw new InvalidPreviousResponseException($partnerName, $partnerPreviousResponse);
     }
     if ($yourPreviousResponse && !in_array($yourPreviousResponse, $this->validResponses)) {
         throw new InvalidPreviousResponseException(self::YOUR_NAME, $yourPreviousResponse);
     }
     if ($partnerPreviousResponse && !$yourPreviousResponse) {
         throw new \InvalidArgumentException(sprintf('Missing argument "%s"', self::YOUR_PREVIOUS_RESPONSE));
     }
 }
 /**
  * Initialize command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if ($input->hasOption('no-llum')) {
         $this->noLlum = $input->getOption('no-llum');
     }
     if ($input->hasOption('dev')) {
         $this->installDev = $input->getOption('dev');
     }
     if ($input->hasOption('use-vendor-publish')) {
         $this->useVendorPublish = $input->getOption('use-vendor-publish');
     }
     if ($input->hasOption('dontforce')) {
         $this->askBeforeOverwrite = $input->getOption('dontforce');
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     // see http://qiita.com/ngyuki/items/d8db4ab6a954c59ed79d
     if ($output->getVerbosity() == $output::VERBOSITY_NORMAL && $input->getOption('verbose')) {
         $output->setVerbosity($output::VERBOSITY_VERBOSE);
     }
     $configPath = $input->getOption('config');
     $dryRun = $input->getOption('dry-run');
     $loader = new ConfigLoader();
     $fn = $loader->resolve($configPath);
     $config = $loader->load($fn);
     $config->dryRun = $dryRun;
     $logger = new Logger($output);
     $this->manager = new Manager($config, $logger);
 }
Beispiel #21
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     // logger
     $logger = $this->getApplication()->getLogger();
     if (!isset($logger)) {
         $verbosityLevelMap = [LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE, LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG];
         $logger = new ConsoleLogger($output, $verbosityLevelMap);
         $this->getApplication()->setLogger($logger);
     }
     // config
     $config = $this->getApplication()->getConfig();
     if (!isset($config)) {
         $config = new Config($input->getOption('config'));
         try {
             $config->loadConfigFile();
         } catch (\RuntimeException $e) {
             $logger->critical($e->getMessage());
             $this->setCode(function () {
                 return 1;
             });
             return;
         }
         $this->getApplication()->setConfig($config);
     }
     // compatibility: first client available at old config names
     // this overrides config values to options from command line arguments
     $firstTransmission = $config->get('transmission')[0];
     $vars = ['host', 'port', 'user', 'password'];
     foreach ($vars as $var) {
         $configName = 'transmission-' . $var;
         $config->set($configName, $this->getInputOption($input, $configName, $firstTransmission[$var]));
     }
     // client
     $client = $this->getApplication()->getClient();
     if (!isset($client)) {
         $client = $this->createTransmissionClient($config->get('transmission-host'), $config->get('transmission-port'), $config->get('transmission-user'), $config->get('transmission-password'));
         $this->getApplication()->setClient($client);
     }
     $logger->info('[{date}] command: {args}', ['date' => date('Y-m-d H:i:s'), 'args' => implode(' ', array_slice($_SERVER['argv'], 1))]);
     parent::initialize($input, $output);
 }
Beispiel #22
0
 /**
  * {inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->initLogger($input, $output);
     $this->initGit($input);
     $this->initShell($input);
     $this->initClient();
     if ($this->needGitRepository() && !$this->git->isInGitRepo()) {
         $this->getLogger()->error('This command must be executed in a git repository. Try the command "twgit init" to start a git repository');
         $this->getApplication()->showUsage($this->logger);
         exit(1);
     }
     // Need to be in a git repository to initialize configuration
     $this->initConfig();
     if ($this->needTwgitRepository() && !$this->isTwgitInitialized()) {
         $this->getLogger()->error('Twgit is not initialzed. Please use "twgit init" command.');
         $this->getApplication()->showUsage($this->logger);
         exit(1);
     }
     // Twgit need to be configured before importing configuration files
     $this->importConfig();
 }
Beispiel #23
0
 /**
  * Handles the default options all commands have in common.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @throws \InvalidArgumentException in case of configuration errors
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->input = $input;
     $this->output = $output;
     // prepend include_path if demanded
     $path = $input->getOption('include-path');
     if (!empty($path)) {
         ini_set('include_path', $path . PATH_SEPARATOR . ini_get('include_path'));
     }
     // run given bootstrap file if necessary
     $bootstrap_path = $input->getOption('bootstrap');
     if (!empty($bootstrap_path)) {
         if (!is_readable($bootstrap_path)) {
             throw new \InvalidArgumentException('Bootstrap file "' . $bootstrap_path . '" is not readable.');
         }
         if ($this->input->getOption('verbose')) {
             $output->writeln('<comment>Requiring boostrap file from "' . $bootstrap_path . '".</comment>');
         }
         require $bootstrap_path;
     }
     // we autoload classes from the current working directory or the specified autoload_dir
     $autoload_dir = $input->getOption('autoload-dir');
     if (!empty($autoload_dir)) {
         if (!is_readable($autoload_dir)) {
             throw new \InvalidArgumentException('Autoload path "' . $autoload_dir . '" is not readable. Please specify an existing directory.');
         }
         if ($this->input->getOption('verbose')) {
             $output->writeln('<comment>Classes will be autoloaded from "' . $autoload_dir . '".</comment>');
         }
     } else {
         if ($this->input->getOption('verbose')) {
             $output->writeln('<comment>No autoload_dir specified, using "' . $this->getCurrentWorkingDirectory() . '" to autoload classes from.</comment>');
         }
     }
     spl_autoload_register(array($this, 'autoload'));
 }
Beispiel #24
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->setInput($input);
     $this->setOutput($output);
     $this->validateConfiguration();
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->setInput($input);
     $this->setOutput($output);
     $this->verbose('Comparing %s "%s" with %s "%s" using "%s" ...', $input->getOption('type'), $input->getArgument('latest'), $input->getOption('type'), $input->getArgument('previous'), $input->getOption('ruleSet'));
     $this->appendIgnorePattern($this->getConfig(), $this->getPreviousWrapper(), $this->getLatestWrapper());
 }
Beispiel #26
0
 /**
  * {@inheritDoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->findVagrantExecutable();
     $this->findLibrarianExecutable();
     parent::initialize($input, $output);
 }
 /**
  * Load options into variables and request other information
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $repository = $input->getArgument('repository');
     if (empty($repository)) {
         return;
     }
     if (strpos($repository, '/') === false) {
         $output->write('<error>The repository should be written in <vendor>/<repository> form.</error>', true);
         exit(1);
     }
     list($this->vendor, $this->repo) = explode('/', $repository);
     $this->version = $input->getArgument('version');
     if ($input->hasOption('version-constant')) {
         $versionConstant = $input->getOption('version-constant');
         if (!empty($versionConstant)) {
             if (strpos($versionConstant, '::') === false) {
                 $output->write('<error>The version constant should be written in <file>::<constant name> form.</error>', true);
                 exit(1);
             }
             list($this->versionFile, $this->versionConstant) = explode('::', $versionConstant);
         }
     }
     $this->devVersion = $input->getArgument('development-version');
     $this->branch = $input->hasOption('branch') ? $input->getOption('branch') : 'master';
     $this->dryRun = $input->getOption('dry-run') ? true : false;
     $this->draft = $input->getOption('draft') ? true : false;
     $this->token = $this->retrieveToken($input, $output);
     $this->committer = $this->retrieveCommitter($input, $output);
     if ($this->dryRun === true) {
         $output->write('<info>Dry Run: not really making a release.</info>', true);
     }
     if ($this->draft === true) {
         $output->write('<info>Draft: creating a draft release.</info>', true);
     }
 }
Beispiel #28
0
 /**
  * {inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->initGit($input);
     $this->initShell($input);
 }
Beispiel #29
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->model = $this->getHelper('container')->getByType('Rixxi\\WatchProcess\\Model');
 }
Beispiel #30
0
 /**
  * Initialize command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if ($input->hasOption('dev')) {
         $this->installDev = true;
     }
 }