execute console lifecycle

@param array|null $argv
553333
public function run(array $argv = null)
    {
        // If no $argv is provided then use the global PHP defined $argv.
        if (is_null($argv)) {
            global $argv;
        }

        // handle call
        $this->handle($argv);

        // exit cli with code 0 or even 1 for error
        $this->shutdown();
    }
289368
protected function runCommand(Command $command, array $argv, ConsoleIo $io)
    {
        try {
            return $command->run($argv, $io);
        } catch (StopException $e) {
            return $e->getCode();
        }
    }
1203706
protected function _parseArg($argv) {
        for ($i = 0; $i < count($argv); $i++) {
            if ($argv[$i] != 'console') {
                if (!preg_match('#\[#', $argv[$i])) {
                    array_push($this->_argv, $argv[$i]);
                }
                else {
                    $data = '';

                    for ($i = 0; $i < count($argv); $i++) {
                        $data .= $argv[$i] . ' ';

                        if (preg_match('#\]#', $argv[$i])) {
                            $data = str_replace(['[', ']'], ['', ''], $data);
                            array_push($this->_argv, trim($data));
                            break;
                        }
                    }
                }
            }
        }
    }
1206313
public function init($args = null){
		/*
		echo __METHOD__.__LINE__.'<br>'.PHP_EOL;
		echo __METHOD__.__LINE__.'get_class<pre>['.var_export(get_class($this), true).']</pre>'.'<br>'.PHP_EOL; 
		echo __METHOD__.__LINE__.'get_parent_class<pre>['.var_export(get_parent_class(__CLASS__), true).']</pre>'.'<br>'.PHP_EOL; 
		echo __METHOD__.__LINE__.'<br>'.PHP_EOL;
		echo __METHOD__.__LINE__.'get_class_methods<pre>['.var_export(get_class_methods($this), true).']</pre>'.'<br>'.PHP_EOL; 
		*/
		#parent::__construct($this->logConfig);
		
		$this->logConfig = $GLOBALS["CONFIG_MANAGER"]->getSetting('AUTH','AUDIT','CLIENT_LOG');
		
		parent::__construct($args);
		return;
	}
1009574
private function _execute($args = array())
    {
        if ($this->_err) {
            return false;
        };
        if ($this->_sth) {
            if ($this->_sth->execute($args)) {
                return true;
            } else {
                $this->_err = implode(' ', $this->_sth->errorInfo());
                return false;
            };
        } else {
            $this->_err = "No statement to execute.";
        };
        return false;
    }
1288442
public function executeSimple($commandline, $dir = null, array $env = [])
    {
        $this->stdErr->writeln(
            'Running command: <info>' . $commandline . '</info>',
            OutputInterface::VERBOSITY_VERBOSE
        );

        if (!empty($env)) {
            $this->showEnvMessage($env);
            $env = $env + $this->getParentEnv();
        } else {
            $env = null;
        }

        $this->showWorkingDirMessage($dir);

        $process = proc_open($commandline, [STDIN, STDOUT, STDERR], $pipes, $dir, $env);

        return proc_close($process);
    }
