1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FSi\Bundle\AdminBundle\Admin; |
11
|
|
|
|
12
|
|
|
use FSi\Bundle\AdminBundle\Exception\MissingOptionException; |
13
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Norbert Orzechowicz <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractElement implements Element |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
private $options; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private $unresolvedOptions; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param array $options |
32
|
|
|
*/ |
33
|
|
|
public function __construct(array $options = []) |
34
|
|
|
{ |
35
|
|
|
$this->unresolvedOptions = $options; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function getRouteParameters() |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
'element' => $this->getId(), |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getOption($name) |
52
|
|
|
{ |
53
|
|
|
$this->initOptions(); |
54
|
|
|
if (!$this->hasOption($name)) { |
55
|
|
|
throw new MissingOptionException(sprintf('Option with name: "%s" does\'t exists.', $name)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $this->options[$name]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function getOptions() |
65
|
|
|
{ |
66
|
|
|
$this->initOptions(); |
67
|
|
|
return $this->options; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function hasOption($name) |
74
|
|
|
{ |
75
|
|
|
$this->initOptions(); |
76
|
|
|
return isset($this->options[$name]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function initOptions() |
80
|
|
|
{ |
81
|
|
|
if (!is_array($this->options)) { |
82
|
|
|
$optionsResolver = new OptionsResolver(); |
83
|
|
|
$this->setDefaultOptions($optionsResolver); |
84
|
|
|
$this->options = $optionsResolver->resolve($this->unresolvedOptions); |
85
|
|
|
unset($this->unresolvedOptions); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|