OutputInterface PHP Class Code Examples

This page contains top rated real world PHP examples of class OutputInterface extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: DbvInstallCommand.php Project: zitec/CodePaxCLI
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = CodePax_Config::getInstance(CONFIG_PATH . 'config.ini');
     try {
         $sql_engine = CodePax_DbVersioning_SqlEngines_Factory::factory($configuration);
         $dir = ABS_PATH . 'app' . DIRECTORY_SEPARATOR . 'db' . DIRECTORY_SEPARATOR;
         switch (strtolower($configuration->db_engine)) {
             case 'mysql':
                 $sql_file_name = 'db_versions_mysql.sql';
                 break;
             case 'pgsql':
                 $sql_file_name = 'db_versions_pgsql.sql';
                 break;
             case 'sqlsrv':
                 $sql_file_name = 'db_versions_sqlsrv.sql';
                 break;
         }
         $sql_engine->executeChangeScript($dir . $sql_file_name);
     } catch (CodePax_DbVersioning_Exception $e) {
         $output->writeln('An error ocurred: ' . $e->getMessage());
         exit;
     } catch (Exception $e) {
         $output->writeln('Generic error: ' . $e->getMessage());
         exit;
     }
     $output->writeln('CodePax successfully installed!');
 }
Example #2
Show file File: JobCreateCommand.php Project: ErikZigo/syrup
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $command = $input->getArgument('cmd');
     $params = json_decode($input->getArgument('params'), true);
     // Create new job
     /** @var JobFactory $jobFactory */
     $jobFactory = $this->getContainer()->get('syrup.job_factory');
     $jobFactory->setStorageApiClient($this->storageApi);
     $job = $jobFactory->create($command, $params);
     // Add job to Elasticsearch
     /** @var JobMapper $jobMapper */
     $jobMapper = $this->getContainer()->get('syrup.elasticsearch.current_component_job_mapper');
     $jobId = $jobMapper->create($job);
     $output->writeln('Created job id ' . $jobId);
     // Run Job
     if ($input->getOption('run')) {
         $runJobCommand = $this->getApplication()->find('syrup:run-job');
         $returnCode = $runJobCommand->run(new ArrayInput(['command' => 'syrup:run-job', 'jobId' => $jobId]), $output);
         if ($returnCode == 0) {
             $output->writeln('Job successfully executed');
         } elseif ($returnCode == 2 || $returnCode == 64) {
             $output->writeln('DB is locked. Run job later using syrup:run-job');
         } else {
             $output->writeln('Error occured');
         }
     }
     return 0;
 }
