@@ -25,13 +25,13 @@ |
||
| 25 | 25 | public function getConfig(People $people, $key, $json = false) |
| 26 | 26 | { |
| 27 | 27 | $config = $this->discoveryConfig($people, $key, false); |
| 28 | - $value = $config ? $config->getConfigValue() : null; |
|
| 28 | + $value = $config ? $config->getConfigValue() : null; |
|
| 29 | 29 | return $json ? json_decode($value) : $value; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | private function discoveryConfig(People $people, $key, $create = true): ?Config |
| 33 | 33 | { |
| 34 | - $config = $this->manager->getRepository(Config::class)->findOneBy([ |
|
| 34 | + $config = $this->manager->getRepository(Config::class)->findOneBy([ |
|
| 35 | 35 | 'people' => $people, |
| 36 | 36 | 'configKey' => $key |
| 37 | 37 | ]); |
@@ -35,8 +35,9 @@ discard block |
||
| 35 | 35 | 'people' => $people, |
| 36 | 36 | 'configKey' => $key |
| 37 | 37 | ]); |
| 38 | - if ($config) |
|
| 39 | - return $config; |
|
| 38 | + if ($config) { |
|
| 39 | + return $config; |
|
| 40 | + } |
|
| 40 | 41 | if ($create) { |
| 41 | 42 | $config = new Config(); |
| 42 | 43 | $config->setConfigKey($key); |
@@ -49,14 +50,16 @@ discard block |
||
| 49 | 50 | { |
| 50 | 51 | $config = $this->discoveryConfig($people, $key); |
| 51 | 52 | $newValue = json_decode($config->getConfigValue()) || []; |
| 52 | - if (!is_array($newValue)) |
|
| 53 | - $newValue = [$newValue]; |
|
| 53 | + if (!is_array($newValue)) { |
|
| 54 | + $newValue = [$newValue]; |
|
| 55 | + } |
|
| 54 | 56 | |
| 55 | - if (is_array($values)) |
|
| 56 | - foreach ($values as $key => $value) |
|
| 57 | + if (is_array($values)) { |
|
| 58 | + foreach ($values as $key => $value) |
|
| 57 | 59 | $newValue[$key] = $value; |
| 58 | - else |
|
| 59 | - $newValue[] = $values; |
|
| 60 | + } else { |
|
| 61 | + $newValue[] = $values; |
|
| 62 | + } |
|
| 60 | 63 | |
| 61 | 64 | $config->setConfigValue(json_encode($newValue)); |
| 62 | 65 | $this->manager->persist($config); |
@@ -17,22 +17,22 @@ |
||
| 17 | 17 | |
| 18 | 18 | class AddAppConfigAction |
| 19 | 19 | { |
| 20 | - public function __construct( |
|
| 20 | + public function __construct( |
|
| 21 | 21 | private Security $security, |
| 22 | 22 | private EntityManagerInterface $manager, |
| 23 | 23 | private ConfigService $configService, |
| 24 | 24 | private HydratorService $hydratorService |
| 25 | - ) {} |
|
| 25 | + ) {} |
|
| 26 | 26 | |
| 27 | - public function __invoke(Request $request): JsonResponse |
|
| 28 | - { |
|
| 27 | + public function __invoke(Request $request): JsonResponse |
|
| 28 | + { |
|
| 29 | 29 | try { |
| 30 | - $json = json_decode($request->getContent(), true); |
|
| 31 | - $people = $this->manager->getRepository(People::class)->find($json['people']); |
|
| 32 | - $config = $this->configService->addConfig($people, $json['configKey'], $json['configValue']); |
|
| 33 | - return new JsonResponse($this->hydratorService->item(Config::class, $config->getId(), "config:read"), Response::HTTP_OK); |
|
| 30 | + $json = json_decode($request->getContent(), true); |
|
| 31 | + $people = $this->manager->getRepository(People::class)->find($json['people']); |
|
| 32 | + $config = $this->configService->addConfig($people, $json['configKey'], $json['configValue']); |
|
| 33 | + return new JsonResponse($this->hydratorService->item(Config::class, $config->getId(), "config:read"), Response::HTTP_OK); |
|
| 34 | 34 | } catch (Exception $e) { |
| 35 | - return new JsonResponse($this->hydratorService->error($e)); |
|
| 35 | + return new JsonResponse($this->hydratorService->error($e)); |
|
| 36 | + } |
|
| 36 | 37 | } |
| 37 | - } |
|
| 38 | 38 | } |