Example #1
0
 public function onPost()
 {
     try {
         $this->connection->beginTransaction();
         $data = Parser::encode($this->getBody());
         $result = $this->systemImportService->import($data);
         $this->connection->commit();
         $this->setBody(['success' => true, 'message' => 'Import successful', 'result' => $result]);
     } catch (\Exception $e) {
         $this->connection->rollback();
         throw $e;
     }
 }
Example #2
0
 /**
  * @param string $method
  * @param string $path
  * @param array|null $body
  * @return mixed
  */
 public function request($method, $path, $body = null, $verbose = false)
 {
     $header = ['User-Agent' => 'Fusio-System v' . Base::getVersion(), 'Authorization' => 'Bearer ' . $this->getAccessToken()];
     $body = $body !== null ? Parser::encode($body) : null;
     $request = new Request(new Url('http://127.0.0.1/backend/' . $path), $method, $header, $body);
     $response = new Response();
     $response->setBody(new TempStream(fopen('php://memory', 'r+')));
     $this->logger->pushHandler($verbose ? new StreamHandler(STDOUT) : new NullHandler());
     $this->dispatch->route($request, $response, null, false);
     $this->logger->popHandler();
     $body = (string) $response->getBody();
     $data = Parser::decode($body, false);
     return $data;
 }
Example #3
0
 public function install(array $instructions, $basePath = null)
 {
     $data = new stdClass();
     foreach ($instructions as $instruction) {
         if ($instruction instanceof Instruction\Route && $basePath !== null) {
             $instruction->setBasePath($basePath);
         }
         $key = $instruction->getKey();
         $value = $instruction->getPayload();
         if (!isset($data->{$key})) {
             $data->{$key} = [];
         }
         array_push($data->{$key}, $value);
     }
     return $this->importService->import(Parser::encode($data));
 }