/** * Forwards the request to another command and / or CommandController. * * Request is directly transferred to the other command / controller * without the need for a new request. * * @param string $commandName * @param string $controllerObjectName * @param array $arguments * @return void * @throws StopActionException */ protected function forward($commandName, $controllerObjectName = null, array $arguments = array()) { $this->request->setDispatched(false); $this->request->setControllerCommandName($commandName); if ($controllerObjectName !== null) { $this->request->setControllerObjectName($controllerObjectName); } $this->request->setArguments($arguments); $this->arguments->removeAll(); throw new StopActionException(); }
/** * Builds a CLI request object from a command line. * * The given command line may be a string (e.g. "mypackage:foo do-that-thing --force") or * an array consisting of the individual parts. The array must not include the script * name (like in $argv) but start with command right away. * * @param mixed $commandLine The command line, either as a string or as an array * @return \TYPO3\Flow\Cli\Request The CLI request as an object */ public function build($commandLine) { $request = new Request(); $request->setControllerObjectName('TYPO3\\Flow\\Command\\HelpCommandController'); $rawCommandLineArguments = is_array($commandLine) ? $commandLine : explode(' ', $commandLine); if (count($rawCommandLineArguments) === 0) { $request->setControllerCommandName('helpStub'); return $request; } $commandIdentifier = trim(array_shift($rawCommandLineArguments)); try { $command = $this->commandManager->getCommandByIdentifier($commandIdentifier); } catch (\TYPO3\Flow\Mvc\Exception\CommandException $exception) { $request->setArgument('exception', $exception); $request->setControllerCommandName('error'); return $request; } $controllerObjectName = $this->objectManager->getObjectNameByClassName($command->getControllerClassName()); $controllerCommandName = $command->getControllerCommandName(); $request->setControllerObjectName($controllerObjectName); $request->setControllerCommandName($controllerCommandName); list($commandLineArguments, $exceedingCommandLineArguments) = $this->parseRawCommandLineArguments($rawCommandLineArguments, $controllerObjectName, $controllerCommandName); $request->setArguments($commandLineArguments); $request->setExceedingArguments($exceedingCommandLineArguments); return $request; }
/** * Builds a CLI request object from a command line. * * The given command line may be a string (e.g. "mypackage:foo do-that-thing --force") or * an array consisting of the individual parts. The array must not include the script * name (like in $argv) but start with command right away. * * @param mixed $commandLine The command line, either as a string or as an array * @return Request The CLI request as an object * @throws InvalidArgumentMixingException * @throws InvalidArgumentNameException */ public function build($commandLine) { $request = new Request(); $request->setControllerObjectName(HelpCommandController::class); if (is_array($commandLine) === true) { $rawCommandLineArguments = $commandLine; } else { preg_match_all(self::ARGUMENT_MATCHING_EXPRESSION, $commandLine, $commandLineMatchings, PREG_SET_ORDER); $rawCommandLineArguments = []; foreach ($commandLineMatchings as $match) { if (isset($match['NoQuotes'])) { $rawCommandLineArguments[] = str_replace(['\\ ', '\\"', "\\'", '\\\\'], [' ', '"', "'", '\\'], $match['NoQuotes']); } elseif (isset($match['DoubleQuotes'])) { $rawCommandLineArguments[] = str_replace('\\"', '"', $match['DoubleQuotes']); } elseif (isset($match['SingleQuotes'])) { $rawCommandLineArguments[] = str_replace('\\\'', '\'', $match['SingleQuotes']); } else { throw new InvalidArgumentNameException(sprintf('Could not parse the command line "%s" - specifically the part "%s".', $commandLine, $match[0])); } } } if (count($rawCommandLineArguments) === 0) { $request->setControllerCommandName('helpStub'); return $request; } $commandIdentifier = trim(array_shift($rawCommandLineArguments)); try { $command = $this->commandManager->getCommandByIdentifier($commandIdentifier); } catch (CommandException $exception) { $request->setArgument('exception', $exception); $request->setControllerCommandName('error'); return $request; } $controllerObjectName = $this->objectManager->getObjectNameByClassName($command->getControllerClassName()); $controllerCommandName = $command->getControllerCommandName(); $request->setControllerObjectName($controllerObjectName); $request->setControllerCommandName($controllerCommandName); list($commandLineArguments, $exceedingCommandLineArguments) = $this->parseRawCommandLineArguments($rawCommandLineArguments, $controllerObjectName, $controllerCommandName); $request->setArguments($commandLineArguments); $request->setExceedingArguments($exceedingCommandLineArguments); return $request; }
/** * Set a new password for the given user * * @param string $username user to modify * @param string $password new password * @param string $authenticationProvider Name of the authentication provider to use for finding the user. Default: "Sandstorm.UserManagement:Login". * @return void */ public function setPasswordCommand($username, $password, $authenticationProvider = 'Sandstorm.UserManagement:Login') { // If we're in Neos context, we simply forward the command to the Neos command controller. if ($this->shouldUseNeosService()) { $cliRequest = new Request($this->request); $cliRequest->setControllerObjectName(UserCommandController::class); $cliRequest->setControllerCommandName('setPassword'); $cliRequest->setArguments(['username' => $username, 'password' => $password, 'authenticationProvider' => $authenticationProvider]); $cliResponse = new Response($this->response); $this->dispatcher->dispatch($cliRequest, $cliResponse); $this->quit(0); } // Otherwise, we use our own logic. $account = $this->accountRepository->findByAccountIdentifierAndAuthenticationProviderName($username, $authenticationProvider); if ($account === null) { $this->outputLine('The user <b>' . $username . '</b> could not be found with auth provider <b>' . $authenticationProvider . '</b>.'); $this->quit(1); } $encrypted = $this->hashService->hashPassword($password); $account->setCredentialsSource($encrypted); $this->accountRepository->update($account); $this->outputLine('Password for user <b>' . $username . '</b> changed.'); }