-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from RonasIT/42-drivers-feature
feat: implement drivers
- Loading branch information
Showing
15 changed files
with
295 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace RonasIT\Support\AutoDoc\Drivers; | ||
|
||
use stdClass; | ||
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface; | ||
|
||
class RemoteDriver implements SwaggerDriverInterface | ||
{ | ||
protected $key; | ||
protected $remoteUrl; | ||
|
||
protected static $data; | ||
|
||
public function __construct() | ||
{ | ||
$this->key = config('auto-doc.drivers.remote.key'); | ||
$this->remoteUrl = config('auto-doc.drivers.remote.url'); | ||
} | ||
|
||
public function saveTmpData($tempData) | ||
{ | ||
self::$data = $tempData; | ||
} | ||
|
||
public function getTmpData() | ||
{ | ||
return self::$data; | ||
} | ||
|
||
public function saveData() | ||
{ | ||
$curl = curl_init(); | ||
|
||
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 = []; | ||
} | ||
|
||
public function getDocumentation(): stdClass | ||
{ | ||
$content = file_get_contents($this->getUrl()); | ||
|
||
if (empty($content)) { | ||
throw new FileNotFoundException(); | ||
} | ||
|
||
return json_decode($content); | ||
} | ||
|
||
protected function getUrl() | ||
{ | ||
return "{$this->remoteUrl}/documentations/{$this->key}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace RonasIT\Support\AutoDoc\Drivers; | ||
|
||
use stdClass; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Contracts\Filesystem\FileNotFoundException; | ||
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface; | ||
|
||
class StorageDriver implements SwaggerDriverInterface | ||
{ | ||
protected $disk; | ||
protected $filePath; | ||
|
||
protected static $data; | ||
|
||
public function __construct() | ||
{ | ||
$this->disk = config('auto-doc.drivers.storage.disk'); | ||
$this->filePath = config('auto-doc.drivers.storage.production_path'); | ||
} | ||
|
||
public function saveTmpData($tempData) | ||
{ | ||
self::$data = $tempData; | ||
} | ||
|
||
public function getTmpData() | ||
{ | ||
return self::$data; | ||
} | ||
|
||
public function saveData() | ||
{ | ||
$content = json_encode(self::$data); | ||
|
||
Storage::disk($this->disk)->put($this->filePath, $content); | ||
|
||
self::$data = []; | ||
} | ||
|
||
public function getDocumentation(): stdClass | ||
{ | ||
if (!Storage::disk($this->disk)->exists($this->filePath)) { | ||
throw new FileNotFoundException(); | ||
} | ||
|
||
$fileContent = Storage::disk($this->disk)->get($this->filePath); | ||
|
||
return json_decode($fileContent); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace RonasIT\Support\AutoDoc\Exceptions; | ||
|
||
use Exception; | ||
|
||
class InvalidDriverClassException extends Exception | ||
{ | ||
public function __construct(string $driver) | ||
{ | ||
parent::__construct("The driver '{$driver}' is not implements the SwaggerDriverInterface."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace RonasIT\Support\AutoDoc\Exceptions; | ||
|
||
use Exception; | ||
|
||
class SwaggerDriverClassNotFoundException extends Exception | ||
{ | ||
public function __construct($className) | ||
{ | ||
if (empty($message)) { | ||
$message = "Driver class '{$className}' was not found. Please check configuration file."; | ||
} | ||
|
||
parent::__construct($message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,4 @@ | |
|
||
class WrongSecurityConfigException extends Exception | ||
{ | ||
|
||
} |
Oops, something went wrong.