Example #3
Show file File: ListCommand.php Project: antistatique/n98-magerun
0
 /**
  * @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'));
 }
Example #4
Show file File: Application.php Project: astronautyan/O2OMobile_PHP
0
 /**
  * Runs the current command.
  *
  * If an event dispatcher has been attached to the application,
  * events are also dispatched during the life-cycle of the command.
  *
  * @param Command         $command A Command instance
  * @param InputInterface  $input   An Input instance
  * @param OutputInterface $output  An Output instance
  *
  * @return int 0 if everything went fine, or an error code
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     foreach ($command->getHelperSet() as $helper) {
         if ($helper instanceof InputAwareInterface) {
             $helper->setInput($input);
         }
     }
     if (null === $this->dispatcher) {
         return $command->run($input, $output);
     }
     $event = new ConsoleCommandEvent($command, $input, $output);
     $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     try {
         $exitCode = $command->run($input, $output);
     } catch (\Exception $e) {
         $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
         $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
         $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
         $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
         throw $event->getException();
     }
     $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
     $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
     return $event->getExitCode();
 }
Example #5
Show file File: GeneratorTask.php Project: milleruk/projectRena
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = prompt("Name");
     $this->descr["description"] = prompt("Description");
     if (!$name) {
         $output->writeln("Error, name is not supplied.");
         exit;
     }
     if ($input->getOption("controller")) {
         $this->controller($name, $output);
     }
     if ($input->getOption("model")) {
         $this->model($name, $output);
     }
     if ($input->getOption("libs")) {
         $this->libs($name, $output);
     }
     if ($input->getOption("task")) {
         $this->task($name, $output);
     }
     if ($input->getOption("cronjob")) {
         $this->cronjob($name, $output);
     }
     if ($input->getOption("resque")) {
         $this->resque($name, $output);
     }
     $output->writeln("Please run update to update RenaApp and Composer");
 }
Example #6
Show file File: CreateCommand.php Project: brentwpeterson/n98-magerun2
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  * @throws \InvalidArgumentException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $subCommandFactory = $this->createSubCommandFactory($input, $output, 'N98\\Magento\\Command\\Developer\\Module\\Create\\SubCommand');
     $configBag = $subCommandFactory->getConfig();
     if (!$input->getOption('modman')) {
         $this->detectMagento($output);
     }
     $configBag->setBool('isModmanMode', $input->getOption('modman'));
     $configBag->setString('magentoRootFolder', $this->_magentoRootFolder);
     $this->initConfigBagDefaultValues($configBag);
     if ($input->getOption('add-all')) {
         $configBag->setBool('shouldAddBlocks', true);
         $configBag->setBool('shouldAddHelpers', true);
         $configBag->setBool('shouldAddModels', true);
         $configBag->setBool('shouldAddSetup', true);
     }
     if ($input->getOption('add-blocks')) {
         $configBag->setBool('shouldAddBlocks', true);
     }
     if ($input->getOption('add-helpers')) {
         $configBag->setBool('shouldAddHelpers', true);
     }
     if ($input->getOption('add-models')) {
         $configBag->setBool('shouldAddModels', true);
     }
     if ($input->getOption('add-setup')) {
         $configBag->setBool('shouldAddSetup', true);
     }
     if ($input->getOption('enable')) {
         $configBag->setBool('shouldEnableModule', true);
     }
     $configBag->setString('baseFolder', __DIR__ . '/../../../../../../res/module/create');
     $configBag->setString('vendorNamespace', ucfirst($input->getArgument('vendorNamespace')));
     $configBag->setString('moduleName', ucfirst($input->getArgument('moduleName')));
     $this->initView($input, $configBag);
     $subCommandFactory->create('CreateModuleFolders')->execute();
     $subCommandFactory->create('CreateModuleRegistrationFiles')->execute();
     if (!$input->getOption('minimal')) {
         $subCommandFactory->create('CreateModuleConfigFile')->execute();
         $subCommandFactory->create('CreateModuleDiFile')->execute();
         $subCommandFactory->create('CreateModuleEventsFile')->execute();
         $subCommandFactory->create('CreateModuleCrontabFile')->execute();
     }
     $subCommandFactory->create('EnableModule')->execute();
     if ($input->getOption('add-readme')) {
         $subCommandFactory->create('CreateReadmeFile')->execute();
     }
     if ($input->getOption('modman')) {
         $subCommandFactory->create('CreateModmanFile')->execute();
     }
     if ($input->getOption('add-composer')) {
         $subCommandFactory->create('CreateComposerFile')->execute();
     }
     if ($input->getOption('add-setup')) {
         $subCommandFactory->create('CreateSetupFiles')->execute();
     }
     if (!$input->getOption('minimal')) {
         $subCommandFactory->create('CreateAdditionalFiles')->execute();
     }
 }
Example #7
Show file File: CoreConfigureCommand.php Project: mistymagich/gush
0
 private function configureAdapter(InputInterface $input, OutputInterface $output, $adapterName, array $adapter)
 {
     /** @var \Gush\Application $application */
     $application = $this->getApplication();
     $isAuthenticated = false;
     $authenticationAttempts = 0;
     $config = [];
     /** @var StyleHelper $styleHelper */
     $styleHelper = $this->getHelper('gush_style');
     $configurator = $application->getAdapterFactory()->createConfigurator($adapterName, $application->getHelperSet());
     while (!$isAuthenticated) {
         // Prevent endless loop with a broken test
         if ($authenticationAttempts > 50) {
             throw new \RuntimeException('Too many attempts, aborting.');
         }
         if ($authenticationAttempts > 0) {
             $styleHelper->error('Authentication failed please try again.');
         }
         try {
             $config = $configurator->interact($input, $output);
             $isAuthenticated = $this->isCredentialsValid($adapterName, $adapter, $config);
         } catch (\Exception $e) {
             $styleHelper->error($e->getMessage());
         }
         ++$authenticationAttempts;
     }
     if ($isAuthenticated) {
         $rawConfig = $this->getConfig()->toArray(Config::CONFIG_SYSTEM);
         $rawConfig['adapters'][$adapterName] = $config;
         $styleHelper->success(sprintf('The "%s" adapter was successfully authenticated.', $adapter['label']));
         $this->getConfig()->merge($rawConfig, Config::CONFIG_SYSTEM);
     }
 }
