Commit 210e7b69 by Qiang Xue

cleanup

parent 60583b87
...@@ -63,7 +63,7 @@ class YiiBase ...@@ -63,7 +63,7 @@ class YiiBase
*/ */
public static $classPath = array(); public static $classPath = array();
/** /**
* @var yii\base\Application the application instance * @var yii\console\Application|yii\web\Application the application instance
*/ */
public static $app; public static $app;
/** /**
......
...@@ -398,8 +398,6 @@ class Application extends Module ...@@ -398,8 +398,6 @@ class Application extends Module
public function registerDefaultAliases() public function registerDefaultAliases()
{ {
Yii::$aliases['@app'] = $this->getBasePath(); Yii::$aliases['@app'] = $this->getBasePath();
Yii::$aliases['@entry'] = dirname($_SERVER['SCRIPT_FILENAME']);
Yii::$aliases['@www'] = '';
} }
/** /**
......
...@@ -13,12 +13,18 @@ namespace yii\base; ...@@ -13,12 +13,18 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class Request extends Component abstract class Request extends Component
{ {
private $_scriptFile; private $_scriptFile;
private $_isConsoleRequest; private $_isConsoleRequest;
/** /**
* 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.
*/
abstract public function resolve();
/**
* Returns a value indicating whether the current request is made via command line * Returns a value indicating whether the current request is made via command line
* @return boolean the value indicating whether the current request is made via console * @return boolean the value indicating whether the current request is made via console
*/ */
......
...@@ -22,6 +22,10 @@ class Request extends \yii\base\Request ...@@ -22,6 +22,10 @@ class Request extends \yii\base\Request
return isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); return isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
} }
/**
* 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.
*/
public function resolve() public function resolve()
{ {
$rawParams = $this->getRawParams(); $rawParams = $this->getRawParams();
......
...@@ -23,7 +23,7 @@ class Application extends \yii\base\Application ...@@ -23,7 +23,7 @@ class Application extends \yii\base\Application
public function registerDefaultAliases() public function registerDefaultAliases()
{ {
parent::registerDefaultAliases(); parent::registerDefaultAliases();
\Yii::$aliases['@www'] = dirname($_SERVER['SCRIPT_FILENAME']); \Yii::$aliases['@webroot'] = dirname($_SERVER['SCRIPT_FILENAME']);
} }
/** /**
...@@ -32,8 +32,8 @@ class Application extends \yii\base\Application ...@@ -32,8 +32,8 @@ class Application extends \yii\base\Application
*/ */
public function processRequest() public function processRequest()
{ {
$route = $this->getUrlManager()->parseRequest($this->getRequest()); list ($route, $params) = $this->getRequest()->resolve();
return $this->runAction($route, $_GET); return $this->runAction($route, $params);
} }
/** /**
...@@ -46,6 +46,24 @@ class Application extends \yii\base\Application ...@@ -46,6 +46,24 @@ class Application extends \yii\base\Application
} }
/** /**
* Returns the response component.
* @return Response the response component
*/
public function getResponse()
{
return $this->getComponent('response');
}
/**
* Returns the session component.
* @return Session the session component
*/
public function getSession()
{
return $this->getComponent('session');
}
/**
* @return UrlManager * @return UrlManager
*/ */
public function getUrlManager() public function getUrlManager()
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace yii\web; namespace yii\web;
use Yii; use Yii;
use yii\base\HttpException;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
/** /**
...@@ -38,6 +39,25 @@ class Request extends \yii\base\Request ...@@ -38,6 +39,25 @@ class Request extends \yii\base\Request
private $_cookies; private $_cookies;
/** /**
* 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.
* @throws HttpException if the request cannot be resolved.
*/
public function resolve()
{
Yii::setAlias('@www', $this->getBaseUrl());
$result = Yii::$app->getUrlManager()->parseRequest($this);
if ($result !== false) {
list ($route, $params) = $result;
$params = array_merge($_GET, $params);
return array($route, $params);
} else {
throw new HttpException(404, Yii::t('yii|Page not found.'));
}
}
/**
* Returns the method of the current request (e.g. GET, POST, HEAD, PUT, DELETE). * Returns the method of the current request (e.g. GET, POST, HEAD, PUT, DELETE).
* @return string request method, such as GET, POST, HEAD, PUT, DELETE. * @return string request method, such as GET, POST, HEAD, PUT, DELETE.
* The value returned is turned into upper case. * The value returned is turned into upper case.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment