Completed
Pull Request — master (#116)
by Arnaud
05:17
created

FieldConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LAG\AdminBundle\Configuration;
4
5
use JK\Configuration\Configuration;
6
use Symfony\Component\OptionsResolver\Options;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
class FieldConfiguration extends Configuration
10
{
11
    /**
12
     * @var array
13
     */
14
    private $allowedFields;
15
16
    public function __construct(array $allowedFields = [])
17
    {
18
        $this->allowedFields = $allowedFields;
19
20
        parent::__construct();
21
    }
22
23
    public function configureOptions(OptionsResolver $resolver): void
24
    {
25
        $resolver
26
            ->setDefaults([
27
                'type' => null,
28
                'options' => [],
29
            ])
30
            // Set allowed fields type from tagged services
31
            ->setAllowedValues('type', $this->allowedFields)
32
            ->setAllowedTypes('type', 'string')
33
            ->setAllowedTypes('options', 'array')
34
            ->setNormalizer('type', function (Options $options, $value) {
35
                if (null === $value) {
36
                    $value = '';
37
                }
38
39
                return $value;
40
            })
41
        ;
42
    }
43
44
    public function getType(): string
45
    {
46
        return $this->get('type');
47
    }
48
49
    public function getOptions(): array
50
    {
51
        return $this->get('options');
52
    }
53
}
54