Skip to content

Commit 0d997f6

Browse files
authored
Merge pull request #47 from RonasIT/42-drivers-feature
fix: remote driver tmp data fix;
2 parents 4fa28ca + ca7c388 commit 0d997f6

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

config/auto-doc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
'remote' => [
103103
'class' => RemoteDriver::class,
104104
'key' => 'project_name',
105-
'url' => 'http://example.com'
105+
'url' => 'https://example.com'
106106
],
107107
'storage' => [
108108
'class' => StorageDriver::class,

src/Drivers/RemoteDriver.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,46 @@ class RemoteDriver implements SwaggerDriverInterface
99
{
1010
protected $key;
1111
protected $remoteUrl;
12-
13-
protected static $data;
12+
protected $tempFileName;
1413

1514
public function __construct()
1615
{
1716
$this->key = config('auto-doc.drivers.remote.key');
1817
$this->remoteUrl = config('auto-doc.drivers.remote.url');
18+
$this->tempFileName = storage_path('temp_documentation.json');
1919
}
2020

21-
public function saveTmpData($tempData)
21+
public function saveTmpData($data)
2222
{
23-
self::$data = $tempData;
23+
file_put_contents($this->tempFileName, json_encode($data));
2424
}
2525

2626
public function getTmpData()
2727
{
28-
return self::$data;
28+
if (file_exists($this->tempFileName)) {
29+
$content = file_get_contents($this->tempFileName);
30+
31+
return json_decode($content, true);
32+
}
33+
34+
return null;
2935
}
3036

3137
public function saveData()
3238
{
3339
$curl = curl_init();
3440

35-
curl_setopt($curl, CURLOPT_URL,$this->getUrl());
41+
curl_setopt($curl, CURLOPT_URL, $this->getUrl());
3642
curl_setopt($curl, CURLOPT_POST, true);
3743
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->getTmpData()));
3844
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
3945

4046
curl_exec($curl);
41-
4247
curl_close($curl);
4348

44-
self::$data = [];
49+
if (file_exists($this->tempFileName)) {
50+
unlink($this->tempFileName);
51+
}
4552
}
4653

4754
public function getDocumentation(): stdClass
@@ -55,7 +62,7 @@ public function getDocumentation(): stdClass
5562
return json_decode($content);
5663
}
5764

58-
protected function getUrl()
65+
protected function getUrl(): string
5966
{
6067
return "{$this->remoteUrl}/documentations/{$this->key}";
6168
}

0 commit comments

Comments
 (0)