Compare commits
1 Commits
934eefa802
...
633e93c129
Author | SHA1 | Date | |
---|---|---|---|
633e93c129 |
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Flag\Controller;
|
namespace App\Flag\Controller;
|
||||||
|
|
||||||
|
use App\Flag\FlagAccessor;
|
||||||
use App\Flag\FlagEnum;
|
use App\Flag\FlagEnum;
|
||||||
use Predis\ClientInterface;
|
use Predis\ClientInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Exception\JsonException;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@ -17,12 +19,13 @@ class FlagController extends AbstractController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
FlagEnum::from($flagName);
|
FlagEnum::from($flagName);
|
||||||
|
$flagValue = \json_decode($request->getContent(), true, flags: JSON_THROW_ON_ERROR)[FlagAccessor::FLAG_VALUE];
|
||||||
} catch (\ValueError $e) {
|
} catch (\ValueError $e) {
|
||||||
throw new \InvalidArgumentException('invalid flag name provided');
|
throw new \InvalidArgumentException('invalid flag name provided');
|
||||||
|
} catch (JsonException $e) {
|
||||||
|
throw new \InvalidArgumentException('invalid json format');
|
||||||
}
|
}
|
||||||
|
|
||||||
$flagValue = $request->query->getBoolean('flagValue');
|
|
||||||
|
|
||||||
$redis->set($flagName, $flagValue);
|
$redis->set($flagName, $flagValue);
|
||||||
|
|
||||||
return new JsonResponse(
|
return new JsonResponse(
|
||||||
|
@ -6,6 +6,8 @@ use Predis\ClientInterface;
|
|||||||
|
|
||||||
class FlagAccessor
|
class FlagAccessor
|
||||||
{
|
{
|
||||||
|
public const FLAG_VALUE = 'flagValue';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly ClientInterface $redis
|
private readonly ClientInterface $redis
|
||||||
) {
|
) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user