Example #8
Show file File: WidgetCssGenerateCommand.php Project: global01/victoire
0
 /**
  * Generate a css file containing all css parameters for all widgets used in each view.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $progress = $this->getHelper('progress');
     $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
     $viewRepo = $entityManager->getRepository('Victoire\\Bundle\\CoreBundle\\Entity\\View');
     $widgetRepo = $entityManager->getRepository('Victoire\\Bundle\\WidgetBundle\\Entity\\Widget');
     $viewCssBuilder = $this->getContainer()->get('victoire_core.view_css_builder');
     $widgetMapBuilder = $this->getContainer()->get('victoire_widget_map.builder');
     $viewCssBuilder->clearViewCssFolder();
     $views = $viewRepo->findAll();
     $progress->start($output, count($views));
     /* @var $views View[] */
     foreach ($views as $view) {
         if (!($viewHash = $view->getCssHash())) {
             $view->changeCssHash();
             $entityManager->persist($view);
             $entityManager->flush($view);
         }
         $widgetMapBuilder->build($view, true);
         $widgets = $widgetRepo->findAllWidgetsForView($view);
         $viewCssBuilder->generateViewCss($view, $widgets);
         $progress->advance();
     }
     $progress->finish();
 }
Example #9
Show file File: Install.php Project: margery/thelia
0
 /**
  * Ask to user all needed information
  *
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return array
  */
 protected function getConnectionInfo(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $connectionInfo = array();
     $connectionInfo["host"] = $dialog->askAndValidate($output, $this->decorateInfo("Database host [default: localhost] : "), function ($answer) {
         $answer = trim($answer);
         if (is_null($answer)) {
             throw new \RuntimeException("You must specify a database host");
         }
         return $answer;
     }, false, "localhost");
     $connectionInfo["port"] = $dialog->askAndValidate($output, $this->decorateInfo("Database port [default: 3306]: "), function ($answer) {
         $answer = trim($answer);
         if (is_null($answer)) {
             throw new \RuntimeException("You must specify a database port");
         }
         return $answer;
     }, false, "3306");
     $connectionInfo["dbName"] = $dialog->askAndValidate($output, $this->decorateInfo("Database name (if database does not exist, Thelia will try to create it) : "), function ($answer) {
         $answer = trim($answer);
         if (is_null($answer)) {
             throw new \RuntimeException("You must specify a database name");
         }
         return $answer;
     });
     $connectionInfo["username"] = $dialog->askAndValidate($output, $this->decorateInfo("Database username : "), function ($answer) {
         $answer = trim($answer);
         if (is_null($answer)) {
             throw new \RuntimeException("You must specify a database username");
         }
         return $answer;
     });
     $connectionInfo["password"] = $dialog->askHiddenResponse($output, $this->decorateInfo("Database password : "));
     return $connectionInfo;
 }
