@@ -256,9 +256,12 @@ public function uploadListener(Listener $listener): bool
256256 {
257257 try {
258258 $ this ->unitRequest ->setMethod (HttpMethodsEnum::PUT )
259- ->send ("/config/listeners/ {$ listener ->getListener ()}" , requestOptions: [
260- 'json ' => $ listener ->toArray ()
261- ]);
259+ ->send (
260+ uri: "/config/listeners/ {$ listener ->getListener ()}" ,
261+ requestOptions: [
262+ 'json ' => $ listener ->toArray ()
263+ ]
264+ );
262265 } catch (UnitException $ e ) {
263266 print_r ($ e ->getMessage ());
264267 return false ;
@@ -270,7 +273,7 @@ public function uploadListener(Listener $listener): bool
270273 /**
271274 * @throws UnitException
272275 */
273- public function uploadListenerFromFile (string $ path , string $ listener ): bool
276+ public function uploadListenerFromFile (string $ path , string $ listenerName ): bool
274277 {
275278 $ fileContent = file_get_contents ($ path );
276279
@@ -284,7 +287,7 @@ public function uploadListenerFromFile(string $path, string $listener): bool
284287
285288 try {
286289 $ this ->unitRequest ->setMethod (HttpMethodsEnum::PUT )
287- ->send (" /config/listeners/ $ listener " , requestOptions: [
290+ ->send (ApiPathEnum:: LISTENER -> getPath ( $ listenerName ) , requestOptions: [
288291 'body ' => $ fileContent
289292 ]);
290293 } catch (UnitException ) {
@@ -301,10 +304,10 @@ public function uploadListenerFromFile(string $path, string $listener): bool
301304 */
302305 public function removeListener (Listener $ listener ): bool
303306 {
304- $ listenerId = $ listener ->getListener ();
307+ $ listenerName = $ listener ->getListener ();
305308 $ this ->unitRequest
306- ->setMethod (HttpMethodsEnum::DELETE -> value )
307- ->send (" /config/listeners/ $ listenerId " );
309+ ->setMethod (HttpMethodsEnum::DELETE )
310+ ->send (ApiPathEnum:: LISTENER -> getPath ( $ listenerName ) );
308311
309312 return true ;
310313 }
@@ -347,12 +350,12 @@ public function uploadApplication(AbstractApplication $application, string $name
347350 throw new UnitException ('Application name not specified ' );
348351 }
349352
350- $ appName = empty ($ application ->getName ()) ? $ name : $ application ->getName ();
353+ $ applicationName = empty ($ application ->getName ()) ? $ name : $ application ->getName ();
351354
352355 try {
353356 $ this ->unitRequest
354- ->setMethod (HttpMethodsEnum::PUT -> value )
355- ->send (" /config/applications/ $ appName " , requestOptions: [
357+ ->setMethod (HttpMethodsEnum::PUT )
358+ ->send (ApiPathEnum:: APPLICATION -> getPath ( $ applicationName ) , requestOptions: [
356359 'json ' => $ application ->toJson ()
357360 ]);
358361 } catch (UnitException ) {
@@ -366,7 +369,7 @@ public function uploadApplication(AbstractApplication $application, string $name
366369 * @inheritdoc
367370 * @throws UnitException
368371 */
369- public function uploadApplicationFromFile (string $ path , string $ name ): bool
372+ public function uploadApplicationFromFile (string $ path , string $ applicationName ): bool
370373 {
371374 // TODO: add validation if json contains application name
372375 $ fileContent = file_get_contents ($ path );
@@ -381,8 +384,8 @@ public function uploadApplicationFromFile(string $path, string $name): bool
381384
382385 try {
383386 $ this ->unitRequest
384- ->setMethod (HttpMethodsEnum::PUT -> value )
385- ->send (" /config/applications/ $ name " , requestOptions: [
387+ ->setMethod (HttpMethodsEnum::PUT )
388+ ->send (ApiPathEnum:: APPLICATION -> getPath ( $ applicationName ) , requestOptions: [
386389 'body ' => $ fileContent
387390 ]);
388391 } catch (UnitException ) {
@@ -402,8 +405,8 @@ public function removeApplication(AbstractApplication|string $application): bool
402405 {
403406 $ applicationName = is_string ($ application ) ? $ application : $ application ->getName ();
404407 $ this ->unitRequest
405- ->setMethod (HttpMethodsEnum::DELETE -> value )
406- ->send (" /config/applications/ $ applicationName" );
408+ ->setMethod (HttpMethodsEnum::DELETE )
409+ ->send (ApiPathEnum:: APPLICATION -> getPath ( $ applicationName) );
407410
408411 return true ;
409412 }
@@ -492,8 +495,8 @@ public function uploadUpstream(Upstream $upstream, string $name = ''): bool
492495
493496 try {
494497 $ this ->unitRequest
495- ->setMethod (HttpMethodsEnum::PUT -> value )
496- ->send (" /config/upstreams/ $ upstreamName" , requestOptions: [
498+ ->setMethod (HttpMethodsEnum::PUT )
499+ ->send (ApiPathEnum:: UPSTREAM -> getPath ( $ upstreamName) , requestOptions: [
497500 'json ' => $ upstream ->toArray ()
498501 ]);
499502 } catch (UnitException ) {
@@ -521,8 +524,8 @@ public function uploadUpstreamsFromFile(string $path): bool
521524
522525 try {
523526 $ this ->unitRequest
524- ->setMethod (HttpMethodsEnum::PUT -> value )
525- ->send (' /config/upstreams ' , requestOptions: [
527+ ->setMethod (HttpMethodsEnum::PUT )
528+ ->send (ApiPathEnum:: UPSTREAMS , requestOptions: [
526529 'body ' => $ fileContent
527530 ]);
528531 } catch (UnitException $ exception ) {
@@ -546,7 +549,7 @@ public function setAccessLog($path, $format = null): bool
546549
547550 try {
548551 $ this ->unitRequest ->setMethod (HttpMethodsEnum::PUT )
549- ->send (' /config/access_log ' , requestOptions: [
552+ ->send (ApiPathEnum:: ACCESS_LOG , requestOptions: [
550553 'json ' => json_encode ($ data )
551554 ]);
552555 } catch (UnitException ) {
@@ -576,8 +579,8 @@ public function removeAccessLog(): bool
576579 {
577580 try {
578581 $ this ->unitRequest
579- ->setMethod (HttpMethodsEnum::DELETE -> value )
580- ->send (' /config/access_log ' );
582+ ->setMethod (HttpMethodsEnum::DELETE )
583+ ->send (ApiPathEnum:: ACCESS_LOG -> value );
581584 } catch (UnitException ) {
582585 return false ;
583586 }
@@ -623,20 +626,20 @@ public function reset(): bool
623626 {
624627 try {
625628 $ this ->unitRequest ->setMethod (HttpMethodsEnum::DELETE )
626- ->send (' /config ' );
629+ ->send (ApiPathEnum:: CONFIG -> value );
627630
628631 $ this ->unitRequest ->setMethod (HttpMethodsEnum::POST )
629632 ->send (
630- uri: ' /config ' ,
633+ uri: ApiPathEnum:: CONFIG -> value ,
631634 requestOptions: [
632- 'json ' => json_encode ([
633- 'listeners ' => (object )[],
634- 'routes ' => (object )[],
635- 'applications ' => (object )[],
636- 'upstreams ' => (object )[],
637- 'settings ' => (object )[]
638- ])
639- ]
635+ 'json ' => json_encode ([
636+ 'listeners ' => (object )[],
637+ 'routes ' => (object )[],
638+ 'applications ' => (object )[],
639+ 'upstreams ' => (object )[],
640+ 'settings ' => (object )[]
641+ ])
642+ ]
640643 );
641644 } catch (UnitException ) {
642645 return false ;
0 commit comments