Пример #1
0
 /**
  * @expectedException \RuntimeException
  */
 public function testGetConnectionInvalid()
 {
     $repository = $this->getActionRepository();
     $factory = $this->getActionFactory();
     $processor = new Processor($repository, $factory);
     $processor->execute(2, $this->getRequest(), $this->getContext());
 }
Пример #2
0
 private function executeAction($record)
 {
     $method = $this->getActiveMethod();
     $context = new EngineContext($this->context->get('fusio.routeId'), $this->app, $this->user);
     $request = new Request($this->request, $this->uriFragments, $this->getParameters(), $record);
     $response = null;
     $actionId = $method['action'];
     if ($actionId > 0) {
         if ($method['status'] != Resource::STATUS_DEVELOPMENT) {
             // if the method is not in dev mode we load the action from the
             // cache
             $repository = unserialize($method['actionCache']);
             if ($repository instanceof Repository\ActionInterface) {
                 $this->processor->push($repository);
                 try {
                     $response = $this->processor->execute($actionId, $request, $context);
                 } catch (\Exception $e) {
                     $this->apiLogger->appendError($this->logId, $e);
                     throw $e;
                 }
                 $this->processor->pop();
             } else {
                 throw new StatusCode\ServiceUnavailableException('Invalid action cache');
             }
         } else {
             // if the action is in dev mode we load the values direct from
             // the table
             try {
                 $response = $this->processor->execute($actionId, $request, $context);
             } catch (\Exception $e) {
                 $this->apiLogger->appendError($this->logId, $e);
                 throw $e;
             }
         }
     } else {
         throw new StatusCode\ServiceUnavailableException('No action provided');
     }
     if ($response instanceof ResponseInterface) {
         $statusCode = $response->getStatusCode();
         $headers = $response->getHeaders();
         if (!empty($statusCode)) {
             $this->setResponseCode($statusCode);
         }
         if (!empty($headers)) {
             foreach ($headers as $name => $value) {
                 $this->setHeader($name, $value);
             }
         }
         return $response->getBody();
     } else {
         throw new StatusCode\InternalServerErrorException('Invalid action response');
     }
 }