diff --git a/src/Controllers/Controller.php b/src/Controllers/Controller.php index 43c37c5..641f6d8 100644 --- a/src/Controllers/Controller.php +++ b/src/Controllers/Controller.php @@ -10,7 +10,6 @@ use Psr\Http\Message\ResponseInterface; abstract class Controller implements ControllerInterface { - /** * @param ServerRequest $request * @return ResponseInterface @@ -44,4 +43,4 @@ abstract class Controller implements ControllerInterface { throw new NotFoundException("not found"); } -} \ No newline at end of file +} diff --git a/src/Controllers/ControllerInterface.php b/src/Controllers/ControllerInterface.php index 228532f..68811fe 100644 --- a/src/Controllers/ControllerInterface.php +++ b/src/Controllers/ControllerInterface.php @@ -13,7 +13,7 @@ interface ControllerInterface * Handle the request and return a response. * * @param ServerRequest $request The request data. - * @return mixed The response data. + * @return ResponseInterface The response data. */ public function get(ServerRequest $request): ResponseInterface; @@ -21,7 +21,7 @@ interface ControllerInterface * Handle the request and return a response. * * @param ServerRequest $request The request data. - * @return mixed The response data. + * @return ResponseInterface The response data. */ public function post(ServerRequest $request): ResponseInterface; @@ -29,7 +29,7 @@ interface ControllerInterface * Handle the request and return a response. * * @param ServerRequest $request The request data. - * @return mixed The response data. + * @return ResponseInterface The response data. */ public function delete(ServerRequest $request): ResponseInterface; @@ -37,7 +37,7 @@ interface ControllerInterface * Handle the request and return a response. * * @param ServerRequest $request The request data. - * @return mixed The response data. + * @return ResponseInterface The response data. */ public function patch(ServerRequest $request): ResponseInterface; -} \ No newline at end of file +} diff --git a/src/Controllers/MiddlewaresController.php b/src/Controllers/MiddlewaresController.php index 0c33420..e30f4b9 100644 --- a/src/Controllers/MiddlewaresController.php +++ b/src/Controllers/MiddlewaresController.php @@ -12,7 +12,6 @@ use Siteworxpro\App\Traefik\RedisClient; class MiddlewaresController extends Controller { - /** * @throws \JsonException */ @@ -60,4 +59,4 @@ class MiddlewaresController extends Controller return JsonResponseFactory::createJsonResponse(['message' => 'Middleware deleted successfully']); } -} \ No newline at end of file +} diff --git a/src/Controllers/RoutesController.php b/src/Controllers/RoutesController.php index c4e17a9..4b49949 100644 --- a/src/Controllers/RoutesController.php +++ b/src/Controllers/RoutesController.php @@ -12,7 +12,6 @@ use Siteworxpro\App\Traefik\RedisClient; class RoutesController extends Controller { - /** * @throws \JsonException */ @@ -78,4 +77,4 @@ class RoutesController extends Controller return JsonResponseFactory::createJsonResponse(['message' => 'Router updated successfully']); } -} \ No newline at end of file +} diff --git a/src/Controllers/ServicesController.php b/src/Controllers/ServicesController.php index 4afb79c..1eb5a51 100644 --- a/src/Controllers/ServicesController.php +++ b/src/Controllers/ServicesController.php @@ -12,7 +12,6 @@ use Siteworxpro\App\Traefik\RedisClient; class ServicesController extends Controller { - /** * @throws \JsonException */ @@ -60,4 +59,4 @@ class ServicesController extends Controller return JsonResponseFactory::createJsonResponse(['message' => 'Service deleted successfully']); } -} \ No newline at end of file +} diff --git a/src/Facades/Redis.php b/src/Facades/Redis.php index 5762ff9..04ab0d1 100644 --- a/src/Facades/Redis.php +++ b/src/Facades/Redis.php @@ -21,7 +21,6 @@ use Predis\Response\Status; */ class Redis extends Facade { - public static function getFacadeRoot(): Client { if (self::$resolvedInstance !== null) { @@ -50,4 +49,4 @@ class Redis extends Facade { return Client::class; } -} \ No newline at end of file +} diff --git a/src/Traefik/EntityEnum.php b/src/Traefik/EntityEnum.php index 5417e95..c003a5b 100644 --- a/src/Traefik/EntityEnum.php +++ b/src/Traefik/EntityEnum.php @@ -18,4 +18,4 @@ enum EntityEnum self::MIDDLEWARE => 'middlewares', }; } -} \ No newline at end of file +} diff --git a/src/Traefik/ProtocolEnum.php b/src/Traefik/ProtocolEnum.php index e70247f..6d811bc 100644 --- a/src/Traefik/ProtocolEnum.php +++ b/src/Traefik/ProtocolEnum.php @@ -18,4 +18,4 @@ enum ProtocolEnum self::UDP => 'udp', }; } -} \ No newline at end of file +} diff --git a/src/Traefik/RedisClient.php b/src/Traefik/RedisClient.php index 68e0e8c..67d2ae9 100644 --- a/src/Traefik/RedisClient.php +++ b/src/Traefik/RedisClient.php @@ -20,14 +20,23 @@ class RedisClient * @param ProtocolEnum $type * @return void */ - public static function createOrReplace(string $name, array $data, EntityEnum $entity, ProtocolEnum $type = ProtocolEnum::HTTP): void - { + public static function createOrReplace( + string $name, + array $data, + EntityEnum $entity, + ProtocolEnum $type = ProtocolEnum::HTTP + ): void { self::deleteAllKeys($name, $entity, $type); $collection = self::flattenToDotArray($data); foreach ($collection as $key => $value) { - $redisKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name/" . str_replace('.', '/', $key); + $redisKey = 'traefik/' . + $type->getValue() . '/' . + $entity->getValue() . + "/$name/" . + str_replace('.', '/', $key); + Redis::set($redisKey, $value); } } @@ -39,8 +48,12 @@ class RedisClient * @param ProtocolEnum $type * @return void */ - public static function patchEntity(string $name, array $data, EntityEnum $entity, ProtocolEnum $type = ProtocolEnum::HTTP): void - { + public static function patchEntity( + string $name, + array $data, + EntityEnum $entity, + ProtocolEnum $type = ProtocolEnum::HTTP + ): void { $collection = self::flattenToDotArray($data); $checkKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name"; @@ -58,7 +71,13 @@ class RedisClient $arrayKey = preg_replace('/\.[0-9]+$/', '', $key); if (in_array($arrayKey, $cleanedUpKeys)) { - $redisKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name/" . str_replace('.', '/', $key); + $redisKey = 'traefik/' . + $type->getValue() . + '/' . + $entity->getValue() . + "/$name/" . + str_replace('.', '/', $key); + Redis::set($redisKey, $value); continue; @@ -73,7 +92,11 @@ class RedisClient $cleanedUpKeys[] = $arrayKey; } - $redisKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name/" . str_replace('.', '/', $key); + $redisKey = 'traefik/' . + $type->getValue() . '/' . $entity->getValue() . + "/$name/" . + str_replace('.', '/', $key); + Redis::set($redisKey, $value); } } @@ -84,8 +107,11 @@ class RedisClient * @param ProtocolEnum $protocol * @return bool */ - public static function deleteAllKeys(string $name, EntityEnum $entity, ProtocolEnum $protocol = ProtocolEnum::HTTP): bool - { + public static function deleteAllKeys( + string $name, + EntityEnum $entity, + ProtocolEnum $protocol = ProtocolEnum::HTTP + ): bool { $pattern = 'traefik/' . $protocol->getValue() . '/' . $entity->getValue() . "/$name/*"; foreach (new Keyspace(Redis::getFacadeRoot(), $pattern) as $key) { @@ -214,4 +240,4 @@ class RedisClient return $collection->dot()->toArray(); } -} \ No newline at end of file +}