[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / Cli / Request.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc\Cli;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Represents a CLI request.
18 *
19 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
20 * @api
21 */
22 class Request implements \TYPO3\CMS\Extbase\Mvc\RequestInterface {
23
24 /**
25 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
26 * @inject
27 */
28 protected $objectManager;
29
30 /**
31 * @var string
32 */
33 protected $controllerObjectName;
34
35 /**
36 * @var string
37 */
38 protected $controllerCommandName = 'default';
39
40 /**
41 * @var string Name of the extension which is supposed to handle this request.
42 */
43 protected $controllerExtensionName = NULL;
44
45 /**
46 * The arguments for this request
47 *
48 * @var array
49 */
50 protected $arguments = array();
51
52 /**
53 * @var array
54 */
55 protected $exceedingArguments = array();
56
57 /**
58 * If this request has been changed and needs to be dispatched again
59 *
60 * @var bool
61 */
62 protected $dispatched = FALSE;
63
64 /**
65 * @var array
66 */
67 protected $commandLineArguments;
68
69 /**
70 * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command | NULL
71 */
72 protected $command = NULL;
73
74 /**
75 * @var string
76 */
77 protected $callingScript;
78
79 /**
80 * @param string $callingScript
81 */
82 public function setCallingScript($callingScript) {
83 $this->callingScript = $callingScript;
84 }
85
86 /**
87 * @return string
88 */
89 public function getCallingScript() {
90 return $this->callingScript;
91 }
92
93 /**
94 * Sets the dispatched flag
95 *
96 * @param bool $flag If this request has been dispatched
97 * @return void
98 */
99 public function setDispatched($flag) {
100 $this->dispatched = $flag ? TRUE : FALSE;
101 }
102
103 /**
104 * If this request has been dispatched and addressed by the responsible
105 * controller and the response is ready to be sent.
106 *
107 * The dispatcher will try to dispatch the request again if it has not been
108 * addressed yet.
109 *
110 * @return bool TRUE if this request has been disptached successfully
111 */
112 public function isDispatched() {
113 return $this->dispatched;
114 }
115
116 /**
117 * Sets the object name of the controller
118 *
119 * @param string $controllerObjectName The fully qualified controller object name
120 * @return void
121 */
122 public function setControllerObjectName($controllerObjectName) {
123 $nameParts = \TYPO3\CMS\Core\Utility\ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
124
125 $this->controllerExtensionName = $nameParts['extensionName'];
126 $this->controllerObjectName = $controllerObjectName;
127 $this->command = NULL;
128 }
129
130 /**
131 * Returns the object name of the controller
132 *
133 * @return string The controller's object name
134 */
135 public function getControllerObjectName() {
136 return $this->controllerObjectName;
137 }
138
139 /**
140 * Returns the extension name of the specified controller.
141 *
142 * @return string The extension name
143 */
144 public function getControllerExtensionName() {
145 return $this->controllerExtensionName;
146 }
147
148 /**
149 * Sets the name of the command contained in this request.
150 *
151 * Note that the command name must start with a lower case letter and is case sensitive.
152 *
153 * @param string $commandName Name of the command to execute by the controller
154 * @return void
155 */
156 public function setControllerCommandName($commandName) {
157 $this->controllerCommandName = $commandName;
158 $this->command = NULL;
159 }
160
161 /**
162 * Returns the name of the command the controller is supposed to execute.
163 *
164 * @return string Command name
165 */
166 public function getControllerCommandName() {
167 return $this->controllerCommandName;
168 }
169
170 /**
171 * Returns the command object for this request
172 *
173 * @return \TYPO3\CMS\Extbase\Mvc\Cli\Command
174 */
175 public function getCommand() {
176 if ($this->command === NULL) {
177 $this->command = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, $this->controllerObjectName, $this->controllerCommandName);
178 }
179 return $this->command;
180 }
181
182 /**
183 * Sets the value of the specified argument
184 *
185 * @param string $argumentName Name of the argument to set
186 * @param mixed $value The new value
187 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
188 * @return void
189 */
190 public function setArgument($argumentName, $value) {
191 if (!is_string($argumentName) || $argumentName === '') {
192 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException('Invalid argument name.', 1300893885);
193 }
194 $this->arguments[$argumentName] = $value;
195 }
196
197 /**
198 * Sets the whole arguments ArrayObject and therefore replaces any arguments
199 * which existed before.
200 *
201 * @param array $arguments An array of argument names and their values
202 * @return void
203 */
204 public function setArguments(array $arguments) {
205 $this->arguments = $arguments;
206 }
207
208 /**
209 * Returns the value of the specified argument
210 *
211 * @param string $argumentName Name of the argument
212 * @return string Value of the argument
213 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException if such an argument does not exist
214 */
215 public function getArgument($argumentName) {
216 if (!isset($this->arguments[$argumentName])) {
217 throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException('An argument "' . $argumentName . '" does not exist for this request.', 1300893886);
218 }
219 return $this->arguments[$argumentName];
220 }
221
222 /**
223 * Checks if an argument of the given name exists (is set)
224 *
225 * @param string $argumentName Name of the argument to check
226 * @return bool TRUE if the argument is set, otherwise FALSE
227 */
228 public function hasArgument($argumentName) {
229 return isset($this->arguments[$argumentName]);
230 }
231
232 /**
233 * Returns an ArrayObject of arguments and their values
234 *
235 * @return array Array of arguments and their values (which may be arguments and values as well)
236 */
237 public function getArguments() {
238 return $this->arguments;
239 }
240
241 /**
242 * Sets the exceeding arguments
243 *
244 * @param array $exceedingArguments Numeric array of exceeding arguments
245 * @return void
246 */
247 public function setExceedingArguments(array $exceedingArguments) {
248 $this->exceedingArguments = $exceedingArguments;
249 }
250
251 /**
252 * Returns additional unnamed arguments (if any) which have been passed through the command line after all
253 * required arguments (if any) have been specified.
254 *
255 * For a command method with the signature ($argument1, $argument2) and for the command line
256 * cli_dispatch.phpsh extbase some-key someaction acme:foo --argument1 Foo --argument2 Bar baz quux
257 * this method would return array(0 => 'baz', 1 => 'quux')
258 *
259 * @return array Numeric array of exceeding argument values
260 */
261 public function getExceedingArguments() {
262 return $this->exceedingArguments;
263 }
264 }