lithium\console\Dispatcher::run()

public static method

Dispatches a request based on a request object (an instance of lithium\console\Request).

If $request is null, a new request object is instantiated based on the value of the 'request' key in the $_classes array.

Parameters

  • object $request

    An instance of a request object with console request information. If null, an instance will be created.

  • array $options

Returns

object

The command action result which is an instance of lithium\console\Response.

Filter

Allows to execute very early or very late in the command request.

Source

	public static function run($request = null, $options = []) {
		$defaults = ['request' => []];
		$options += $defaults;
		$params = compact('request', 'options');

		return Filters::run(get_called_class(), __FUNCTION__, $params, function($params) {
			$classes = static::$_classes;

			$request = $params['request'];
			$options = $params['options'];
			$router = $classes['router'];

			$request = $request ?: new $classes['request']($options['request']);
			$request->params = $router::parse($request);
			$params = static::applyRules($request->params);
			Environment::set($request);
			try {
				$callable = static::_callable($request, $params, $options);
				return static::_call($callable, $request, $params);
			} catch (UnexpectedValueException $e) {
				return (object) ['status' => $e->getMessage() . "\n"];
			}
		});
	}