Invokes a single Symfony command.

@param string $command_name
The name of the command, e.g., 'tests:behat:run'.
@param array $args
An array of arguments to pass to the command.

@throws \Acquia\Blt\Robo\Exceptions\BltException
555798
protected function invokeCommand($command_name, array $args = []) {
    $this->invokeDepth++;

    if (!$this->isCommandDisabled($command_name)) {
      /** @var \Acquia\Blt\Robo\Application $application */
      $application = $this->getContainer()->get('application');
      $command = $application->find($command_name);

      $input = new ArrayInput($args);
      $input->setInteractive($this->input()->isInteractive());
      $prefix = str_repeat(">", $this->invokeDepth);
      $this->output->writeln("<comment>$prefix $command_name</comment>");
      $exit_code = $application->runCommand($command, $input, $this->output());
      $this->invokeDepth--;

      // The application will catch any exceptions thrown in the executed
      // command. We must check the exit code and throw our own exception. This
      // obviates the need to check the exit code of every invoked command.
      if ($exit_code) {
        throw new BltException("Command `$command_name {$input->__toString()}` exited with code $exit_code.");
      }
    }
  }
853073
protected function runCommand(string $name, $handler, array $options)
    {
        if (\is_object($handler) && \method_exists($handler, '__invoke')) {
            if ($this->input->getSameOpt(['h', 'help'])) {
                $desc = $options['description'] ?? 'No command description message';

                return $this->output->write($desc);
            }

            $result = $handler($this->input, $this->output);
        } else {
            if (!\class_exists($handler)) {
                Helper::throwInvalidArgument("The console command class [$handler] not exists!");
            }

            /** @var Command $object */
            $object = new $handler($this->input, $this->output);

            if (!($object instanceof Command)) {
                Helper::throwInvalidArgument("The console command class [$handler] must instanceof the " . Command::class);
            }

            $object::setName($name);
            $object->setApp($this);
            $result = $object->run();
        }

        return $result;
    }
387792
public function callCommand(string $command, array $arguments = [])
    {
        $newCommand = $this->getApplication()->find($command);

        $arguments['command'] = $command;

        return $newCommand->run(new ArrayInput($arguments), $this->getOutput());
    }
890969
public function execute($command_name)
    {
        // Find it
        if (!($command = Command::find($command_name))) {
            App::abort(404);
        }

        // Run it, ignoring all output
        set_time_limit(self::MAX_EXECUTION_TIME);
        ob_start();
        Artisan::call($command->getName());
        ob_end_clean();

        // Return response
        return Response::json('ok');
    }
1366948
protected function fireEvent($name, $beforeOrAfter, &$args)
	{
		$eventName = 'cb.' . $beforeOrAfter . '.' . $name;

		Event::fire($eventName, $args);
	}
470124
public function callSilent($command, array $arguments = []) {
		$instance = $this->getApplication()->find($command);
		$arguments['command'] = $command;

		return $instance->run(new ArrayInput($arguments), new NullOutput);
	}
651690
public function runCommand($command)
    {
        $this->setAutoExit(false);
        $argv = explode(' ','application '.$command);
        $input = new ArgvInput($argv);
        $this->run($input);
    }
1186842
public function execute($commandName, $params = [])
    {
        $className = str_replace(' ', '', ucwords(str_replace('-', ' ', $commandName))) . 'Command';
        $clearCommandName = $this->getNamespace() . "\\console\\" . $className;
        if (!class_exists($clearCommandName)) $clearCommandName = '\\app\\console\\' . $className;
        if (!class_exists($clearCommandName)) $clearCommandName = 'PhpDevil\\framework\\console\\commands\\' . $className;
        if (!class_exists($clearCommandName)) die("\nCommand " . $commandName . " not found");
        (new $clearCommandName)->execute($params);
    }
