@@ -24,7 +24,7 @@ |
||
24 | 24 | ->children() |
25 | 25 | ->scalarNode('class') |
26 | 26 | ->validate() |
27 | - ->ifTrue(function ($class) { |
|
27 | + ->ifTrue(function($class) { |
|
28 | 28 | return !class_exists($class); |
29 | 29 | }) |
30 | 30 | ->thenInvalid("Class doesn't exist.") |
@@ -6,32 +6,32 @@ discard block |
||
6 | 6 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
7 | 7 | |
8 | 8 | class Configuration implements ConfigurationInterface { |
9 | - public function getConfigTreeBuilder() { |
|
10 | - $treeBuilder = new TreeBuilder(); |
|
11 | - $rootNode = $treeBuilder->root('one_guard_dynamic_configuration'); |
|
9 | + public function getConfigTreeBuilder() { |
|
10 | + $treeBuilder = new TreeBuilder(); |
|
11 | + $rootNode = $treeBuilder->root('one_guard_dynamic_configuration'); |
|
12 | 12 | |
13 | - $rootNode |
|
14 | - ->addDefaultsIfNotSet() |
|
15 | - ->children() |
|
16 | - ->arrayNode('definitions') |
|
17 | - ->prototype('array') |
|
18 | - ->children() |
|
19 | - ->enumNode('type') |
|
20 | - ->values(['entity', 'string']) |
|
21 | - ->isRequired() |
|
22 | - ->end() |
|
23 | - ->arrayNode('options') |
|
24 | - ->children() |
|
25 | - ->scalarNode('class') |
|
26 | - ->validate() |
|
27 | - ->ifTrue(function ($class) { |
|
28 | - return !class_exists($class); |
|
29 | - }) |
|
30 | - ->thenInvalid("Class doesn't exist.") |
|
31 | - ->end() |
|
32 | - ->end() |
|
33 | - ->scalarNode('choice_label')->end() |
|
34 | - ->end() |
|
13 | + $rootNode |
|
14 | + ->addDefaultsIfNotSet() |
|
15 | + ->children() |
|
16 | + ->arrayNode('definitions') |
|
17 | + ->prototype('array') |
|
18 | + ->children() |
|
19 | + ->enumNode('type') |
|
20 | + ->values(['entity', 'string']) |
|
21 | + ->isRequired() |
|
22 | + ->end() |
|
23 | + ->arrayNode('options') |
|
24 | + ->children() |
|
25 | + ->scalarNode('class') |
|
26 | + ->validate() |
|
27 | + ->ifTrue(function ($class) { |
|
28 | + return !class_exists($class); |
|
29 | + }) |
|
30 | + ->thenInvalid("Class doesn't exist.") |
|
31 | + ->end() |
|
32 | + ->end() |
|
33 | + ->scalarNode('choice_label')->end() |
|
34 | + ->end() |
|
35 | 35 | // ->validate() |
36 | 36 | // ->ifTrue(function ($options) { |
37 | 37 | // if (!empty($options['class'])) { |
@@ -42,19 +42,19 @@ discard block |
||
42 | 42 | // }) |
43 | 43 | // ->thenInvalid("Property not accessible.") |
44 | 44 | // ->end() |
45 | - ->end() |
|
46 | - ->end() |
|
47 | - ->end() |
|
48 | - ->end() |
|
49 | - ->scalarNode('translation_domain') |
|
50 | - ->defaultValue('messages') |
|
51 | - ->cannotBeEmpty() |
|
52 | - ->end() |
|
53 | - ->scalarNode('translation_prefix') |
|
54 | - ->defaultValue('') |
|
55 | - ->end() |
|
56 | - ->end(); |
|
45 | + ->end() |
|
46 | + ->end() |
|
47 | + ->end() |
|
48 | + ->end() |
|
49 | + ->scalarNode('translation_domain') |
|
50 | + ->defaultValue('messages') |
|
51 | + ->cannotBeEmpty() |
|
52 | + ->end() |
|
53 | + ->scalarNode('translation_prefix') |
|
54 | + ->defaultValue('') |
|
55 | + ->end() |
|
56 | + ->end(); |
|
57 | 57 | |
58 | - return $treeBuilder; |
|
59 | - } |
|
58 | + return $treeBuilder; |
|
59 | + } |
|
60 | 60 | } |
@@ -21,10 +21,10 @@ |
||
21 | 21 | public function buildForm(FormBuilderInterface $builder, array $options) { |
22 | 22 | parent::buildForm($builder, $options); |
23 | 23 | $builder->addModelTransformer(new CallbackTransformer( |
24 | - function ($id) use ($options) { |
|
24 | + function($id) use ($options) { |
|
25 | 25 | return $id === null ? null : $this->doctrine->getRepository($options['class'])->find($id); |
26 | 26 | }, |
27 | - function ($entity) use ($options) { |
|
27 | + function($entity) use ($options) { |
|
28 | 28 | return $entity === null ? |
29 | 29 | null : $this->doctrine->getEntityManagerForClass($options['class'])->getUnitOfWork()->getSingleIdentifierValue($entity); |
30 | 30 | } |
@@ -8,26 +8,26 @@ |
||
8 | 8 | use Symfony\Component\Form\FormBuilderInterface; |
9 | 9 | |
10 | 10 | class EntityConfigurationValueType extends EntityType { |
11 | - /** |
|
12 | - * @var RegistryInterface |
|
13 | - */ |
|
14 | - private $doctrine; |
|
11 | + /** |
|
12 | + * @var RegistryInterface |
|
13 | + */ |
|
14 | + private $doctrine; |
|
15 | 15 | |
16 | - public function __construct(RegistryInterface $doctrine) { |
|
17 | - parent::__construct($doctrine); |
|
18 | - $this->doctrine = $doctrine; |
|
19 | - } |
|
16 | + public function __construct(RegistryInterface $doctrine) { |
|
17 | + parent::__construct($doctrine); |
|
18 | + $this->doctrine = $doctrine; |
|
19 | + } |
|
20 | 20 | |
21 | - public function buildForm(FormBuilderInterface $builder, array $options) { |
|
22 | - parent::buildForm($builder, $options); |
|
23 | - $builder->addModelTransformer(new CallbackTransformer( |
|
24 | - function ($id) use ($options) { |
|
25 | - return $id === null ? null : $this->doctrine->getRepository($options['class'])->find($id); |
|
26 | - }, |
|
27 | - function ($entity) use ($options) { |
|
28 | - return $entity === null ? |
|
29 | - null : $this->doctrine->getEntityManagerForClass($options['class'])->getUnitOfWork()->getSingleIdentifierValue($entity); |
|
30 | - } |
|
31 | - )); |
|
32 | - } |
|
21 | + public function buildForm(FormBuilderInterface $builder, array $options) { |
|
22 | + parent::buildForm($builder, $options); |
|
23 | + $builder->addModelTransformer(new CallbackTransformer( |
|
24 | + function ($id) use ($options) { |
|
25 | + return $id === null ? null : $this->doctrine->getRepository($options['class'])->find($id); |
|
26 | + }, |
|
27 | + function ($entity) use ($options) { |
|
28 | + return $entity === null ? |
|
29 | + null : $this->doctrine->getEntityManagerForClass($options['class'])->getUnitOfWork()->getSingleIdentifierValue($entity); |
|
30 | + } |
|
31 | + )); |
|
32 | + } |
|
33 | 33 | } |
@@ -48,13 +48,13 @@ |
||
48 | 48 | */ |
49 | 49 | public function assignAction(Request $request) { |
50 | 50 | $configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll(); |
51 | - $existingValueKeys = array_map(function (ConfigurationValue $value) { |
|
51 | + $existingValueKeys = array_map(function(ConfigurationValue $value) { |
|
52 | 52 | return $value->getKey(); |
53 | 53 | }, $configurationValues); |
54 | 54 | $missingValueKeys = array_diff($this->registry->keys(), $existingValueKeys); |
55 | 55 | $configurationValues = array_merge( |
56 | 56 | $configurationValues, |
57 | - array_map(function (string $key) { |
|
57 | + array_map(function(string $key) { |
|
58 | 58 | $value = new ConfigurationValue(); |
59 | 59 | $value->setKey($key); |
60 | 60 | return $value; |
@@ -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 | } |
@@ -8,28 +8,28 @@ |
||
8 | 8 | use OneGuard\Bundle\DynamicConfigurationBundle\ProtectedReferencesChecker; |
9 | 9 | |
10 | 10 | class ProtectedReferencesDoctrineSubscriber implements EventSubscriber { |
11 | - /** |
|
12 | - * @var ProtectedReferencesChecker |
|
13 | - */ |
|
14 | - private $checker; |
|
11 | + /** |
|
12 | + * @var ProtectedReferencesChecker |
|
13 | + */ |
|
14 | + private $checker; |
|
15 | 15 | |
16 | - public function __construct(ProtectedReferencesChecker $checker) { |
|
17 | - $this->checker = $checker; |
|
18 | - } |
|
16 | + public function __construct(ProtectedReferencesChecker $checker) { |
|
17 | + $this->checker = $checker; |
|
18 | + } |
|
19 | 19 | |
20 | - public function getSubscribedEvents() { |
|
21 | - return [ |
|
22 | - 'preRemove' |
|
23 | - ]; |
|
24 | - } |
|
20 | + public function getSubscribedEvents() { |
|
21 | + return [ |
|
22 | + 'preRemove' |
|
23 | + ]; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param LifecycleEventArgs $args |
|
28 | - * @throws ProtectedReferenceException |
|
29 | - * @throws \Doctrine\ORM\NoResultException |
|
30 | - * @throws \Doctrine\ORM\NonUniqueResultException |
|
31 | - */ |
|
32 | - public function preRemove(LifecycleEventArgs $args) { |
|
33 | - $this->checker->checkReferenceForProtection($args->getObject()); |
|
34 | - } |
|
26 | + /** |
|
27 | + * @param LifecycleEventArgs $args |
|
28 | + * @throws ProtectedReferenceException |
|
29 | + * @throws \Doctrine\ORM\NoResultException |
|
30 | + * @throws \Doctrine\ORM\NonUniqueResultException |
|
31 | + */ |
|
32 | + public function preRemove(LifecycleEventArgs $args) { |
|
33 | + $this->checker->checkReferenceForProtection($args->getObject()); |
|
34 | + } |
|
35 | 35 | } |
@@ -7,11 +7,11 @@ |
||
7 | 7 | use Symfony\Component\Form\FormBuilderInterface; |
8 | 8 | |
9 | 9 | class ConfigurationValuesType extends AbstractType { |
10 | - public function buildForm(FormBuilderInterface $builder, array $options) { |
|
11 | - $builder |
|
12 | - ->add('configurationValues', CollectionType::class, [ |
|
13 | - 'entry_type' => ConfigurationValueType::class, |
|
14 | - 'attr' => ['class' => 'panel panel-default panel-body'], |
|
15 | - ]); |
|
16 | - } |
|
10 | + public function buildForm(FormBuilderInterface $builder, array $options) { |
|
11 | + $builder |
|
12 | + ->add('configurationValues', CollectionType::class, [ |
|
13 | + 'entry_type' => ConfigurationValueType::class, |
|
14 | + 'attr' => ['class' => 'panel panel-default panel-body'], |
|
15 | + ]); |
|
16 | + } |
|
17 | 17 | } |
@@ -13,55 +13,55 @@ |
||
13 | 13 | use Symfony\Component\OptionsResolver\OptionsResolver; |
14 | 14 | |
15 | 15 | class ConfigurationValueType extends AbstractType { |
16 | - /** |
|
17 | - * @var DefinitionRegistry |
|
18 | - */ |
|
19 | - private $registry; |
|
16 | + /** |
|
17 | + * @var DefinitionRegistry |
|
18 | + */ |
|
19 | + private $registry; |
|
20 | 20 | |
21 | - private $translationDomain; |
|
22 | - private $translationPrefix; |
|
21 | + private $translationDomain; |
|
22 | + private $translationPrefix; |
|
23 | 23 | |
24 | - public function __construct( |
|
25 | - DefinitionRegistry $registry, |
|
26 | - string $translationDomain, |
|
27 | - string $translationPrefix |
|
28 | - ) { |
|
29 | - $this->registry = $registry; |
|
30 | - $this->translationDomain = $translationDomain; |
|
31 | - $this->translationPrefix = $translationPrefix; |
|
32 | - } |
|
24 | + public function __construct( |
|
25 | + DefinitionRegistry $registry, |
|
26 | + string $translationDomain, |
|
27 | + string $translationPrefix |
|
28 | + ) { |
|
29 | + $this->registry = $registry; |
|
30 | + $this->translationDomain = $translationDomain; |
|
31 | + $this->translationPrefix = $translationPrefix; |
|
32 | + } |
|
33 | 33 | |
34 | - public function buildForm(FormBuilderInterface $builder, array $options) { |
|
35 | - $builder |
|
36 | - ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
|
37 | - /* @var $configurationValue ConfigurationValue */ |
|
38 | - $configurationValue = $event->getData(); |
|
39 | - $definition = $this->registry->get($configurationValue->getKey()); |
|
40 | - switch (get_class($definition)) { |
|
41 | - case EntityDefinition::class: |
|
42 | - /* @var $definition EntityDefinition */ |
|
43 | - $form = $event->getForm(); |
|
44 | - $form->add('value', EntityConfigurationValueType::class, [ |
|
45 | - 'class' => $definition->getClass(), |
|
46 | - 'choice_label' => $definition->getChoiceLabel(), |
|
47 | - 'label' => $this->translationPrefix . $configurationValue->getKey(), |
|
48 | - 'translation_domain' => $this->translationDomain, |
|
49 | - 'placeholder' => 'Please choose', |
|
50 | - 'empty_data' => null, |
|
51 | - 'required' => false |
|
52 | - ]); |
|
53 | - break; |
|
54 | - default: // assume StringDefinition |
|
55 | - $event->getForm()->add('value', TextType::class, [ |
|
56 | - 'label' => $this->translationPrefix . $configurationValue->getKey(), |
|
57 | - 'translation_domain' => $this->translationDomain, |
|
58 | - 'required' => false |
|
59 | - ]); |
|
60 | - } |
|
61 | - }); |
|
62 | - } |
|
34 | + public function buildForm(FormBuilderInterface $builder, array $options) { |
|
35 | + $builder |
|
36 | + ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
|
37 | + /* @var $configurationValue ConfigurationValue */ |
|
38 | + $configurationValue = $event->getData(); |
|
39 | + $definition = $this->registry->get($configurationValue->getKey()); |
|
40 | + switch (get_class($definition)) { |
|
41 | + case EntityDefinition::class: |
|
42 | + /* @var $definition EntityDefinition */ |
|
43 | + $form = $event->getForm(); |
|
44 | + $form->add('value', EntityConfigurationValueType::class, [ |
|
45 | + 'class' => $definition->getClass(), |
|
46 | + 'choice_label' => $definition->getChoiceLabel(), |
|
47 | + 'label' => $this->translationPrefix . $configurationValue->getKey(), |
|
48 | + 'translation_domain' => $this->translationDomain, |
|
49 | + 'placeholder' => 'Please choose', |
|
50 | + 'empty_data' => null, |
|
51 | + 'required' => false |
|
52 | + ]); |
|
53 | + break; |
|
54 | + default: // assume StringDefinition |
|
55 | + $event->getForm()->add('value', TextType::class, [ |
|
56 | + 'label' => $this->translationPrefix . $configurationValue->getKey(), |
|
57 | + 'translation_domain' => $this->translationDomain, |
|
58 | + 'required' => false |
|
59 | + ]); |
|
60 | + } |
|
61 | + }); |
|
62 | + } |
|
63 | 63 | |
64 | - public function configureOptions(OptionsResolver $resolver) { |
|
65 | - $resolver->setDefault('data_class', ConfigurationValue::class); |
|
66 | - } |
|
64 | + public function configureOptions(OptionsResolver $resolver) { |
|
65 | + $resolver->setDefault('data_class', ConfigurationValue::class); |
|
66 | + } |
|
67 | 67 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function buildForm(FormBuilderInterface $builder, array $options) { |
35 | 35 | $builder |
36 | - ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
|
36 | + ->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) { |
|
37 | 37 | /* @var $configurationValue ConfigurationValue */ |
38 | 38 | $configurationValue = $event->getData(); |
39 | 39 | $definition = $this->registry->get($configurationValue->getKey()); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $form->add('value', EntityConfigurationValueType::class, [ |
45 | 45 | 'class' => $definition->getClass(), |
46 | 46 | 'choice_label' => $definition->getChoiceLabel(), |
47 | - 'label' => $this->translationPrefix . $configurationValue->getKey(), |
|
47 | + 'label' => $this->translationPrefix.$configurationValue->getKey(), |
|
48 | 48 | 'translation_domain' => $this->translationDomain, |
49 | 49 | 'placeholder' => 'Please choose', |
50 | 50 | 'empty_data' => null, |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | break; |
54 | 54 | default: // assume StringDefinition |
55 | 55 | $event->getForm()->add('value', TextType::class, [ |
56 | - 'label' => $this->translationPrefix . $configurationValue->getKey(), |
|
56 | + 'label' => $this->translationPrefix.$configurationValue->getKey(), |
|
57 | 57 | 'translation_domain' => $this->translationDomain, |
58 | 58 | 'required' => false |
59 | 59 | ]); |
@@ -9,50 +9,50 @@ |
||
9 | 9 | * @ORM\Entity() |
10 | 10 | */ |
11 | 11 | class ConfigurationValue { |
12 | - /** |
|
13 | - * @var string |
|
14 | - * |
|
15 | - * @ORM\Id() |
|
16 | - * @ORM\Column(name="`key`", nullable=false, type="string", length=64) |
|
17 | - * |
|
18 | - * @Assert\NotNull() |
|
19 | - * @Assert\NotBlank() |
|
20 | - * @Assert\Length(max="64") |
|
21 | - */ |
|
22 | - private $key; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string |
|
26 | - * |
|
27 | - * @ORM\Column(name="`value`", nullable=false, type="text") |
|
28 | - */ |
|
29 | - private $value; |
|
30 | - |
|
31 | - /** |
|
32 | - * @return string|null |
|
33 | - */ |
|
34 | - public function getKey() { |
|
35 | - return $this->key; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string|null $key |
|
40 | - */ |
|
41 | - public function setKey(string $key = null) { |
|
42 | - $this->key = $key; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string|null |
|
47 | - */ |
|
48 | - public function getValue() { |
|
49 | - return $this->value; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @param string|null $value |
|
54 | - */ |
|
55 | - public function setValue(string $value = null) { |
|
56 | - $this->value = $value; |
|
57 | - } |
|
12 | + /** |
|
13 | + * @var string |
|
14 | + * |
|
15 | + * @ORM\Id() |
|
16 | + * @ORM\Column(name="`key`", nullable=false, type="string", length=64) |
|
17 | + * |
|
18 | + * @Assert\NotNull() |
|
19 | + * @Assert\NotBlank() |
|
20 | + * @Assert\Length(max="64") |
|
21 | + */ |
|
22 | + private $key; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string |
|
26 | + * |
|
27 | + * @ORM\Column(name="`value`", nullable=false, type="text") |
|
28 | + */ |
|
29 | + private $value; |
|
30 | + |
|
31 | + /** |
|
32 | + * @return string|null |
|
33 | + */ |
|
34 | + public function getKey() { |
|
35 | + return $this->key; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string|null $key |
|
40 | + */ |
|
41 | + public function setKey(string $key = null) { |
|
42 | + $this->key = $key; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string|null |
|
47 | + */ |
|
48 | + public function getValue() { |
|
49 | + return $this->value; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @param string|null $value |
|
54 | + */ |
|
55 | + public function setValue(string $value = null) { |
|
56 | + $this->value = $value; |
|
57 | + } |
|
58 | 58 | } |
@@ -3,54 +3,54 @@ |
||
3 | 3 | namespace OneGuard\Bundle\DynamicConfigurationBundle; |
4 | 4 | |
5 | 5 | class DefinitionRegistry { |
6 | - /** |
|
7 | - * @var Definition[] |
|
8 | - */ |
|
9 | - private $definitions = []; |
|
10 | - |
|
11 | - /** |
|
12 | - * @param Definition $definition |
|
13 | - * @throws \InvalidArgumentException |
|
14 | - */ |
|
15 | - public function register(Definition $definition) { |
|
16 | - if (array_key_exists($definition->getKey(), $this->definitions)) { |
|
17 | - throw new \InvalidArgumentException('Definition already exists.'); |
|
18 | - } |
|
19 | - $this->definitions[$definition->getKey()] = $definition; |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @param string $key |
|
24 | - * @return Definition |
|
25 | - * @throws \InvalidArgumentException |
|
26 | - */ |
|
27 | - public function get(string $key) : Definition { |
|
28 | - if (!array_key_exists($key, $this->definitions)) { |
|
29 | - throw new \InvalidArgumentException('Definition not found.'); |
|
30 | - } |
|
31 | - return $this->definitions[$key]; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @param string $key |
|
36 | - * @return bool |
|
37 | - */ |
|
38 | - public function has(string $key) : bool { |
|
39 | - return array_key_exists($key, $this->definitions); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @return string[] |
|
44 | - */ |
|
45 | - public function keys() : array { |
|
46 | - return array_keys($this->definitions); |
|
47 | - } |
|
48 | - |
|
49 | - public function registerEntity($key, $class, $choiceLabel) { |
|
50 | - $this->register(new EntityDefinition($key, $class, $choiceLabel)); |
|
51 | - } |
|
52 | - |
|
53 | - public function registerString($key) { |
|
54 | - $this->register(new StringDefinition($key)); |
|
55 | - } |
|
6 | + /** |
|
7 | + * @var Definition[] |
|
8 | + */ |
|
9 | + private $definitions = []; |
|
10 | + |
|
11 | + /** |
|
12 | + * @param Definition $definition |
|
13 | + * @throws \InvalidArgumentException |
|
14 | + */ |
|
15 | + public function register(Definition $definition) { |
|
16 | + if (array_key_exists($definition->getKey(), $this->definitions)) { |
|
17 | + throw new \InvalidArgumentException('Definition already exists.'); |
|
18 | + } |
|
19 | + $this->definitions[$definition->getKey()] = $definition; |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @param string $key |
|
24 | + * @return Definition |
|
25 | + * @throws \InvalidArgumentException |
|
26 | + */ |
|
27 | + public function get(string $key) : Definition { |
|
28 | + if (!array_key_exists($key, $this->definitions)) { |
|
29 | + throw new \InvalidArgumentException('Definition not found.'); |
|
30 | + } |
|
31 | + return $this->definitions[$key]; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @param string $key |
|
36 | + * @return bool |
|
37 | + */ |
|
38 | + public function has(string $key) : bool { |
|
39 | + return array_key_exists($key, $this->definitions); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @return string[] |
|
44 | + */ |
|
45 | + public function keys() : array { |
|
46 | + return array_keys($this->definitions); |
|
47 | + } |
|
48 | + |
|
49 | + public function registerEntity($key, $class, $choiceLabel) { |
|
50 | + $this->register(new EntityDefinition($key, $class, $choiceLabel)); |
|
51 | + } |
|
52 | + |
|
53 | + public function registerString($key) { |
|
54 | + $this->register(new StringDefinition($key)); |
|
55 | + } |
|
56 | 56 | } |
@@ -5,25 +5,25 @@ |
||
5 | 5 | use Symfony\Bridge\Doctrine\RegistryInterface; |
6 | 6 | |
7 | 7 | class ConfigurationResolverFactory { |
8 | - /** |
|
9 | - * @var RegistryInterface |
|
10 | - */ |
|
11 | - private $doctrine; |
|
8 | + /** |
|
9 | + * @var RegistryInterface |
|
10 | + */ |
|
11 | + private $doctrine; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @var DefinitionRegistry |
|
15 | - */ |
|
16 | - private $registry; |
|
13 | + /** |
|
14 | + * @var DefinitionRegistry |
|
15 | + */ |
|
16 | + private $registry; |
|
17 | 17 | |
18 | - public function __construct(RegistryInterface $doctrine, DefinitionRegistry $registry) { |
|
19 | - $this->doctrine = $doctrine; |
|
20 | - $this->registry = $registry; |
|
21 | - } |
|
18 | + public function __construct(RegistryInterface $doctrine, DefinitionRegistry $registry) { |
|
19 | + $this->doctrine = $doctrine; |
|
20 | + $this->registry = $registry; |
|
21 | + } |
|
22 | 22 | |
23 | - public function create(string $key) { |
|
24 | - return new ConfigurationResolver( |
|
25 | - $this->doctrine, |
|
26 | - $this->registry->get($key) |
|
27 | - ); |
|
28 | - } |
|
23 | + public function create(string $key) { |
|
24 | + return new ConfigurationResolver( |
|
25 | + $this->doctrine, |
|
26 | + $this->registry->get($key) |
|
27 | + ); |
|
28 | + } |
|
29 | 29 | } |