From ca7c3881c2a146fbb8ba9ab4fdcd4740506a14a2 Mon Sep 17 00:00:00 2001 From: dpankratov Date: Mon, 9 May 2022 10:11:07 +0600 Subject: [PATCH] fix: remote driver tmp data fix; - saving tmp data to the local file instead of protected class field; - code reformat; - remove tmp file after pushing; --- config/auto-doc.php | 2 +- src/Drivers/RemoteDriver.php | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/config/auto-doc.php b/config/auto-doc.php index 5daf8e01..0d33f099 100644 --- a/config/auto-doc.php +++ b/config/auto-doc.php @@ -102,7 +102,7 @@ 'remote' => [ 'class' => RemoteDriver::class, 'key' => 'project_name', - 'url' => 'http://example.com' + 'url' => 'https://example.com' ], 'storage' => [ 'class' => StorageDriver::class, diff --git a/src/Drivers/RemoteDriver.php b/src/Drivers/RemoteDriver.php index 30944ac2..5ad91bb3 100755 --- a/src/Drivers/RemoteDriver.php +++ b/src/Drivers/RemoteDriver.php @@ -9,39 +9,46 @@ class RemoteDriver implements SwaggerDriverInterface { protected $key; protected $remoteUrl; - - protected static $data; + protected $tempFileName; public function __construct() { $this->key = config('auto-doc.drivers.remote.key'); $this->remoteUrl = config('auto-doc.drivers.remote.url'); + $this->tempFileName = storage_path('temp_documentation.json'); } - public function saveTmpData($tempData) + public function saveTmpData($data) { - self::$data = $tempData; + file_put_contents($this->tempFileName, json_encode($data)); } public function getTmpData() { - return self::$data; + if (file_exists($this->tempFileName)) { + $content = file_get_contents($this->tempFileName); + + return json_decode($content, true); + } + + return null; } public function saveData() { $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL,$this->getUrl()); + curl_setopt($curl, CURLOPT_URL, $this->getUrl()); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->getTmpData())); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_exec($curl); - curl_close($curl); - self::$data = []; + if (file_exists($this->tempFileName)) { + unlink($this->tempFileName); + } } public function getDocumentation(): stdClass @@ -55,7 +62,7 @@ public function getDocumentation(): stdClass return json_decode($content); } - protected function getUrl() + protected function getUrl(): string { return "{$this->remoteUrl}/documentations/{$this->key}"; }