Example #10
Show file File: CreateRoleCommand.php Project: Silwereth/sulu
0
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $doctrine = $this->getContainer()->get('doctrine');
     $pool = $this->getContainer()->get('sulu_admin.admin_pool');
     $contexts = $pool->getSecurityContexts();
     $systems = array_keys($contexts);
     if (!$input->getArgument('name')) {
         $question = new Question('Please choose a rolename: ');
         $question->setValidator(function ($name) use($doctrine) {
             if (empty($name)) {
                 throw new \InvalidArgumentException('Rolename cannot be empty');
             }
             $roles = $this->getContainer()->get('sulu.repository.role')->findBy(['name' => $name]);
             if (count($roles) > 0) {
                 throw new \InvalidArgumentException(sprintf('Rolename "%s" is not unique', $name));
             }
             return $name;
         });
         $name = $helper->ask($input, $output, $question);
         $input->setArgument('name', $name);
     }
     if (!$input->getArgument('system')) {
         $question = new ChoiceQuestion('Please choose a system: ', $systems, 0);
         $system = $helper->ask($input, $output, $question);
         $input->setArgument('system', $system);
     }
 }
Example #11
Show file File: GlobalCommand.php Project: detain/composer
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     // extract real command name
     $tokens = preg_split('{\\s+}', $input->__toString());
     $args = array();
     foreach ($tokens as $token) {
         if ($token && $token[0] !== '-') {
             $args[] = $token;
             if (count($args) >= 2) {
                 break;
             }
         }
     }
     // show help for this command if no command was found
     if (count($args) < 2) {
         return parent::run($input, $output);
     }
     // change to global dir
     $config = Factory::createConfig();
     chdir($config->get('home'));
     $this->getIO()->writeError('<info>Changed current directory to ' . $config->get('home') . '</info>');
     // create new input without "global" command prefix
     $input = new StringInput(preg_replace('{\\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\\b}', '', $input->__toString(), 1));
     $this->getApplication()->resetComposer();
     return $this->getApplication()->run($input, $output);
 }
Example #12
Show file File: PluginTypeAnnotationCommand.php Project: legovaer/DrupalConsole
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $output = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output);
         $input->setOption('module', $module);
     }
     // --class option
     $class_name = $input->getOption('class');
     if (!$class_name) {
         $class_name = $output->ask($this->trans('commands.generate.plugin.type.annotation.options.class'), 'ExamplePlugin');
         $input->setOption('class', $class_name);
     }
     // --machine-name option
     $machine_name = $input->getOption('machine-name');
     if (!$machine_name) {
         $machine_name = $output->ask($this->trans('commands.generate.plugin.type.annotation.options.machine-name'), $this->getStringHelper()->camelCaseToUnderscore($class_name));
         $input->setOption('machine-name', $machine_name);
     }
     // --label option
     $label = $input->getOption('label');
     if (!$label) {
         $label = $output->ask($this->trans('commands.generate.plugin.type.annotation.options.label'), $this->getStringHelper()->camelCaseToHuman($class_name));
         $input->setOption('label', $label);
     }
 }
Example #13
Show file File: TimePeriodsUpdateCommand.php Project: dstansby/camdram
0
 protected function addVacation($name, \DateTime $start, \DateTime $end, OutputInterface $output)
 {
     $start_year = $start->format('Y');
     $end_year = $end->format('Y');
     $year = $start_year == $end_year ? $start_year : $start_year . '/' . $end_year;
     $this->createPeriod($name . ' Vacation', $name . ' Vacation', $name . ' Vacation ' . $year, $start, $end, $output);
 }
