Skip to content

Commit

Permalink
Merge pull request #47 from RonasIT/42-drivers-feature
Browse files Browse the repository at this point in the history
fix: remote driver tmp data fix;
  • Loading branch information
DenTray authored May 9, 2022
2 parents 4fa28ca + ca7c388 commit 0d997f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/auto-doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
'remote' => [
'class' => RemoteDriver::class,
'key' => 'project_name',
'url' => 'http://example.com'
'url' => 'https://example.com'
],
'storage' => [
'class' => StorageDriver::class,
Expand Down
25 changes: 16 additions & 9 deletions src/Drivers/RemoteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}";
}
Expand Down

0 comments on commit 0d997f6

Please sign in to comment.