|
3 | 3 | namespace RonasIT\Support\AutoDoc\Drivers; |
4 | 4 |
|
5 | 5 | use Illuminate\Contracts\Filesystem\FileNotFoundException; |
6 | | -use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface; |
| 6 | +use RonasIT\Support\AutoDoc\Exceptions\MissedRemoteDocumentationUrlException; |
7 | 7 |
|
8 | | -class RemoteDriver implements SwaggerDriverInterface |
| 8 | +class RemoteDriver extends BaseDriver |
9 | 9 | { |
10 | 10 | protected $key; |
11 | 11 | protected $remoteUrl; |
12 | | - protected $tempFilePath; |
13 | 12 |
|
14 | 13 | public function __construct() |
15 | 14 | { |
16 | 15 | $this->key = config('auto-doc.drivers.remote.key'); |
17 | 16 | $this->remoteUrl = config('auto-doc.drivers.remote.url'); |
18 | 17 | $this->tempFilePath = storage_path('temp_documentation.json'); |
19 | | - } |
20 | | - |
21 | | - public function saveTmpData($data) |
22 | | - { |
23 | | - file_put_contents($this->tempFilePath, json_encode($data)); |
24 | | - } |
25 | 18 |
|
26 | | - public function getTmpData() |
27 | | - { |
28 | | - if (file_exists($this->tempFilePath)) { |
29 | | - $content = file_get_contents($this->tempFilePath); |
30 | | - |
31 | | - return json_decode($content, true); |
| 19 | + if (empty($this->remoteUrl)) { |
| 20 | + throw new MissedRemoteDocumentationUrlException(); |
32 | 21 | } |
33 | | - |
34 | | - return null; |
35 | 22 | } |
36 | 23 |
|
37 | | - public function saveData() |
| 24 | + public function saveData(): void |
38 | 25 | { |
39 | 26 | $this->makeHttpRequest('post', $this->getUrl(), $this->getTmpData(), [ |
40 | 27 | 'Content-Type: application/json' |
@@ -64,7 +51,7 @@ protected function getUrl(): string |
64 | 51 | /** |
65 | 52 | * @codeCoverageIgnore |
66 | 53 | */ |
67 | | - protected function makeHttpRequest($type, $url, $data = [], $headers = []) |
| 54 | + protected function makeHttpRequest($type, $url, $data = [], $headers = []): array |
68 | 55 | { |
69 | 56 | $curl = curl_init(); |
70 | 57 |
|
|
0 commit comments