You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
13 years ago
|
<?php
|
||
|
/**
|
||
|
* @link http://www.yiiframework.com/
|
||
12 years ago
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||
13 years ago
|
* @license http://www.yiiframework.com/license/
|
||
|
*/
|
||
|
|
||
|
namespace yii\console;
|
||
|
|
||
|
/**
|
||
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||
|
* @since 2.0
|
||
|
*/
|
||
13 years ago
|
class Request extends \yii\base\Request
|
||
13 years ago
|
{
|
||
12 years ago
|
const ANONYMOUS_PARAMS = '-args';
|
||
12 years ago
|
|
||
13 years ago
|
public function getRawParams()
|
||
|
{
|
||
|
return isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Resolves the current request into a route and the associated parameters.
|
||
|
* @return array the first element is the route, and the second is the associated parameters.
|
||
|
*/
|
||
12 years ago
|
public function resolve()
|
||
13 years ago
|
{
|
||
|
$rawParams = $this->getRawParams();
|
||
12 years ago
|
array_shift($rawParams); // the 1st argument is the yii script name
|
||
13 years ago
|
|
||
|
if (isset($rawParams[0])) {
|
||
12 years ago
|
$route = $rawParams[0];
|
||
13 years ago
|
array_shift($rawParams);
|
||
|
} else {
|
||
12 years ago
|
$route = '';
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
$params = array(self::ANONYMOUS_PARAMS => array());
|
||
13 years ago
|
foreach ($rawParams as $param) {
|
||
|
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
|
||
|
$name = $matches[1];
|
||
12 years ago
|
$params[$name] = isset($matches[3]) ? $matches[3] : true;
|
||
13 years ago
|
} else {
|
||
12 years ago
|
$params[self::ANONYMOUS_PARAMS][] = $param;
|
||
13 years ago
|
}
|
||
|
}
|
||
12 years ago
|
|
||
|
return array($route, $params);
|
||
13 years ago
|
}
|
||
|
}
|