@@ -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