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 string $hostname
  * @param boolean $useHttps
  * @param Request $request
  * @return Response
  */
 public function dispatchOutgoingRequest($hostname, $useHttps, Request $request)
 {
     $compiledRequest = $request->compile();
     $targetUrl = 'http' . (!$useHttps ? '' : 's') . '://' . $hostname . '/?type=991';
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $targetUrl);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $compiledRequest);
     curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
     $responseBody = curl_exec($curl);
     if (empty($responseBody)) {
         throw new \RuntimeException('Received an empty response from the server. Is the server RPC-enabled?');
     }
     $decodedJson = json_decode($responseBody, JSON_OBJECT_AS_ARRAY);
     if (empty($decodedJson)) {
         throw new \RuntimeException('The server yielded a response but the response was not JSON. Is the server RPC-enabled?');
     }
     $response = new Response();
     $response->fillFromJsonData($decodedJson);
     return $response;
 }
Example #4
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 #5
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;
 }