2 namespace TYPO3\CMS\Extbase\Mvc\Controller;
20 use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException;
21 use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchCommandException;
22 use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
23 use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException;
93 $this->arguments = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Controller\Arguments::class);
94 $this->userAuthentication = isset(
$GLOBALS[
'BE_USER']) ?
$GLOBALS[
'BE_USER'] : null;
95 $this->
output = $this->objectManager->get(ConsoleOutput::class);
114 return $request instanceof
Request;
129 throw new UnsupportedRequestTypeException(sprintf(
'%s only supports command line requests – requests of type "%s" given.', get_class($this), get_class($request)), 1300787096);
133 $this->request->setDispatched(
true);
138 $this->mapRequestArgumentsToControllerArguments();
139 $this->callCommandMethod();
171 $this->arguments->removeAll();
172 $methodParameters = $this->reflectionService->getMethodParameters(get_class($this), $this->commandMethodName);
174 foreach ($methodParameters as $parameterName => $parameterInfo) {
176 if (isset($parameterInfo[
'type'])) {
177 $dataType = $parameterInfo[
'type'];
178 }
elseif ($parameterInfo[
'array']) {
181 if ($dataType === null) {
182 throw new InvalidArgumentTypeException(sprintf(
'The argument type for parameter $%s of method %s->%s() could not be detected.', $parameterName, get_class($this), $this->commandMethodName), 1306755296);
184 $defaultValue = (isset($parameterInfo[
'defaultValue']) ? $parameterInfo[
'defaultValue'] : null);
185 $this->arguments->addNewArgument($parameterName, $dataType, ($parameterInfo[
'optional'] ===
false), $defaultValue);
194 protected function mapRequestArgumentsToControllerArguments()
197 foreach ($this->arguments as $argument) {
198 $argumentName = $argument->getName();
199 if ($this->request->hasArgument($argumentName)) {
200 $argument->setValue($this->request->getArgument($argumentName));
203 if (!$argument->isRequired()) {
206 $argumentValue = null;
207 $commandArgumentDefinition = $this->objectManager->get(CommandArgumentDefinition::class, $argumentName,
true, null);
208 while ($argumentValue === null) {
209 $argumentValue = $this->
output->ask(sprintf(
'<comment>Please specify the required argument "%s":</comment> ', $commandArgumentDefinition->getDashedName()));
211 $argument->setValue($argumentValue);
227 protected function forward($commandName, $controllerObjectName = null, array
$arguments = array())
229 $this->request->setDispatched(
false);
230 $this->request->setControllerCommandName($commandName);
231 if ($controllerObjectName !== null) {
232 $this->request->setControllerObjectName($controllerObjectName);
236 $this->arguments->removeAll();
249 protected function callCommandMethod()
251 $preparedArguments = array();
253 foreach ($this->arguments as $argument) {
254 $preparedArguments[] = $argument->getValue();
257 $commandResult = call_user_func_array(array($this, $this->commandMethodName), $preparedArguments);
259 if (is_string($commandResult) && $commandResult !==
'') {
260 $this->response->appendContent($commandResult);
261 }
elseif (is_object($commandResult) && method_exists($commandResult,
'__toString')) {
262 $this->response->appendContent((
string)$commandResult);
274 if (!$this->requestAdminPermissions || !$this->userAuthentication || !isset($this->userAuthentication->user[
'admin'])) {
277 $originalRole = $this->userAuthentication->user[
'admin'];
278 $this->userAuthentication->user[
'admin'] = 1;
279 return $originalRole;
289 if ($originalRole !== null) {
290 $this->userAuthentication->user[
'admin'] = $originalRole;
344 protected function quit($exitCode = 0)
346 $this->response->setExitCode($exitCode);
359 $this->response->send();