Based on the output it builds the response object.
Наследование: use trait Webiny\Component\Http\HttpTrait, use trait Webiny\Component\StdLib\ValidatorTrait
Пример #1
0
 public function testGetCallbackResultException()
 {
     $methodData = ['method' => 'testCallbackException', 'cache' => ['ttl' => 0], 'header' => ['cache' => ['expires' => 0], 'status' => ['success' => 200, 'error' => 404, 'errorMessage' => '']]];
     $requestBag = new RequestBag();
     $requestBag->setApi('CacheTest')->setClassData(['class' => 'Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClassCallback', 'version' => '1.0'])->setMethodData($methodData)->setMethodParameters([]);
     $callback = new Callback($requestBag);
     $response = $callback->getCallbackResult()->getOutput();
     $this->assertSame('There has been an error processing the request.', $response['errorReport']['message']);
 }
Пример #2
0
 /**
  * Analyzes the request and tries to match an api method.
  *
  * @param array $classData Class array form compiled cache file.
  *
  * @return CallbackResult
  * @throws RestException
  * @throws \Exception
  */
 private function matchRequest(&$classData)
 {
     if (!is_array($classData)) {
         throw new RestException("Invalid class cache data.");
     }
     // build the request url upon which we will do the matching
     try {
         $url = $this->getUrl();
     } catch (\Exception $e) {
         throw $e;
     }
     // get request method
     $method = $this->getMethod();
     if (!in_array($method, self::$supportedRequestTypes)) {
         throw new RestException('Unsupported request method: "' . $method . '"');
     }
     $callbacks = empty($classData[$method]) ? [] : $classData[$method];
     // match array
     $matchedMethod = ['methodData' => false, 'matchedParameters' => false];
     // validate that we have the ending class name in the url
     $classUrl = PathTransformations::classNameToUrl($this->class, $this->normalize);
     if (strpos($url, '/' . $classUrl . '/') !== false) {
         $matchedMethod = $this->matchMethod($callbacks, $url);
         // if method was not matched
         if (!$matchedMethod['methodData']) {
             // if no method was matched, let's try to match a default method
             $matchedMethod = $this->matchDefaultMethod($callbacks, $url, $classUrl);
         }
     }
     $methodData = isset($matchedMethod['methodData']) ? $matchedMethod['methodData'] : false;
     $matchedParameters = $matchedMethod['matchedParameters'] ? $matchedMethod['matchedParameters'] : [];
     $requestBag = new RequestBag();
     $requestBag->setClassData($classData)->setMethodData($methodData)->setMethodParameters($matchedParameters)->setApi($this->api);
     $callback = new Callback($requestBag);
     return $callback->getCallbackResult();
 }