Total Complexity | 9 |
Total Lines | 63 |
Duplicated Lines | 0 % |
Coverage | 56.25% |
Changes | 0 |
1 | <?php |
||
23 | abstract class Request extends Component |
||
24 | { |
||
25 | private $_scriptFile; |
||
26 | private $_isConsoleRequest; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * Resolves the current request into a route and the associated parameters. |
||
31 | * @return array the first element is the route, and the second is the associated parameters. |
||
32 | */ |
||
33 | abstract public function resolve(); |
||
34 | |||
35 | /** |
||
36 | * Returns a value indicating whether the current request is made via command line. |
||
37 | * @return bool the value indicating whether the current request is made via console |
||
38 | */ |
||
39 | public function getIsConsoleRequest() |
||
40 | { |
||
41 | return $this->_isConsoleRequest !== null ? $this->_isConsoleRequest : PHP_SAPI === 'cli'; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Sets the value indicating whether the current request is made via command line. |
||
46 | * @param bool $value the value indicating whether the current request is made via command line |
||
47 | */ |
||
48 | public function setIsConsoleRequest($value) |
||
49 | { |
||
50 | $this->_isConsoleRequest = $value; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Returns entry script file path. |
||
55 | * @return string entry script file path (processed w/ realpath()) |
||
56 | * @throws InvalidConfigException if the entry script file path cannot be determined automatically. |
||
57 | */ |
||
58 | 4 | public function getScriptFile() |
|
59 | { |
||
60 | 4 | if ($this->_scriptFile === null) { |
|
61 | 4 | if (isset($_SERVER['SCRIPT_FILENAME'])) { |
|
62 | 4 | $this->setScriptFile($_SERVER['SCRIPT_FILENAME']); |
|
63 | } else { |
||
64 | throw new InvalidConfigException('Unable to determine the entry script file path.'); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | 4 | return $this->_scriptFile; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Sets the entry script file path. |
||
73 | * The entry script file path can normally be determined based on the `SCRIPT_FILENAME` SERVER variable. |
||
74 | * However, for some server configurations, this may not be correct or feasible. |
||
75 | * This setter is provided so that the entry script file path can be manually specified. |
||
76 | * @param string $value the entry script file path. This can be either a file path or a [path alias](guide:concept-aliases). |
||
77 | * @throws InvalidConfigException if the provided entry script file path is invalid. |
||
78 | */ |
||
79 | 4 | public function setScriptFile($value) |
|
86 | } |
||
87 | 4 | } |
|
88 | } |
||
89 |