868660
public function handle($args = null)
    {
        $this->_args = $args !== null ? $args : $GLOBALS['argv'];

        list(, $controllerName, $commandName) = array_pad($this->_args, 3, null);
        if ($commandName !== null && $commandName[0] === '-') {
            $commandName = null;
        }

        if ($controllerName === 'list') {
            $controllerName = 'help';
            $commandName = $commandName ?: 'list';
        } elseif ($controllerName === null) {
            $controllerName = 'help';
        } elseif ($controllerName === 'help' && $commandName !== null && $commandName !== 'list') {
            $controllerName = $commandName;
            $commandName = 'help';
        }

        $controllerName = Text::camelize($controllerName);
        $commandName = lcfirst(Text::camelize($commandName));

        $controllerClassName = null;

        if ($this->alias->has('@ns.cli')) {
            $namespaces = ['@ns.cli', 'ManaPHP\\Cli\\Controllers'];
        } else {
            $namespaces = ['ManaPHP\\Cli\\Controllers'];
        }

        foreach ($namespaces as $prefix) {
            $className = $this->alias->resolveNS($prefix . '\\' . $controllerName . 'Controller');

            if (class_exists($className)) {
                $controllerClassName = $className;
                break;
            }
        }

        if (!$controllerClassName) {
            $guessed = $this->_guessController($controllerName);
            if ($guessed) {
                $controllerClassName = $guessed;
                $controllerName = basename(substr($controllerClassName, strrpos($controllerClassName, '\\')), 'Controller');
            } else {
                return $this->console->error(['`:command` command is not exists', 'command' => lcfirst($controllerName) . ':' . $commandName]);
            }
        }

        $controllerInstance = $this->_di->getShared($controllerClassName);
        if ($commandName === '') {
            $commands = $this->_getCommands($controllerClassName);
            if (count($commands) === 1) {
                $commandName = $commands[0];
            } elseif (in_array('default', $commands, true)) {
                $commandName = 'default';
            } else {
                $commandName = 'help';
            }
        }

        if ($commandName !== 'help' && in_array('--help', $this->_args, true)) {
            $commandName = 'help';
        }

        if (!method_exists($controllerInstance, $commandName . 'Command')) {
            $guessed = $this->_guessCommand($controllerClassName, $commandName);
            if (!$guessed) {
                return $this->console->error(['`:command` sub command is not exists', 'command' => lcfirst($controllerName) . ':' . $commandName]);
            } else {
                $commandName = $guessed;
            }
        }

        try {
            $r = $this->commandInvoker->invoke($controllerInstance, $commandName);
        } /** @noinspection PhpRedundantCatchClauseInspection */
        catch (ArgumentsException $e) {
            return $this->console->error($e->getMessage());
        }

        return is_int($r) ? $r : 0;
    }
449744
public function execute(array $args, array $options = [])
    {
        $this->bootstrap($args, $options);

        $version = isset($options['target']) ? $options['target'] : $options['t'];
        $date = isset($options['date']) ? $options['date'] : $options['d'];
        $force = isset($options['force']) ? $options['force'] : $options['f'];

        // rollback the specified environment
        $start = microtime(true);
        if (null !== $date) {
            $this->getManager()->rollbackToDateTime(new \DateTime($date), $force);
        } else {
            $this->getManager()->rollback($version, $force);
        }
        $end = microtime(true);

        Output::writeln('');
        Output::writeln(Colour::colour('All Done. Took ', Colour::GREEN) . sprintf('%.4fs', $end - $start));
    }
1196254
final public function run(int $argc, array $argv)
    {
        $ar = new ArgsManager();
        $ar->getArgs($argc, $argv);
    }
849938
public function main(array $argv)
    {
        // @codeCoverageIgnoreStart
        // We cannot easily test this, so we'll skip it. Pretty basic anyway.

        if (!$this->stderr) {
            $this->stderr = fopen('php://stderr', 'w');
        }
        if (!$this->stdout) {
            $this->stdout = fopen('php://stdout', 'w');
        }
        if (!$this->stdin) {
            $this->stdin = fopen('php://stdin', 'r');
        }

        // @codeCoverageIgnoreEnd

        try {
            list($options, $positional) = $this->parseArguments($argv);

            if (isset($options['q'])) {
                $this->quiet = true;
            }
            $this->log($this->colorize('green', 'sabre/vobject ').$this->colorize('yellow', Version::VERSION));

            foreach ($options as $name => $value) {
                switch ($name) {
                    case 'q':
                        // Already handled earlier.
                        break;
                    case 'h':
                    case 'help':
                        $this->showHelp();

                        return 0;
                        break;
                    case 'format':
                        switch ($value) {
                            // jcard/jcal documents
                            case 'jcard':
                            case 'jcal':

                            // specific document versions
                            case 'vcard21':
                            case 'vcard30':
                            case 'vcard40':
                            case 'icalendar20':

                            // specific formats
                            case 'json':
                            case 'mimedir':

                            // icalendar/vcad
                            case 'icalendar':
                            case 'vcard':
                                $this->format = $value;
                                break;

                            default:
                                throw new InvalidArgumentException('Unknown format: '.$value);
                        }
                        break;
                    case 'pretty':
                        if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
                            $this->pretty = true;
                        }
                        break;
                    case 'forgiving':
                        $this->forgiving = true;
                        break;
                    case 'inputformat':
                        switch ($value) {
                            // json formats
                            case 'jcard':
                            case 'jcal':
                            case 'json':
                                $this->inputFormat = 'json';
                                break;

                            // mimedir formats
                            case 'mimedir':
                            case 'icalendar':
                            case 'vcard':
                            case 'vcard21':
                            case 'vcard30':
                            case 'vcard40':
                            case 'icalendar20':

                                $this->inputFormat = 'mimedir';
                                break;

                            default:
                                throw new InvalidArgumentException('Unknown format: '.$value);
                        }
                        break;
                    default:
                        throw new InvalidArgumentException('Unknown option: '.$name);
                }
            }

            if (0 === count($positional)) {
                $this->showHelp();

                return 1;
            }

            if (1 === count($positional)) {
                throw new InvalidArgumentException('Inputfile is a required argument');
            }

            if (count($positional) > 3) {
                throw new InvalidArgumentException('Too many arguments');
            }

            if (!in_array($positional[0], ['validate', 'repair', 'convert', 'color'])) {
                throw new InvalidArgumentException('Uknown command: '.$positional[0]);
            }
        } catch (InvalidArgumentException $e) {
            $this->showHelp();
            $this->log('Error: '.$e->getMessage(), 'red');

            return 1;
        }

        $command = $positional[0];

        $this->inputPath = $positional[1];
        $this->outputPath = isset($positional[2]) ? $positional[2] : '-';

        if ('-' !== $this->outputPath) {
            $this->stdout = fopen($this->outputPath, 'w');
        }

        if (!$this->inputFormat) {
            if ('.json' === substr($this->inputPath, -5)) {
                $this->inputFormat = 'json';
            } else {
                $this->inputFormat = 'mimedir';
            }
        }
        if (!$this->format) {
            if ('.json' === substr($this->outputPath, -5)) {
                $this->format = 'json';
            } else {
                $this->format = 'mimedir';
            }
        }

        $realCode = 0;

        try {
            while ($input = $this->readInput()) {
                $returnCode = $this->$command($input);
                if (0 !== $returnCode) {
                    $realCode = $returnCode;
                }
            }
        } catch (EofException $e) {
            // end of file
        } catch (\Exception $e) {
            $this->log('Error: '.$e->getMessage(), 'red');

            return 2;
        }

        return $realCode;
    }
789002
protected function preprocessingArguments(array $argv)
    {
        // preprocessing arguments
        $newArgv = [];
        $extra = [];
        $afterDash = false;
        foreach ($argv as $arg) {
            if ($arg === '--') {
                $afterDash = true;
                continue;
            }
            if ($afterDash) {
                $extra[] = $arg;
                continue;
            }

            $a = new Argument($arg);
            if ($a->anyOfOptions($this->specs) && $a->containsOptionValue()) {
                list($opt, $val) = $a->splitAsOption();
                array_push($newArgv, $opt, $val);
            } else {
                $newArgv[] = $arg;
            }
        }

        return [$newArgv, $extra];
    }
856003
public static void main(String argv[]) throws Exception {
    DnsMonitorSecurityManager.setTheManager();
    AvatarZKShell shell = null;

    shell = new AvatarZKShell();
    int res;
    try {
      res = ToolRunner.run(shell, argv);
    } finally {
      shell.close();
    }
    System.exit(res);
  }