1313534
protected function executeSymfonyCmdHook(CommandHookInterface $command_hook, $method)
    {
        $command = $command_hook->getCommand();

        $container = ProjectX::getContainer();
        $application = $container->get('application');

        try {
            $info = $this->getCommandInfo($method);
            $command = $application->find($command);

            if ($command->getName() === $info->getName()) {
                throw new \Exception(sprintf(
                    'Unable to call the %s command hook due to it ' .
                    'invoking the parent method.',
                    $command->getName()
                ));
            }
        } catch (CommandNotFoundException $exception) {
            throw new CommandHookRuntimeException(sprintf(
                'Unable to find %s command in the project-x command ' .
                'hook.',
                $command
            ));
        } catch (\Exception $exception) {
            throw new CommandHookRuntimeException($exception->getMessage());
        }
        $exec = $this->taskSymfonyCommand($command);
        $definition = $command->getDefinition();

        // Support symfony command options.
        if ($command_hook->hasOptions()) {
            foreach ($command_hook->getOptions() as $option => $value) {
                if (is_numeric($option)) {
                    $option = $value;
                    $value = null;
                }
                if (!$definition->hasOption($option)) {
                    continue;
                }
                $exec->opt($option, $value);
            }
        }

        // Support symfony command arguments.
        if ($command_hook->hasArguments()) {
            foreach ($command_hook->getArguments() as $arg => $value) {
                if (!isset($value) || !$definition->hasArgument($arg)) {
                    continue;
                }
                $exec->arg($arg, $value);
            }
        }

        return $exec->run();
    }
135416
public static function trigger($name, $args) {
        if (array_key_exists($name, static::$events)) {
            $infos = static::$events[ $name ];
            if ($infos) {
                foreach ($infos as $info) {
                    $module = Ioc::get($info[ 'class' ]);
                    if ($info[ 'action' ]) {
                        static::doAction($module, $info[ 'action' ], $args);
                    }
                }
            }
        }
    }
327213
protected function executeCommand(OutputInterface $output, $name, $args = [])
    {
        array_unshift($args, 'internal');

        $return = $this->getApplication()->find($name)->run(new ArrayInput($args), $output);

        if (0 !== $return) {
            throw new \RuntimeException(sprintf("An error occured when executing command '%s'", $name), 30);
        }

        return $this;
    }
122796
private function _execute_command() {
		$app = new Application( 'Codeception', \Codeception\Codecept::VERSION );
		$app->add( new \WPCC\Command\Build( 'build' ) );
		$app->add( new \Codeception\Command\Console( 'console' ) );
		$app->add( new \WPCC\Command\Bootstrap( 'bootstrap' ) );
		$app->add( new \Codeception\Command\GenerateCept( 'generate-cept' ) );
		$app->add( new \Codeception\Command\GenerateCest( 'generate-cest' ) );
		$app->add( new \Codeception\Command\GenerateTest( 'generate-test' ) );
		$app->add( new \Codeception\Command\GeneratePhpUnit( 'generate-phpunit' ) );
		$app->add( new \Codeception\Command\GenerateSuite( 'generate-suite' ) );
		$app->add( new \Codeception\Command\GenerateHelper( 'generate-helper' ) );
		$app->add( new \Codeception\Command\GenerateScenarios( 'generate-scenarios' ) );
		$app->add( new \Codeception\Command\Clean( 'clean' ) );
		$app->add( new \Codeception\Command\GenerateGroup( 'generate-group' ) );
		$app->add( new \Codeception\Command\GeneratePageObject( 'generate-pageobject' ) );
		$app->add( new \Codeception\Command\GenerateStepObject( 'generate-stepobject' ) );
		$app->run( new ArgvInput() );
	}
993626
protected function command($command, $args)
    {
        $command = trim(sprintf('git %s %s', $command, Stringify::arguments($args)));
        list($output, $return) = $this->execute($command);
        if ($return != self::SUCCESS) {
            throw new CommandFailureException($output);
        }

        if (is_array($output)) {
            return array_map('trim', $output);
        }

        return trim($output);
    }
