You've already forked Traefik-Redis-Api
Is there an award for this?
This commit is contained in:
@@ -4,10 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use League\Route\Http\Exception\NotFoundException;
|
||||
use Nyholm\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Siteworxpro\App\Facades\Logger;
|
||||
use Siteworxpro\App\Traefik\ProtocolEnum;
|
||||
|
||||
abstract class Controller implements ControllerInterface
|
||||
@@ -19,7 +19,7 @@ abstract class Controller implements ControllerInterface
|
||||
try {
|
||||
return ProtocolEnum::fromString($protocol);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Logger::error($e->getMessage());
|
||||
|
||||
return ProtocolEnum::HTTP;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use Nyholm\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Siteworxpro\App\Http\JsonResponseFactory;
|
||||
use Siteworxpro\App\Traefik\EntityEnum;
|
||||
use Siteworxpro\App\Traefik\RedisClient;
|
||||
use Siteworxpro\App\Facades\RedisClient;
|
||||
|
||||
class MiddlewaresController extends Controller
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ use Nyholm\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Siteworxpro\App\Http\JsonResponseFactory;
|
||||
use Siteworxpro\App\Traefik\EntityEnum;
|
||||
use Siteworxpro\App\Traefik\RedisClient;
|
||||
use Siteworxpro\App\Facades\RedisClient;
|
||||
|
||||
class RoutesController extends Controller
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ use Nyholm\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Siteworxpro\App\Http\JsonResponseFactory;
|
||||
use Siteworxpro\App\Traefik\EntityEnum;
|
||||
use Siteworxpro\App\Traefik\RedisClient;
|
||||
use Siteworxpro\App\Facades\RedisClient;
|
||||
|
||||
class ServicesController extends Controller
|
||||
{
|
||||
|
||||
45
src/Facades/RedisClient.php
Normal file
45
src/Facades/RedisClient.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Siteworxpro\App\Traefik\EntityEnum;
|
||||
use Siteworxpro\App\Traefik\ProtocolEnum;
|
||||
use Siteworxpro\App\Traefik\RedisClient as RedisClientConcrete;
|
||||
|
||||
/**
|
||||
* Facade for RedisClient.
|
||||
*
|
||||
* This class provides a static interface to the RedisClientConcrete class.
|
||||
*
|
||||
* @method static void createOrReplace(string $name, array $data, EntityEnum $entity, ProtocolEnum $type = ProtocolEnum::HTTP)
|
||||
* @method static bool deleteAllKeys(string $name, EntityEnum $entity, ProtocolEnum $protocol = ProtocolEnum::HTTP)
|
||||
* @method static array getAllMiddlewares(ProtocolEnum $protocol = ProtocolEnum::HTTP)
|
||||
* @method static array getMiddleware(string $name, ProtocolEnum $protocol = ProtocolEnum::HTTP)
|
||||
* @method static array getAllRouters(ProtocolEnum $protocol = ProtocolEnum::HTTP)
|
||||
* @method static array getRouter(string $name, ProtocolEnum $protocol = ProtocolEnum::HTTP)
|
||||
* @method static array getAllServices(ProtocolEnum $protocol = ProtocolEnum::HTTP)
|
||||
* @method static array getService(string $name, ProtocolEnum $protocol = ProtocolEnum::HTTP)
|
||||
*/
|
||||
class RedisClient extends Facade
|
||||
{
|
||||
public static function getFacadeRoot(): RedisClientConcrete
|
||||
{
|
||||
if (self::$resolvedInstance !== null) {
|
||||
$client = self::resolveFacadeInstance(self::getFacadeAccessor());
|
||||
|
||||
if ($client instanceof RedisClientConcrete) {
|
||||
return $client;
|
||||
}
|
||||
}
|
||||
|
||||
return new RedisClientConcrete();
|
||||
}
|
||||
|
||||
protected static function getFacadeAccessor(): string
|
||||
{
|
||||
return RedisClientConcrete::class;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class RedisClient
|
||||
* @param ProtocolEnum $type
|
||||
* @return void
|
||||
*/
|
||||
public static function createOrReplace(
|
||||
public function createOrReplace(
|
||||
string $name,
|
||||
array $data,
|
||||
EntityEnum $entity,
|
||||
@@ -47,7 +47,7 @@ class RedisClient
|
||||
* @param ProtocolEnum $protocol
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteAllKeys(
|
||||
public function deleteAllKeys(
|
||||
string $name,
|
||||
EntityEnum $entity,
|
||||
ProtocolEnum $protocol = ProtocolEnum::HTTP
|
||||
@@ -66,33 +66,33 @@ class RedisClient
|
||||
* @param ProtocolEnum $type
|
||||
* @return array
|
||||
*/
|
||||
public static function getMiddleware(string $name, ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
public function getMiddleware(string $name, ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
{
|
||||
$pattern = 'traefik/' . $type->getValue() . '/' . EntityEnum::MIDDLEWARE->getValue() . "/$name/*";
|
||||
|
||||
return self::fetchValuesToArray($pattern);
|
||||
return $this->fetchValuesToArray($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProtocolEnum $type
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllMiddlewares(ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
public function getAllMiddlewares(ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
{
|
||||
$pattern = 'traefik/' . $type->getValue() . '/' . EntityEnum::MIDDLEWARE->getValue() . '/*';
|
||||
|
||||
return self::getUniqueKeys($pattern, 3);
|
||||
return $this->getUniqueKeys($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProtocolEnum $type
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllServices(ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
public function getAllServices(ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
{
|
||||
$pattern = 'traefik/' . $type->getValue() . '/' . EntityEnum::SERVICE->getValue() . '/*';
|
||||
|
||||
return self::getUniqueKeys($pattern, 3);
|
||||
return $this->getUniqueKeys($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,22 +100,22 @@ class RedisClient
|
||||
* @param ProtocolEnum $type
|
||||
* @return array
|
||||
*/
|
||||
public static function getService(string $serviceName, ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
public function getService(string $serviceName, ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
{
|
||||
$pattern = 'traefik/' . $type->getValue() . '/' . EntityEnum::SERVICE->getValue() . "/$serviceName/*";
|
||||
|
||||
return self::fetchValuesToArray($pattern);
|
||||
return $this->fetchValuesToArray($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProtocolEnum $type
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllRouters(ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
public function getAllRouters(ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
{
|
||||
$pattern = 'traefik/' . $type->getValue() . '/' . EntityEnum::ROUTER->getValue() . '/*';
|
||||
|
||||
return self::getUniqueKeys($pattern, 3);
|
||||
return $this->getUniqueKeys($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,27 +123,26 @@ class RedisClient
|
||||
* @param ProtocolEnum $type
|
||||
* @return array
|
||||
*/
|
||||
public static function getRouter(string $name, ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
public function getRouter(string $name, ProtocolEnum $type = ProtocolEnum::HTTP): array
|
||||
{
|
||||
$pattern = 'traefik/' . $type->getValue() . '/' . EntityEnum::ROUTER->getValue() . "/$name/*";
|
||||
|
||||
return self::fetchValuesToArray($pattern);
|
||||
return $this->fetchValuesToArray($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pattern
|
||||
* @param int $position
|
||||
* @return array
|
||||
*/
|
||||
private static function getUniqueKeys(string $pattern, int $position): array
|
||||
private function getUniqueKeys(string $pattern): array
|
||||
{
|
||||
$values = new Collection();
|
||||
$redis = Redis::getFacadeRoot();
|
||||
|
||||
foreach (new Keyspace($redis, $pattern) as $key) {
|
||||
$parts = explode('/', $key);
|
||||
if (isset($parts[$position])) {
|
||||
$values->push($parts[$position]);
|
||||
if (isset($parts[3])) {
|
||||
$values->push($parts[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +153,7 @@ class RedisClient
|
||||
* @param string $pattern
|
||||
* @return array
|
||||
*/
|
||||
private static function fetchValuesToArray(string $pattern): array
|
||||
private function fetchValuesToArray(string $pattern): array
|
||||
{
|
||||
$redis = Redis::getFacadeRoot();
|
||||
|
||||
@@ -174,7 +173,7 @@ class RedisClient
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public static function flattenToDotArray(array $data): array
|
||||
public function flattenToDotArray(array $data): array
|
||||
{
|
||||
$collection = new Collection($data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user