@@ -256,9 +256,12 @@ public function uploadListener(Listener $listener): bool
256
256
{
257
257
try {
258
258
$ 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
+ );
262
265
} catch (UnitException $ e ) {
263
266
print_r ($ e ->getMessage ());
264
267
return false ;
@@ -270,7 +273,7 @@ public function uploadListener(Listener $listener): bool
270
273
/**
271
274
* @throws UnitException
272
275
*/
273
- public function uploadListenerFromFile (string $ path , string $ listener ): bool
276
+ public function uploadListenerFromFile (string $ path , string $ listenerName ): bool
274
277
{
275
278
$ fileContent = file_get_contents ($ path );
276
279
@@ -284,7 +287,7 @@ public function uploadListenerFromFile(string $path, string $listener): bool
284
287
285
288
try {
286
289
$ this ->unitRequest ->setMethod (HttpMethodsEnum::PUT )
287
- ->send (" /config/listeners/ $ listener " , requestOptions: [
290
+ ->send (ApiPathEnum:: LISTENER -> getPath ( $ listenerName ) , requestOptions: [
288
291
'body ' => $ fileContent
289
292
]);
290
293
} catch (UnitException ) {
@@ -301,10 +304,10 @@ public function uploadListenerFromFile(string $path, string $listener): bool
301
304
*/
302
305
public function removeListener (Listener $ listener ): bool
303
306
{
304
- $ listenerId = $ listener ->getListener ();
307
+ $ listenerName = $ listener ->getListener ();
305
308
$ this ->unitRequest
306
- ->setMethod (HttpMethodsEnum::DELETE -> value )
307
- ->send (" /config/listeners/ $ listenerId " );
309
+ ->setMethod (HttpMethodsEnum::DELETE )
310
+ ->send (ApiPathEnum:: LISTENER -> getPath ( $ listenerName ) );
308
311
309
312
return true ;
310
313
}
@@ -347,12 +350,12 @@ public function uploadApplication(AbstractApplication $application, string $name
347
350
throw new UnitException ('Application name not specified ' );
348
351
}
349
352
350
- $ appName = empty ($ application ->getName ()) ? $ name : $ application ->getName ();
353
+ $ applicationName = empty ($ application ->getName ()) ? $ name : $ application ->getName ();
351
354
352
355
try {
353
356
$ this ->unitRequest
354
- ->setMethod (HttpMethodsEnum::PUT -> value )
355
- ->send (" /config/applications/ $ appName " , requestOptions: [
357
+ ->setMethod (HttpMethodsEnum::PUT )
358
+ ->send (ApiPathEnum:: APPLICATION -> getPath ( $ applicationName ) , requestOptions: [
356
359
'json ' => $ application ->toJson ()
357
360
]);
358
361
} catch (UnitException ) {
@@ -366,7 +369,7 @@ public function uploadApplication(AbstractApplication $application, string $name
366
369
* @inheritdoc
367
370
* @throws UnitException
368
371
*/
369
- public function uploadApplicationFromFile (string $ path , string $ name ): bool
372
+ public function uploadApplicationFromFile (string $ path , string $ applicationName ): bool
370
373
{
371
374
// TODO: add validation if json contains application name
372
375
$ fileContent = file_get_contents ($ path );
@@ -381,8 +384,8 @@ public function uploadApplicationFromFile(string $path, string $name): bool
381
384
382
385
try {
383
386
$ this ->unitRequest
384
- ->setMethod (HttpMethodsEnum::PUT -> value )
385
- ->send (" /config/applications/ $ name " , requestOptions: [
387
+ ->setMethod (HttpMethodsEnum::PUT )
388
+ ->send (ApiPathEnum:: APPLICATION -> getPath ( $ applicationName ) , requestOptions: [
386
389
'body ' => $ fileContent
387
390
]);
388
391
} catch (UnitException ) {
@@ -402,8 +405,8 @@ public function removeApplication(AbstractApplication|string $application): bool
402
405
{
403
406
$ applicationName = is_string ($ application ) ? $ application : $ application ->getName ();
404
407
$ this ->unitRequest
405
- ->setMethod (HttpMethodsEnum::DELETE -> value )
406
- ->send (" /config/applications/ $ applicationName" );
408
+ ->setMethod (HttpMethodsEnum::DELETE )
409
+ ->send (ApiPathEnum:: APPLICATION -> getPath ( $ applicationName) );
407
410
408
411
return true ;
409
412
}
@@ -492,8 +495,8 @@ public function uploadUpstream(Upstream $upstream, string $name = ''): bool
492
495
493
496
try {
494
497
$ this ->unitRequest
495
- ->setMethod (HttpMethodsEnum::PUT -> value )
496
- ->send (" /config/upstreams/ $ upstreamName" , requestOptions: [
498
+ ->setMethod (HttpMethodsEnum::PUT )
499
+ ->send (ApiPathEnum:: UPSTREAM -> getPath ( $ upstreamName) , requestOptions: [
497
500
'json ' => $ upstream ->toArray ()
498
501
]);
499
502
} catch (UnitException ) {
@@ -521,8 +524,8 @@ public function uploadUpstreamsFromFile(string $path): bool
521
524
522
525
try {
523
526
$ this ->unitRequest
524
- ->setMethod (HttpMethodsEnum::PUT -> value )
525
- ->send (' /config/upstreams ' , requestOptions: [
527
+ ->setMethod (HttpMethodsEnum::PUT )
528
+ ->send (ApiPathEnum:: UPSTREAMS , requestOptions: [
526
529
'body ' => $ fileContent
527
530
]);
528
531
} catch (UnitException $ exception ) {
@@ -546,7 +549,7 @@ public function setAccessLog($path, $format = null): bool
546
549
547
550
try {
548
551
$ this ->unitRequest ->setMethod (HttpMethodsEnum::PUT )
549
- ->send (' /config/access_log ' , requestOptions: [
552
+ ->send (ApiPathEnum:: ACCESS_LOG , requestOptions: [
550
553
'json ' => json_encode ($ data )
551
554
]);
552
555
} catch (UnitException ) {
@@ -576,8 +579,8 @@ public function removeAccessLog(): bool
576
579
{
577
580
try {
578
581
$ this ->unitRequest
579
- ->setMethod (HttpMethodsEnum::DELETE -> value )
580
- ->send (' /config/access_log ' );
582
+ ->setMethod (HttpMethodsEnum::DELETE )
583
+ ->send (ApiPathEnum:: ACCESS_LOG -> value );
581
584
} catch (UnitException ) {
582
585
return false ;
583
586
}
@@ -623,20 +626,20 @@ public function reset(): bool
623
626
{
624
627
try {
625
628
$ this ->unitRequest ->setMethod (HttpMethodsEnum::DELETE )
626
- ->send (' /config ' );
629
+ ->send (ApiPathEnum:: CONFIG -> value );
627
630
628
631
$ this ->unitRequest ->setMethod (HttpMethodsEnum::POST )
629
632
->send (
630
- uri: ' /config ' ,
633
+ uri: ApiPathEnum:: CONFIG -> value ,
631
634
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
+ ]
640
643
);
641
644
} catch (UnitException ) {
642
645
return false ;
0 commit comments