Example #14
Show file File: DumpCommand.php Project: ccq18/EduSoho
0
 protected function execute(InputInterface $input, OutputInterface $stdout)
 {
     // capture error output
     $stderr = $stdout instanceof ConsoleOutputInterface ? $stdout->getErrorOutput() : $stdout;
     if ($input->getOption('watch')) {
         $stderr->writeln('<error>The --watch option is deprecated. Please use the ' . 'assetic:watch command instead.</error>');
         // build assetic:watch arguments
         $arguments = array('command' => 'assetic:watch', 'write_to' => $this->basePath, '--period' => $input->getOption('period'), '--env' => $input->getOption('env'));
         if ($input->getOption('no-debug')) {
             $arguments['--no-debug'] = true;
         }
         if ($input->getOption('force')) {
             $arguments['--force'] = true;
         }
         $command = $this->getApplication()->find('assetic:watch');
         return $command->run(new ArrayInput($arguments), $stdout);
     }
     // print the header
     $stdout->writeln(sprintf('Dumping all <comment>%s</comment> assets.', $input->getOption('env')));
     $stdout->writeln(sprintf('Debug mode is <comment>%s</comment>.', $this->am->isDebug() ? 'on' : 'off'));
     $stdout->writeln('');
     if ($this->spork) {
         $batch = $this->spork->createBatchJob($this->am->getNames(), new ChunkStrategy($input->getOption('forks')));
         $self = $this;
         $batch->execute(function ($name) use($self, $stdout) {
             $self->dumpAsset($name, $stdout);
         });
     } else {
         foreach ($this->am->getNames() as $name) {
             $this->dumpAsset($name, $stdout);
         }
     }
 }