935512
private function exec( $controller_name, $args )
	{
		// Process controller
		$compo = explode( '@', $controller_name );

		if ( count( $compo ) <= 1 ) {

			throw new Exception( sprintf( 'Controller action must be defined in %s.', $controller_name ) );

		}

		// Get controller
		require_once(  $this->controllers_path . $compo[0] . '.php' );
		$classname = sprintf( $this->namespace . '\Controllers\%s', $compo[0]);
		$controller = new $classname( $this->view );

		if ( !method_exists( $controller, $compo[1] ) ) {

			throw new Exception( sprintf( 'Controller action "%s" not found in %s.', $compo[1], $compo[0] ) );

		}

		return call_user_func_array( [ $controller, $compo[1] ], $args );
	}
846028
public function execute($name, $args)
	{
	    if (!$this->__sock) {
	        return null;
	    }
	    
	    $args = (array) $args;
	    if(in_array($name, static::$keyCommands)) {
	        if ($this->options['prefix'] && strpos($args[0], $this->options['prefix']) === false) {
	            $args[0] = $this->options['prefix'] . $args[0];
	        }
	    }
	    
	    /* Build the Redis unified protocol command */
	    array_unshift($args, strtoupper($name));
	    $command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF);
	    
	    /* Open a Redis connection and execute the command */
	    for ($written = 0; $written < strlen($command); $written += $fwrite) {
	        $fwrite = fwrite($this->__sock, substr($command, $written));
	        if ($fwrite === FALSE) {
	            throw new Exception('Failed to write entire command to stream');
	        }
	    }
	    
	    /* Parse the response based on the reply identifier */
	    $reply = trim(fgets($this->__sock, 512));
	    switch (substr($reply, 0, 1)) {
	        /* Error reply */
	        case '-':
	            throw new RedisException(substr(trim($reply), 4));
	            break;
	            /* Inline reply */
	        case '+':
	            $response = substr(trim($reply), 1);
	            break;
	            /* Bulk reply */
	        case '$':
	            $response = null;
	            if ($reply == '$-1') {
	                break;
	            }
	            $read = 0;
	            $size = substr($reply, 1);
	            do {
	                $block_size = ($size - $read) > 1024 ? 1024 : ($size - $read);
	                $response .= fread($this->__sock, $block_size);
	                $read += $block_size;
	            } while ($read < $size);
	            fread($this->__sock, 2); /* discard crlf */
	            break;
	            /* Multi-bulk reply */
	        case '*':
	            $count = substr($reply, 1);
	            if ($count == '-1') {
	                return null;
	            }
	            $response = array();
	            for ($i = 0; $i < $count; $i++) {
	                $bulk_head = trim(fgets($this->__sock, 512));
	                $size = substr($bulk_head, 1);
	                if ($size == '-1') {
	                    $response[] = null;
	                }
	                else {
	                    $read = 0;
	                    $block = "";
	                    do {
	                        $block_size = ($size - $read) > 1024 ? 1024 : ($size - $read);
	                        $block .= fread($this->__sock, $block_size);
	                        $read += $block_size;
	                    } while ($read < $size);
	                    fread($this->__sock, 2); /* discard crlf */
	                    $response[] = $block;
	                }
	            }
	            break;
	            /* Integer reply */
	        case ':':
	            $response = intval(substr(trim($reply), 1));
	            break;
	        default:
	            throw new RedisException("invalid server response: {$reply}");
	            break;
	    }
	    /* Party on */
	    return $response;
	}
282891
protected function handle($name, array $args = [])
    {
        if (isset($this->handlers[$name]) && is_callable($this->handlers[$name])) {
            array_unshift($args, $this);
            call_user_func_array($this->handlers[$name], $args);
        }
    }
610118
public function getCommand($name, array $args = [])
    {
        if (!$this->description->hasOperation($name)) {
            $name = ucfirst($name);
            if (!$this->description->hasOperation($name)) {
                throw new \InvalidArgumentException(
                    "No operation found named {$name}"
                );
            }
        }

        // Merge in default command options
        $args += $this->getConfig('defaults');

        return parent::getCommand($name, $args);
    }