@@ -17,93 +17,93 @@ |
||
17 | 17 | * @Route(path="/configuration-value") |
18 | 18 | */ |
19 | 19 | class ConfigurationValueController extends Controller { |
20 | - /** |
|
21 | - * @var \Doctrine\ORM\EntityManagerInterface |
|
22 | - */ |
|
23 | - private $entityManager; |
|
20 | + /** |
|
21 | + * @var \Doctrine\ORM\EntityManagerInterface |
|
22 | + */ |
|
23 | + private $entityManager; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var DefinitionRegistry |
|
27 | - */ |
|
28 | - private $registry; |
|
25 | + /** |
|
26 | + * @var DefinitionRegistry |
|
27 | + */ |
|
28 | + private $registry; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var ConfigurationResolverFactory |
|
32 | - */ |
|
33 | - private $factory; |
|
30 | + /** |
|
31 | + * @var ConfigurationResolverFactory |
|
32 | + */ |
|
33 | + private $factory; |
|
34 | 34 | |
35 | - public function __construct( |
|
36 | - RegistryInterface $doctrine, |
|
37 | - DefinitionRegistry $registry, |
|
38 | - ConfigurationResolverFactory $factory |
|
39 | - ) { |
|
40 | - $this->entityManager = $doctrine->getEntityManagerForClass(ConfigurationValue::class); |
|
41 | - $this->registry = $registry; |
|
42 | - $this->factory = $factory; |
|
43 | - } |
|
35 | + public function __construct( |
|
36 | + RegistryInterface $doctrine, |
|
37 | + DefinitionRegistry $registry, |
|
38 | + ConfigurationResolverFactory $factory |
|
39 | + ) { |
|
40 | + $this->entityManager = $doctrine->getEntityManagerForClass(ConfigurationValue::class); |
|
41 | + $this->registry = $registry; |
|
42 | + $this->factory = $factory; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @Route(path="/assign", name="configurationValue.assign") |
|
47 | - * @throws \Doctrine\ORM\OptimisticLockException |
|
48 | - */ |
|
49 | - public function assignAction(Request $request) { |
|
50 | - $configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll(); |
|
51 | - $existingValueKeys = array_map(function (ConfigurationValue $value) { |
|
52 | - return $value->getKey(); |
|
53 | - }, $configurationValues); |
|
54 | - $missingValueKeys = array_diff($this->registry->keys(), $existingValueKeys); |
|
55 | - $configurationValues = array_merge( |
|
56 | - $configurationValues, |
|
57 | - array_map(function (string $key) { |
|
58 | - $value = new ConfigurationValue(); |
|
59 | - $value->setKey($key); |
|
60 | - return $value; |
|
61 | - }, $missingValueKeys) |
|
62 | - ); |
|
45 | + /** |
|
46 | + * @Route(path="/assign", name="configurationValue.assign") |
|
47 | + * @throws \Doctrine\ORM\OptimisticLockException |
|
48 | + */ |
|
49 | + public function assignAction(Request $request) { |
|
50 | + $configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll(); |
|
51 | + $existingValueKeys = array_map(function (ConfigurationValue $value) { |
|
52 | + return $value->getKey(); |
|
53 | + }, $configurationValues); |
|
54 | + $missingValueKeys = array_diff($this->registry->keys(), $existingValueKeys); |
|
55 | + $configurationValues = array_merge( |
|
56 | + $configurationValues, |
|
57 | + array_map(function (string $key) { |
|
58 | + $value = new ConfigurationValue(); |
|
59 | + $value->setKey($key); |
|
60 | + return $value; |
|
61 | + }, $missingValueKeys) |
|
62 | + ); |
|
63 | 63 | |
64 | - $form = $this->createForm(ConfigurationValuesType::class, ['configurationValues' => $configurationValues]); |
|
65 | - $form->handleRequest($request); |
|
66 | - if ($form->isSubmitted() and $form->isValid()) { |
|
67 | - /* @var $configurationValue ConfigurationValue */ |
|
68 | - foreach ($form->get('configurationValues')->getData() as $configurationValue) { |
|
69 | - $isPersisted = \Doctrine\ORM\UnitOfWork::STATE_MANAGED === |
|
70 | - $this->entityManager->getUnitOfWork()->getEntityState($configurationValue); |
|
64 | + $form = $this->createForm(ConfigurationValuesType::class, ['configurationValues' => $configurationValues]); |
|
65 | + $form->handleRequest($request); |
|
66 | + if ($form->isSubmitted() and $form->isValid()) { |
|
67 | + /* @var $configurationValue ConfigurationValue */ |
|
68 | + foreach ($form->get('configurationValues')->getData() as $configurationValue) { |
|
69 | + $isPersisted = \Doctrine\ORM\UnitOfWork::STATE_MANAGED === |
|
70 | + $this->entityManager->getUnitOfWork()->getEntityState($configurationValue); |
|
71 | 71 | |
72 | - if ($configurationValue->getValue() === null and $isPersisted) { |
|
73 | - $this->entityManager->remove($configurationValue); |
|
74 | - } else if ($configurationValue->getValue() !== null and !$isPersisted) { |
|
75 | - $this->entityManager->persist($configurationValue); |
|
76 | - } |
|
77 | - } |
|
78 | - $this->entityManager->flush(); |
|
72 | + if ($configurationValue->getValue() === null and $isPersisted) { |
|
73 | + $this->entityManager->remove($configurationValue); |
|
74 | + } else if ($configurationValue->getValue() !== null and !$isPersisted) { |
|
75 | + $this->entityManager->persist($configurationValue); |
|
76 | + } |
|
77 | + } |
|
78 | + $this->entityManager->flush(); |
|
79 | 79 | |
80 | - return $this->redirectToRoute('configurationValue.view'); |
|
81 | - } |
|
80 | + return $this->redirectToRoute('configurationValue.view'); |
|
81 | + } |
|
82 | 82 | |
83 | - return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:assign.html.twig', ['form' => $form->createView()]); |
|
84 | - } |
|
83 | + return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:assign.html.twig', ['form' => $form->createView()]); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @Route(path="/view", name="configurationValue.view") |
|
88 | - */ |
|
89 | - public function viewAction() { |
|
90 | - /* @var $configurationValues ConfigurationValue[] */ |
|
91 | - $configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll(); |
|
92 | - $labels = []; |
|
93 | - $propertyAccessor = new PropertyAccessor(); |
|
94 | - foreach ($configurationValues as $configurationValue) { |
|
95 | - $definition = $this->registry->get($configurationValue->getKey()); |
|
96 | - if ($definition instanceof EntityDefinition) { |
|
97 | - $object = $this->factory->create($definition->getKey())->resolve(); |
|
98 | - $labels[$definition->getKey()] = $propertyAccessor->getValue($object, $definition->getChoiceLabel()); |
|
99 | - } |
|
100 | - } |
|
86 | + /** |
|
87 | + * @Route(path="/view", name="configurationValue.view") |
|
88 | + */ |
|
89 | + public function viewAction() { |
|
90 | + /* @var $configurationValues ConfigurationValue[] */ |
|
91 | + $configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll(); |
|
92 | + $labels = []; |
|
93 | + $propertyAccessor = new PropertyAccessor(); |
|
94 | + foreach ($configurationValues as $configurationValue) { |
|
95 | + $definition = $this->registry->get($configurationValue->getKey()); |
|
96 | + if ($definition instanceof EntityDefinition) { |
|
97 | + $object = $this->factory->create($definition->getKey())->resolve(); |
|
98 | + $labels[$definition->getKey()] = $propertyAccessor->getValue($object, $definition->getChoiceLabel()); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:view.html.twig', [ |
|
103 | - 'configurationValues' => $configurationValues, |
|
104 | - 'translationDomain' => $this->getParameter('one_guard.dynamic_configuration.translation_domain'), |
|
105 | - 'translationPrefix' => $this->getParameter('one_guard.dynamic_configuration.translation_prefix'), |
|
106 | - 'labels' => $labels |
|
107 | - ]); |
|
108 | - } |
|
102 | + return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:view.html.twig', [ |
|
103 | + 'configurationValues' => $configurationValues, |
|
104 | + 'translationDomain' => $this->getParameter('one_guard.dynamic_configuration.translation_domain'), |
|
105 | + 'translationPrefix' => $this->getParameter('one_guard.dynamic_configuration.translation_prefix'), |
|
106 | + 'labels' => $labels |
|
107 | + ]); |
|
108 | + } |
|
109 | 109 | } |