Example #1
0
 /**
  * @param Request $request
  * @return Response
  */
 public function processRequest(Request $request)
 {
     $taskIds = TaskManager::getInstance()->getTaskIdsByToken($request->getToken());
     $taskDescriptions = array_map(array($this, 'getDescriptionForTask'), $taskIds);
     $response = new Response();
     $response->setPayload(array_combine($taskIds, $taskDescriptions));
     $response->setReport(new SuccessReport('Tasks', 'Select task from list'));
     return $response;
 }
Example #2
0
 /**
  * @param Request $request
  * @return Response
  */
 public function processRequest(Request $request)
 {
     list($controllerClassName, $actionName) = explode('->', $request->getTask());
     /** @var ControllerInterface $controller */
     $controller = GeneralUtility::makeInstance(ObjectManager::class)->get($controllerClassName);
     $methodName = $actionName . 'Command';
     $response = new Response();
     $response->getReport()->setTitle('Enter command arguments')->setContent('Fill in the arguments to execute');
     $expectedCommandArguments = $this->getExpectedArgumentsForMethod($controller, $methodName);
     $commandArguments = $this->buildArgumentArray($controller, $methodName, $request->getArguments());
     foreach ($expectedCommandArguments as $expectedCommandArgument) {
         $expectedCommandArgumentName = $expectedCommandArgument->getName();
         list($expectedArgumentType, $expectedArgumentDescription) = $this->parseDocCommentOfArgument($expectedCommandArgument, $expectedCommandArgumentName);
         $fieldType = $this->getFieldForArgumentNameAndType($expectedCommandArgumentName, $expectedArgumentType);
         /** @var FieldInterface $field */
         $field = new $fieldType();
         $field->setName($expectedCommandArgumentName);
         if ($expectedArgumentDescription) {
             $field->setLabel($expectedArgumentDescription);
         } else {
             $field->setLabel('Argument: ' . $expectedCommandArgumentName);
         }
         $response->getSheet()->addField($field);
     }
     if (count($expectedCommandArguments) > count($request->getArguments())) {
         // We lack some arguments - return the response now so the client can fill those values.
         // Present a small report outputting the doc comment
         $methodReflection = new \ReflectionMethod($controller, $methodName);
         $docCommentParser = new DocCommentParser();
         $docCommentParser->parseDocComment($methodReflection->getDocComment());
         $response->setReport(new SuccessReport($this->getTaskConfiguration()->getDescription(), $docCommentParser->getDescription()));
         return $response;
     }
     try {
         $temporaryResponse = new \TYPO3\CMS\Extbase\Mvc\Cli\Response();
         $responseProperty = new \ReflectionProperty($controller, 'response');
         $responseProperty->setAccessible(TRUE);
         $responseProperty->setValue($controller, $temporaryResponse);
         // Catch output of any manual calls to outputLine() or Response->send() from controller action
         ob_start();
         call_user_func_array([$controller, $methodName], array_values($commandArguments));
         $output = ob_get_clean();
         // Append any finish output accumulated in Response; this normally gets output after finishing a Request
         // but we bypass the Request and call the command methods directly - so we need to fetch this output.
         $output .= $temporaryResponse->getContent();
         $response->setPayload($output);
         $response->setReport(new SuccessReport(sprintf('CommandController executed (exit code: %d)', $temporaryResponse->getExitCode()), empty($output) ? 'There was no output from the command' : 'Output is attached as response payload'))->complete();
     } catch (\Exception $error) {
         $response->setReport(new ErrorReport(sprintf('CommandController error (%d)', $error->getCode()), $error->getMessage()));
     }
     return $response;
 }
Example #3
0
 /**
  * @param Request $request
  * @return Response
  */
 public function processRequest(Request $request)
 {
     $response = new Response();
     $response->setReport(new SuccessReport('RPC Help', file_get_contents(__DIR__ . '/../../../CLIENT.md')))->setPayload($this->collectSystemInformation())->complete();
     return $response;
 }
Example #4
0
 /**
  * @param string $title
  * @param string $content
  * @param Request $request
  * @return Response
  */
 protected function createErrorResponse($title, $content, Request $request)
 {
     $errorReport = new ErrorReport($title, $content);
     $response = new Response();
     $response->setReport($errorReport);
     $response->setToken($request->getToken());
     $response->complete();
     return $response;
 }