Request.php 1.62 KB
Newer Older
Qiang Xue committed
1 2 3 4 5
<?php
/**
 * Request class file.
 *
 * @link http://www.yiiframework.com/
Qiang Xue committed
6
 * @copyright Copyright &copy; 2008 Yii Software LLC
Qiang Xue committed
7 8 9 10 11 12 13 14 15
 * @license http://www.yiiframework.com/license/
 */

namespace yii\base;

/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
16
class Request extends Component
Qiang Xue committed
17 18
{
	private $_scriptFile;
Qiang Xue committed
19
	private $_isConsoleRequest;
Qiang Xue committed
20 21

	/**
Qiang Xue committed
22 23
	 * 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
Qiang Xue committed
24
	 */
Qiang Xue committed
25
	public function getIsConsoleRequest()
Qiang Xue committed
26
	{
Qiang Xue committed
27
		return $this->_isConsoleRequest !== null ? $this->_isConsoleRequest : PHP_SAPI === 'cli';
Qiang Xue committed
28 29 30
	}

	/**
Qiang Xue committed
31 32
	 * 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
Qiang Xue committed
33
	 */
Qiang Xue committed
34
	public function setIsConsoleRequest($value)
Qiang Xue committed
35
	{
Qiang Xue committed
36
		$this->_isConsoleRequest = $value;
Qiang Xue committed
37 38 39
	}

	/**
Qiang Xue committed
40 41
	 * Returns entry script file path.
	 * @return string entry script file path (processed w/ realpath())
Qiang Xue committed
42
	 */
Qiang Xue committed
43
	public function getScriptFile()
Qiang Xue committed
44
	{
Qiang Xue committed
45 46 47 48
		if ($this->_scriptFile === null) {
			$this->_scriptFile = realpath($_SERVER['SCRIPT_FILENAME']);
		}
		return $this->_scriptFile;
Qiang Xue committed
49 50 51
	}

	/**
Qiang Xue committed
52 53 54 55 56
	 * Sets the entry script file path.
	 * This can be an absolute or relative file path, or a path alias.
	 * Note that you normally do not have to set the script file path
	 * as [[getScriptFile()]] can determine it based on `$_SERVER['SCRIPT_FILENAME']`.
	 * @param string $value the entry script file
Qiang Xue committed
57
	 */
Qiang Xue committed
58
	public function setScriptFile($value)
Qiang Xue committed
59
	{
Qiang Xue committed
60
		$this->_scriptFile = realpath(\Yii::getAlias($value));
Qiang Xue committed
61 62
	}
}