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.
78 lines
2.4 KiB
78 lines
2.4 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\base;
|
||
|
|
||
|
/**
|
||
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||
|
* @since 2.0
|
||
|
*/
|
||
12 years ago
|
abstract class Request extends Component
|
||
13 years ago
|
{
|
||
|
private $_scriptFile;
|
||
12 years ago
|
private $_isConsoleRequest;
|
||
13 years ago
|
|
||
|
/**
|
||
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.
|
||
|
*/
|
||
|
abstract public function resolve();
|
||
|
|
||
|
/**
|
||
12 years ago
|
* 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
|
||
13 years ago
|
*/
|
||
12 years ago
|
public function getIsConsoleRequest()
|
||
13 years ago
|
{
|
||
12 years ago
|
return $this->_isConsoleRequest !== null ? $this->_isConsoleRequest : PHP_SAPI === 'cli';
|
||
13 years ago
|
}
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Sets the value indicating whether the current request is made via command line
|
||
|
* @param boolean $value the value indicating whether the current request is made via command line
|
||
13 years ago
|
*/
|
||
12 years ago
|
public function setIsConsoleRequest($value)
|
||
13 years ago
|
{
|
||
12 years ago
|
$this->_isConsoleRequest = $value;
|
||
13 years ago
|
}
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Returns entry script file path.
|
||
|
* @return string entry script file path (processed w/ realpath())
|
||
12 years ago
|
* @throws InvalidConfigException if the entry script file path cannot be determined automatically.
|
||
13 years ago
|
*/
|
||
12 years ago
|
public function getScriptFile()
|
||
13 years ago
|
{
|
||
12 years ago
|
if ($this->_scriptFile === null) {
|
||
12 years ago
|
if (isset($_SERVER['SCRIPT_FILENAME'])) {
|
||
|
$this->setScriptFile($_SERVER['SCRIPT_FILENAME']);
|
||
|
} else {
|
||
|
throw new InvalidConfigException('Unable to determine the entry script file path.');
|
||
|
}
|
||
12 years ago
|
}
|
||
|
return $this->_scriptFile;
|
||
13 years ago
|
}
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Sets the entry script file path.
|
||
12 years ago
|
* The entry script file path can normally be determined based on the `SCRIPT_FILENAME` SERVER variable.
|
||
|
* However, for some server configurations, this may not be correct or feasible.
|
||
|
* This setter is provided so that the entry script file path can be manually specified.
|
||
|
* @param string $value the entry script file path. This can be either a file path or a path alias.
|
||
|
* @throws InvalidConfigException if the provided entry script file path is invalid.
|
||
13 years ago
|
*/
|
||
12 years ago
|
public function setScriptFile($value)
|
||
13 years ago
|
{
|
||
12 years ago
|
$scriptFile = realpath(\Yii::getAlias($value));
|
||
|
if ($scriptFile !== false && is_file($scriptFile)) {
|
||
|
$this->_scriptFile = $scriptFile;
|
||
|
} else {
|
||
|
throw new InvalidConfigException('Unable to determine the entry script file path.');
|
||
|
}
|
||
13 years ago
|
}
|
||
|
}
|