Cake\Console\ShellDispatcher::dispatch PHP Method

dispatch() public method

Converts a shell command result into an exit code. Null/True are treated as success. All other return values are an error.
public dispatch ( array $extra = [] ) : integer
$extra array Extra parameters that you can manually pass to the Shell to be dispatched. Built-in extra parameter is : - `requested` : if used, will prevent the Shell welcome message to be displayed
return integer The cli command exit code. 0 is success.
    public function dispatch($extra = [])
    {
        try {
            $result = $this->_dispatch($extra);
        } catch (StopException $e) {
            return $e->getCode();
        }
        if ($result === null || $result === true) {
            return 0;
        }
        return 1;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Dispatch a command to another Shell. Similar to Object::requestAction()
  * but intended for running shells from other shells.
  *
  * ### Usage:
  *
  * With a string command:
  *
  * ```
  * return $this->dispatchShell('schema create DbAcl');
  * ```
  *
  * Avoid using this form if you have string arguments, with spaces in them.
  * The dispatched will be invoked incorrectly. Only use this form for simple
  * command dispatching.
  *
  * With an array command:
  *
  * ```
  * return $this->dispatchShell('schema', 'create', 'i18n', '--dry');
  * ```
  *
  * With an array having two key / value pairs:
  *  - `command` can accept either a string or an array. Represents the command to dispatch
  *  - `extra` can accept an array of extra parameters to pass on to the dispatcher. This
  *  parameters will be available in the `param` property of the called `Shell`
  *
  * `return $this->dispatchShell([
  *      'command' => 'schema create DbAcl',
  *      'extra' => ['param' => 'value']
  * ]);`
  *
  * or
  *
  * `return $this->dispatchShell([
  *      'command' => ['schema', 'create', 'DbAcl'],
  *      'extra' => ['param' => 'value']
  * ]);`
  *
  * @return mixed The return of the other shell.
  * @link http://book.cakephp.org/3.0/en/console-and-shells.html#invoking-other-shells-from-your-shell
  */
 public function dispatchShell()
 {
     list($args, $extra) = $this->parseDispatchArguments(func_get_args());
     if (!isset($extra['requested'])) {
         $extra['requested'] = true;
     }
     $dispatcher = new ShellDispatcher($args, false);
     return $dispatcher->dispatch($extra);
 }
All Usage Examples Of Cake\Console\ShellDispatcher::dispatch