2 namespace TYPO3\CMS\Extbase\Mvc\Cli;
87 public function build($commandLine =
'', $callingScript =
'./typo3/cli_dispatch.phpsh extbase')
89 $request = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Request::class);
90 $request->setCallingScript($callingScript);
91 $request->setControllerObjectName(\TYPO3\CMS\Extbase\
Command\HelpCommandController::class);
92 $rawCommandLineArguments = is_array($commandLine) ? $commandLine : explode(
' ', $commandLine);
93 if (empty($rawCommandLineArguments)) {
94 $request->setControllerCommandName(
'helpStub');
97 $commandIdentifier = trim(array_shift($rawCommandLineArguments));
99 $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
100 $this->configurationManager->setConfiguration(array(
'extensionName' => $command->getExtensionName()));
101 }
catch (\TYPO3\CMS\Extbase\Mvc\
Exception\CommandException $exception) {
102 $request->setArgument(
'exception', $exception);
103 $request->setControllerCommandName(
'error');
106 $controllerObjectName = $command->getControllerClassName();
107 $controllerCommandName = $command->getControllerCommandName();
108 $request->setControllerObjectName($controllerObjectName);
109 $request->setControllerCommandName($controllerCommandName);
110 list($commandLineArguments, $exceedingCommandLineArguments) = $this->
parseRawCommandLineArguments($rawCommandLineArguments, $controllerObjectName, $controllerCommandName);
111 $request->setArguments($commandLineArguments);
112 $request->setExceedingArguments($exceedingCommandLineArguments);
128 $commandLineArguments = array();
129 $exceedingArguments = array();
130 $commandMethodName = $controllerCommandName .
'Command';
131 $commandMethodParameters = $this->reflectionService->getMethodParameters($controllerObjectName, $commandMethodName);
132 $requiredArguments = array();
133 $optionalArguments = array();
134 $argumentNames = array();
135 foreach ($commandMethodParameters as $parameterName => $parameterInfo) {
136 $argumentNames[] = $parameterName;
137 if ($parameterInfo[
'optional'] ===
false) {
138 $requiredArguments[strtolower($parameterName)] = array(
'parameterName' => $parameterName,
'type' => $parameterInfo[
'type']);
140 $optionalArguments[strtolower($parameterName)] = array(
'parameterName' => $parameterName,
'type' => $parameterInfo[
'type']);
143 $decidedToUseNamedArguments =
false;
144 $decidedToUseUnnamedArguments =
false;
146 while (!empty($rawCommandLineArguments)) {
147 $rawArgument = array_shift($rawCommandLineArguments);
148 if ($rawArgument[0] ===
'-') {
149 if ($rawArgument[1] ===
'-') {
150 $rawArgument = substr($rawArgument, 2);
152 $rawArgument = substr($rawArgument, 1);
155 if (isset($optionalArguments[$argumentName])) {
157 $commandLineArguments[$optionalArguments[$argumentName][
'parameterName']] = $argumentValue;
158 }
elseif (isset($requiredArguments[$argumentName])) {
159 if ($decidedToUseUnnamedArguments) {
160 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentMixingException(sprintf(
'Unexpected named argument "%s". If you use unnamed arguments, all required arguments must be passed without a name.', $argumentName), 1309971821);
162 $decidedToUseNamedArguments =
true;
164 $commandLineArguments[$requiredArguments[$argumentName][
'parameterName']] = $argumentValue;
165 unset($requiredArguments[$argumentName]);
168 if (!empty($requiredArguments)) {
169 if ($decidedToUseNamedArguments) {
170 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentMixingException(sprintf(
'Unexpected unnamed argument "%s". If you use named arguments, all required arguments must be passed named.', $rawArgument), 1309971820);
172 $argument = array_shift($requiredArguments);
173 $commandLineArguments[$argument[
'parameterName']] = $rawArgument;
174 $decidedToUseUnnamedArguments =
true;
176 if ($argumentIndex < count($argumentNames)) {
177 $commandLineArguments[$argumentNames[$argumentIndex]] = $rawArgument;
179 $exceedingArguments[] = $rawArgument;
185 return array($commandLineArguments, $exceedingArguments);
196 $nameAndValue = explode(
'=', $commandLinePart, 2);
197 return strtolower(str_replace(
'-',
'', $nameAndValue[0]));
210 if (!isset($rawCommandLineArguments[0]) && strpos($currentArgument,
'=') ===
false || isset($rawCommandLineArguments[0]) && $rawCommandLineArguments[0][0] ===
'-' && strpos($currentArgument,
'=') ===
false) {
213 if (strpos($currentArgument,
'=') ===
false) {
214 $possibleValue = trim(array_shift($rawCommandLineArguments));
215 if (strpos($possibleValue,
'=') ===
false) {
216 if ($expectedArgumentType !==
'boolean') {
217 return $possibleValue;
219 if (array_search($possibleValue, array(
'on',
'1',
'y',
'yes',
'true',
'TRUE')) !==
false) {
222 if (array_search($possibleValue, array(
'off',
'0',
'n',
'no',
'false',
'FALSE')) !==
false) {
225 array_unshift($rawCommandLineArguments, $possibleValue);
228 $currentArgument .= $possibleValue;
230 $splitArgument = explode(
'=', $currentArgument, 2);
231 while ((!isset($splitArgument[1]) || trim($splitArgument[1]) ===
'') && !empty($rawCommandLineArguments)) {
232 $currentArgument .= array_shift($rawCommandLineArguments);
233 $splitArgument = explode(
'=', $currentArgument);
235 $value = isset($splitArgument[1]) ? $splitArgument[1] :
'';