Example #15
Show file File: InitProcessor.php Project: unkerror/Budabot
0
 /**
  * Processes data from container and console input.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function process(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('init')) {
         $this->initFeaturesDirectoryStructure($output);
         exit(0);
     }
 }
Example #16
Show file File: Command.php Project: GeorgeBroadley/caffeine-vendor
0
 /**
  * Runs the command.
  *
  * The code to execute is either defined directly with the
  * setCode() method or by overriding the execute() method
  * in a sub-class.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return int The command exit code
  *
  * @throws \Exception
  *
  * @see setCode()
  * @see execute()
  *
  * @api
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // force the creation of the synopsis before the merge with the app definition
     $this->getSynopsis();
     // add the application arguments and options
     $this->mergeApplicationDefinition();
     // bind the input against the command specific arguments/options
     try {
         $input->bind($this->definition);
     } catch (\Exception $e) {
         if (!$this->ignoreValidationErrors) {
             throw $e;
         }
     }
     $this->initialize($input, $output);
     if (null !== $this->processTitle) {
         if (function_exists('cli_set_process_title')) {
             cli_set_process_title($this->processTitle);
         } elseif (function_exists('setproctitle')) {
             setproctitle($this->processTitle);
         } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
             $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
         }
     }
     if ($input->isInteractive()) {
         $this->interact($input, $output);
     }
     $input->validate();
     if ($this->code) {
         $statusCode = call_user_func($this->code, $input, $output);
     } else {
         $statusCode = $this->execute($input, $output);
     }
     return is_numeric($statusCode) ? (int) $statusCode : 0;
 }
Example #17
Show file File: tui.class.php Project: Poket-Jony/school-todo-app
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // $model = new ModelController2(new NotePrototype, new GroupPrototype, new JSONController());
     // $model = new ModelController2(new NotePrototype, new GroupPrototype, new MySQLController());
     // $model = new ModelController(new JSONController(), new DataHelper(), new Validator());
     $model = new ModelController(new MySQLController(), new DataHelper(), new Validator());
     $this->setInput($input);
     $this->setOutput($output);
     $this->setModel($model);
     $output->writeln('<info>Todo App</>');
     while (true) {
         switch ($this->showMainMenu()) {
             case $this->startMenuOptions[0]:
                 // all notes
                 switch ($this->showAllNotes()) {
                     case $this->noteMenuOptions[0]:
                         // add note
                         $this->createNote();
                         break;
                     case $this->noteMenuOptions[1]:
                         // edit note
                         $this->editNote();
                         break;
                     case $this->noteMenuOptions[2]:
                         // delete note
                         $this->deleteNote();
                         break;
                     case $this->noteMenuOptions[3]:
                         // back to menu
                         continue;
                         break;
                 }
                 break;
             case $this->startMenuOptions[1]:
                 // all groups
                 switch ($this->showAllGroups()) {
                     case $this->groupMenuOptions[0]:
                         // add group
                         $this->addGroup();
                         break;
                     case $this->groupMenuOptions[1]:
                         // edit group
                         $this->editGroup();
                         break;
                     case $this->groupMenuOptions[2]:
                         // delete group
                         $this->deleteGroup();
                         break;
                     case $this->groupMenuOptions[3]:
                         continue;
                         break;
                 }
                 break;
             case $this->startMenuOptions[2]:
             default:
                 $this->closeApplication();
                 break;
         }
     }
 }
Example #18
Show file File: MigrationsDiffDoctrineCommand.php Project: ccq18/EduSoho
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
     $configuration = $this->getMigrationConfiguration($input, $output);
     DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
     parent::execute($input, $output);
 }
Example #19
Show file File: Application.php Project: ProgrammingPeter/nba-schedule-api
0
 /**
  * Runs the current command.
  *
  * If an event dispatcher has been attached to the application,
  * events are also dispatched during the life-cycle of the command.
  *
  * @param Command         $command A Command instance
  * @param InputInterface  $input   An Input instance
  * @param OutputInterface $output  An Output instance
  *
  * @return int 0 if everything went fine, or an error code
  *
  * @throws \Exception when the command being run threw an exception
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     foreach ($command->getHelperSet() as $helper) {
         if ($helper instanceof InputAwareInterface) {
             $helper->setInput($input);
         }
     }
     if (null === $this->dispatcher) {
         return $command->run($input, $output);
     }
     $event = new ConsoleCommandEvent($command, $input, $output);
     $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     if ($event->commandShouldRun()) {
         try {
             $exitCode = $command->run($input, $output);
         } catch (\Exception $e) {
             $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
             $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
             $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
             $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
             throw $event->getException();
         }
     } else {
         $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
     }
     $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
     $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
     return $event->getExitCode();
 }
Example #20
Show file File: StatusCommand.php Project: inetprocess/sugarcli
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getService('logger');
     $metadata_file = $input->getOption('metadata-file');
     $style = new OutputFormatterStyle(null, null, array('bold'));
     $output->getFormatter()->setStyle('b', $style);
     if (!is_readable($metadata_file)) {
         $logger->error("Unable to access metadata file {$metadata_file}.");
         $output->writeln('');
         $output->writeln("Use \"{$this->getProgramName()} metadata:dump\" first to dump the current table state.");
         return ExitCode::EXIT_METADATA_NOT_FOUND;
     }
     try {
         $meta = new Metadata($logger, $this->getService('sugarcrm.pdo'), $metadata_file);
         $dump_fields = $meta->loadFromFile();
         $db_fields = $meta->loadFromDb();
         $diff = $meta->diff($db_fields, $dump_fields);
         if (empty($diff[Metadata::ADD]) && empty($diff[Metadata::UPDATE]) && empty($diff[Metadata::DEL])) {
             $output->writeln('<info>Metadata are synced</info>');
             return;
         }
         $this->writeAdd($output, $diff[Metadata::ADD]);
         $this->writeUpdate($output, $diff[Metadata::UPDATE]);
         $this->writeDel($output, $diff[Metadata::DEL]);
         if ($input->getOption('quiet') && (!empty($diff[Metadata::ADD]) || !empty($diff[Metadata::DEL]) || !empty($diff[Metadata::UPDATE]))) {
             return ExitCode::EXIT_STATUS_MODIFICATIONS;
         }
     } catch (SugarException $e) {
         $logger->error('An error occured.');
         $logger->error($e->getMessage());
         return ExitCode::EXIT_UNKNOWN_SUGAR_ERROR;
     }
 }
Example #21
Show file File: InstallCommand.php Project: abdeldayem/pim-community-dev
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $forceInstall = $input->getOption('force');
     // if there is application is not installed or no --force option
     if ($this->getContainer()->hasParameter('installed') && $this->getContainer()->getParameter('installed') && !$forceInstall) {
         throw new \RuntimeException('Oro Application already installed.');
     } elseif ($forceInstall) {
         // if --force option we have to clear cache and set installed to false
         $this->updateInstalledFlag($input, $output, false);
     }
     $output->writeln(sprintf('<info>Installing %s Application.</info>', static::APP_NAME));
     $output->writeln('');
     try {
         foreach ($this->getDirectoriesContainer()->getDirectories() as $directory) {
             $this->cleanDirectory($directory);
         }
         $this->checkStep($input, $output)->databaseStep($input, $output)->assetsStep($input, $output);
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Error during PIM installation. %s</error>', $e->getMessage()));
         $output->writeln('');
         return $e->getCode();
     }
     $this->updateInstalledFlag($input, $output, date('c'));
     $output->writeln('');
     $output->writeln(sprintf('<info>%s Application has been successfully installed.</info>', static::APP_NAME));
     return 0;
 }
Example #22
Show file File: GenerateCommand.php Project: xtx-dev/mongodb-migrations
0
 /**
  * @param Symfony\Component\Console\Input\InputInterface
  * @param Symfony\Component\Console\Output\OutputInterface
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = $this->getMigrationConfiguration($input, $output);
     $version = $this->getVersionString();
     $path = $this->generateMigration($configuration, $input, $version);
     $output->writeln(sprintf('Generated new migration class to "<info>%s</info>"', $path));
 }
Example #23
Show file File: Rollback.php Project: Slayug/castor
0
 /**
  * Rollback the migration.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->bootstrap($input, $output);
     $environment = $input->getOption('environment');
     $version = $input->getOption('target');
     $date = $input->getOption('date');
     if (null === $environment) {
         $environment = $this->getConfig()->getDefaultEnvironment();
         $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
     } else {
         $output->writeln('<info>using environment</info> ' . $environment);
     }
     $envOptions = $this->getConfig()->getEnvironment($environment);
     if (isset($envOptions['adapter'])) {
         $output->writeln('<info>using adapter</info> ' . $envOptions['adapter']);
     }
     if (isset($envOptions['wrapper'])) {
         $output->writeln('<info>using wrapper</info> ' . $envOptions['wrapper']);
     }
     if (isset($envOptions['name'])) {
         $output->writeln('<info>using database</info> ' . $envOptions['name']);
     }
     // rollback the specified environment
     $start = microtime(true);
     if (null !== $date) {
         $this->getManager()->rollbackToDateTime($environment, new \DateTime($date));
     } else {
         $this->getManager()->rollback($environment, $version);
     }
     $end = microtime(true);
     $output->writeln('');
     $output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
 }
Example #24
Show file File: ConfigDumpReferenceCommand.php Project: alekitto/symfony
0
 /**
  * {@inheritdoc}
  *
  * @throws \LogicException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $name = $input->getArgument('name');
     if (empty($name)) {
         $io->comment('Provide the name of a bundle as the first argument of this command to dump its default configuration.');
         $io->newLine();
         $this->listBundles($output);
         return;
     }
     $extension = $this->findExtension($name);
     $configuration = $extension->getConfiguration(array(), $this->getContainerBuilder());
     $this->validateConfiguration($extension, $configuration);
     if ($name === $extension->getAlias()) {
         $message = sprintf('Default configuration for extension with alias: "%s"', $name);
     } else {
         $message = sprintf('Default configuration for "%s"', $name);
     }
     switch ($input->getOption('format')) {
         case 'yaml':
             $io->writeln(sprintf('# %s', $message));
             $dumper = new YamlReferenceDumper();
             break;
         case 'xml':
             $io->writeln(sprintf('<!-- %s -->', $message));
             $dumper = new XmlReferenceDumper();
             break;
         default:
             $io->writeln($message);
             throw new \InvalidArgumentException('Only the yaml and xml formats are supported.');
     }
     $io->writeln($dumper->dump($configuration, $extension->getNamespace()));
 }
Example #25
Show file File: CreateModelCommand.php Project: mrcoco/slim3-eloquent-skeleton
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $directory = "app/src/Model/";
     $file = file_get_contents("resources/model_template.txt");
     $file = str_replace("!name", ucfirst($name), $file);
     $file = str_replace("?name", strtolower($name), $file);
     if (is_dir($directory) && !is_writable($directory)) {
         $output->writeln('The "%s" directory is not writable');
         return;
     }
     if (!is_dir($directory)) {
         $dialog = $this->getHelperSet()->get('dialog');
         if (!$dialog->askConfirmation($output, '<question>Directory doesn\'t exist. Would you like to try to create it?</question>')) {
             return;
         }
         @mkdir($directory);
         if (!is_dir($directory)) {
             $output->writeln('<error>Couldn\'t create directory.</error>');
             return;
         }
     }
     if (!file_exists($directory . ucfirst($name) . ".php")) {
         $fh = fopen($directory . ucfirst($name) . ".php", "w");
         fwrite($fh, $file);
         fclose($fh);
         $className = ucfirst($name) . ".php";
         $output->writeln("Created {$className} in App\\Model");
     } else {
         $output->writeln("Class model already Exists!");
     }
 }
Example #26
Show file File: CreateUserCommand.php Project: acorbel/FOSUserBundle
0
 private function legacyInteract(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getArgument('username')) {
         $username = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a username:', function ($username) {
             if (empty($username)) {
                 throw new \Exception('Username can not be empty');
             }
             return $username;
         });
         $input->setArgument('username', $username);
     }
     if (!$input->getArgument('email')) {
         $email = $this->getHelper('dialog')->askAndValidate($output, 'Please choose an email:', function ($email) {
             if (empty($email)) {
                 throw new \Exception('Email can not be empty');
             }
             return $email;
         });
         $input->setArgument('email', $email);
     }
     if (!$input->getArgument('password')) {
         $password = $this->getHelper('dialog')->askHiddenResponseAndValidate($output, 'Please choose a password:', function ($password) {
             if (empty($password)) {
                 throw new \Exception('Password can not be empty');
             }
             return $password;
         });
         $input->setArgument('password', $password);
     }
 }
Example #27
Show file File: ConfigCommand.php Project: pradeep-wagento/magento2
0
 /**
  * Display the contents of the file in a pretty formatted way
  *
  * @param array           $contents
  * @param array           $rawContents
  * @param OutputInterface $output
  * @param string|null     $k
  */
 protected function listConfiguration(array $contents, array $rawContents, OutputInterface $output, $k = null)
 {
     $origK = $k;
     $io = $this->getIO();
     foreach ($contents as $key => $value) {
         if ($k === null && !in_array($key, array('config', 'repositories'))) {
             continue;
         }
         $rawVal = isset($rawContents[$key]) ? $rawContents[$key] : null;
         if (is_array($value) && (!is_numeric(key($value)) || $key === 'repositories' && null === $k)) {
             $k .= preg_replace('{^config\\.}', '', $key . '.');
             $this->listConfiguration($value, $rawVal, $output, $k);
             $k = $origK;
             continue;
         }
         if (is_array($value)) {
             $value = array_map(function ($val) {
                 return is_array($val) ? json_encode($val) : $val;
             }, $value);
             $value = '[' . implode(', ', $value) . ']';
         }
         if (is_bool($value)) {
             $value = var_export($value, true);
         }
         if (is_string($rawVal) && $rawVal != $value) {
             $io->write('[<comment>' . $k . $key . '</comment>] <info>' . $rawVal . ' (' . $value . ')</info>');
         } else {
             $io->write('[<comment>' . $k . $key . '</comment>] <info>' . $value . '</info>');
         }
     }
 }