Configuration::configureOptions()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace JK\Sam\Configuration;
4
5
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
/**
9
 * Abstract configuration class.
10
 */
11
abstract class Configuration implements ConfigurationInterface
12
{
13
    /**
14
     * @var ParameterBag
15
     */
16
    protected $parameters;
17
18
    /**
19
     * Configuration constructor.
20
     */
21 2
    public function __construct()
22
    {
23 2
        $this->parameters = new ParameterBag();
24 2
    }
25
26
    /**
27
     * Define allowed parameters and values for this configuration, using optionsResolver component.
28
     *
29
     * @param OptionsResolver $resolver
30
     */
31
    abstract public function configureOptions(OptionsResolver $resolver);
32
33
    /**
34
     * Return true if the parameter exists.
35
     *
36
     * @param string $name
37
     * @return bool
38
     */
39 1
    public function hasParameter($name)
40
    {
41
        return $this
42 1
            ->parameters
43 1
            ->has($name);
44
    }
45
46
    /**
47
     * Return the parameter value.
48
     *
49
     * @param string $name
50
     * @return mixed
51
     */
52 2
    public function getParameter($name)
53
    {
54
        return $this
55 2
            ->parameters
56 2
            ->get($name);
57
    }
58
59
    /**
60
     * Define all resolved parameters values.
61
     *
62
     * @param array $parameters
63
     */
64 2
    public function setParameters(array $parameters)
65
    {
66 2
        $this->parameters = new ParameterBag($parameters);
67 2
    }
68
69
    /**
70
     * Return all parameters.
71
     *
72
     * @return array
73
     */
74 1
    public function getParameters()
75
    {
76
        return $this
77 1
            ->parameters
78 1
            ->all();
79
    }
80
}
81