1327089
function execute(argv, bin, args, req) {
  var config = this.configure();
  var errors = this.errors, scope = this, e;
  var dir = config.bin || dirname(argv[1]);
  var local = path.join(dir, bin);
  var exists = fs.existsSync(local);
  var data = {bin: bin, dir: dir, local: local, args: args};
  if(!exists) {
    e = new ExecError(errors.EEXEC_NOENT.message, [bin], errors.EEXEC_NOENT.code);
    e.data = data;
    throw e;
  }
  var stat = fs.statSync(local);
  var ps = spawn(local, args, {stdio: [0, 1, 'pipe']});
  req.process = ps;
  this.emit('exec', ps, local, args, req);
  ps.on('error', function(err){
    error(scope, err, [bin]);
  });
  // suppress the execvp() error so we can cleanly
  // present our own error message
  ps.stderr.on('data', function(data) {
    if(!/^execvp\(\)/.test(data.toString())) {
      process.stderr.write(data);
    }
  })
  ps.on('close', function (code, signal) {
    // NOTE: workaround for https://github.com/joyent/node/issues/3222
    // NOTE: assume child process exited gracefully on SIGINT
    if(signal == 'SIGINT') {
      return process.exit(0);
    }
    // TODO: remove this event?
    scope.emit('close', code, signal);
    if(config.exit) process.exit(code);
  });
  return ps;
}
223427
public function executeCommand(array $args, OutputInterface $output, $message)
    {
        $name = $args[0];
        $cmd = $this->getCmd($args);

        $output->writeln('');
        $output->writeln(
            sprintf(
                '<info>Running %s</info>',
                $name
            )
        );

        $output->writeln(
            sprintf(
                '<comment>%s</comment>',
                $cmd
            )
        );

        $this->process->setCommandLine($cmd);
        $this->process->run(
            function ($type, $buffer) use ($output, $cmd) {
                if (Process::ERR === $type) {
                    $output->writeln(
                        sprintf(
                            '<error>%s</error>',
                            $buffer
                        )
                    );
                } else {
                    $output->writeln(
                        sprintf(
                            '<comment>%s</comment>',
                            $buffer
                        )
                    );
                }
            }
        );

        if (!$this->process->isSuccessful()) {
            throw new \RuntimeException($message . '<error>' . $this->process->getErrorOutput() . '</error>');
        }
    }
714700
public function handle(array $args = [])
    {
        // remove source file name from argv
        $source = array_shift($args);

        /** @var ConsoleEvent $applicationEvent */
        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setName(self::EVENT_REQUEST_RECEIVED);
        $applicationEvent->setSourceFile($source);
        $applicationEvent->setArguments($args);
        $this->emit($applicationEvent);

        // init dispatcher
        $dispatcher = new Dispatcher($this->commands, $this->container);

        $middlewareRunner = new MiddlewareRunner($this->getMiddlewares());

        $middlewareRunner->run([$applicationEvent->getArguments()], function ($args) use ($applicationEvent, $dispatcher) {
            // dispatch command with args from cli
            $dispatcher->dispatch($args);
        });
    }
372944
protected function parseArgv($argv)
    {
        foreach ($this->argv as $arg) {
            $parts = explode('=', $arg);
            if (! isset($parts[1])) {
                continue;
            }
            $value = $parts[1];
            $key   = strtr($parts[0], [
                '-' => ''
            ]);

            if (array_key_exists($key, $this->supportedArgs)) {
                $this->parsedArgs[$key] = $value;
            }

        }

        return $this;
    }
920782
public function defined($name, array $argv = null)
    {
        // The argument isn't defined if it's not defined by the calling code.
        if (!$this->exists($name)) {
            return false;
        }

        $argument = $this->arguments[$name];
        $command_arguments = $this->parser->arguments($argv);

        foreach ($command_arguments as $command_argument) {
            if ($this->isArgument($argument, $command_argument)) {
                return true;
            }
        }

        return false;
    }