58 public function build($commandLine =
'', $callingScript =
'./typo3/cli_dispatch.phpsh extbase') {
59 $request = $this->objectManager->get(
'TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Request');
60 $request->setCallingScript($callingScript);
61 $request->setControllerObjectName(
'TYPO3\\CMS\\Extbase\\Command\\HelpCommandController');
62 $rawCommandLineArguments = is_array($commandLine) ? $commandLine : explode(
' ', $commandLine);
63 if (count($rawCommandLineArguments) === 0) {
64 $request->setControllerCommandName(
'helpStub');
67 $commandIdentifier = trim(array_shift($rawCommandLineArguments));
69 $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
70 $this->configurationManager->setConfiguration(array(
'extensionName' => $command->getExtensionName()));
71 }
catch (\
TYPO3\CMS\Extbase\Mvc\
Exception\CommandException $exception) {
72 $request->setArgument(
'exception', $exception);
73 $request->setControllerCommandName(
'error');
76 $controllerObjectName = $command->getControllerClassName();
77 $controllerCommandName = $command->getControllerCommandName();
78 $request->setControllerObjectName($controllerObjectName);
79 $request->setControllerCommandName($controllerCommandName);
80 list($commandLineArguments, $exceedingCommandLineArguments) = $this->
parseRawCommandLineArguments($rawCommandLineArguments, $controllerObjectName, $controllerCommandName);
81 $request->setArguments($commandLineArguments);
82 $request->setExceedingArguments($exceedingCommandLineArguments);
97 $commandLineArguments = array();
98 $exceedingArguments = array();
99 $commandMethodName = $controllerCommandName .
'Command';
100 $commandMethodParameters = $this->reflectionService->getMethodParameters($controllerObjectName, $commandMethodName);
101 $requiredArguments = array();
102 $optionalArguments = array();
103 $argumentNames = array();
104 foreach ($commandMethodParameters as $parameterName => $parameterInfo) {
105 $argumentNames[] = $parameterName;
106 if ($parameterInfo[
'optional'] === FALSE) {
107 $requiredArguments[strtolower($parameterName)] = array(
'parameterName' => $parameterName,
'type' => $parameterInfo[
'type']);
109 $optionalArguments[strtolower($parameterName)] = array(
'parameterName' => $parameterName,
'type' => $parameterInfo[
'type']);
112 $decidedToUseNamedArguments = FALSE;
113 $decidedToUseUnnamedArguments = FALSE;
115 while (count($rawCommandLineArguments) > 0) {
116 $rawArgument = array_shift($rawCommandLineArguments);
117 if ($rawArgument[0] ===
'-') {
118 if ($rawArgument[1] ===
'-') {
119 $rawArgument = substr($rawArgument, 2);
121 $rawArgument = substr($rawArgument, 1);
124 if (isset($optionalArguments[$argumentName])) {
126 $commandLineArguments[$optionalArguments[$argumentName][
'parameterName']] = $argumentValue;
127 } elseif (isset($requiredArguments[$argumentName])) {
128 if ($decidedToUseUnnamedArguments) {
129 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);
131 $decidedToUseNamedArguments = TRUE;
133 $commandLineArguments[$requiredArguments[$argumentName][
'parameterName']] = $argumentValue;
134 unset($requiredArguments[$argumentName]);
137 if (count($requiredArguments) > 0) {
138 if ($decidedToUseNamedArguments) {
139 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);
141 $argument = array_shift($requiredArguments);
142 $commandLineArguments[$argument[
'parameterName']] = $rawArgument;
143 $decidedToUseUnnamedArguments = TRUE;
145 if ($argumentIndex < count($argumentNames)) {
146 $commandLineArguments[$argumentNames[$argumentIndex]] = $rawArgument;
148 $exceedingArguments[] = $rawArgument;
154 return array($commandLineArguments, $exceedingArguments);
164 $nameAndValue = explode(
'=', $commandLinePart, 2);
165 return strtolower(str_replace(
'-',
'', $nameAndValue[0]));
177 if (!isset($rawCommandLineArguments[0]) && strpos($currentArgument,
'=') === FALSE || isset($rawCommandLineArguments[0]) && $rawCommandLineArguments[0][0] ===
'-' && strpos($currentArgument,
'=') === FALSE) {
180 if (strpos($currentArgument,
'=') === FALSE) {
181 $possibleValue = trim(array_shift($rawCommandLineArguments));
182 if (strpos($possibleValue,
'=') === FALSE) {
183 if ($expectedArgumentType !==
'boolean') {
184 return $possibleValue;
186 if (array_search($possibleValue, array(
'on',
'1',
'y',
'yes',
'true',
'TRUE')) !== FALSE) {
189 if (array_search($possibleValue, array(
'off',
'0',
'n',
'no',
'false',
'FALSE')) !== FALSE) {
192 array_unshift($rawCommandLineArguments, $possibleValue);
195 $currentArgument .= $possibleValue;
197 $splitArgument = explode(
'=', $currentArgument, 2);
198 while ((!isset($splitArgument[1]) || trim($splitArgument[1]) ===
'') && count($rawCommandLineArguments) > 0) {
199 $currentArgument .= array_shift($rawCommandLineArguments);
200 $splitArgument = explode(
'=', $currentArgument);
202 $value = isset($splitArgument[1]) ? $splitArgument[1] :
'';
parseRawCommandLineArguments(array $rawCommandLineArguments, $controllerObjectName, $controllerCommandName)
extractArgumentNameFromCommandLinePart($commandLinePart)
getValueOfCurrentCommandLineOption($currentArgument, array &$rawCommandLineArguments, $expectedArgumentType)
build($commandLine='', $callingScript='./typo3/cli_dispatch.phpsh extbase')