1 | <?php |
||
23 | class AbstractFormDefinitionComponent |
||
24 | { |
||
25 | use MagicMethodsTrait { |
||
26 | handlePropertyMagicMethod as handlePropertyMagicMethodInternal; |
||
27 | } |
||
28 | use ParentsTrait { |
||
29 | attachParent as private attachParentInternal; |
||
30 | attachParents as private attachParentsInternal; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | private $parentsAttached = false; |
||
37 | |||
38 | /** |
||
39 | * This method is used by setter methods, and other methods which goal is to |
||
40 | * modify a property value. |
||
41 | * |
||
42 | * It checks that the definition is not frozen, and if it is actually frozen |
||
43 | * an exception is thrown. |
||
44 | * |
||
45 | * @throws PropertyNotAccessibleException |
||
46 | */ |
||
47 | protected function checkDefinitionFreezeState() |
||
48 | { |
||
49 | if ($this->isDefinitionFrozen()) { |
||
50 | $methodName = debug_backtrace()[1]['function']; |
||
51 | |||
52 | throw PropertyNotAccessibleException::formDefinitionFrozenMethod(get_class($this), $methodName); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return bool |
||
58 | */ |
||
59 | protected function isDefinitionFrozen() |
||
60 | { |
||
61 | return $this->getState() |
||
62 | && $this->getState()->isFrozen(); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return ConfigurationState |
||
67 | */ |
||
68 | protected function getState() |
||
69 | { |
||
70 | if ($this->hasParent(FormDefinition::class)) { |
||
71 | return $this->getFirstParent(FormDefinition::class)->getState(); |
||
72 | } elseif ($this->hasParent(Configuration::class)) { |
||
73 | return $this->getFirstParent(Configuration::class)->getState(); |
||
74 | } |
||
75 | |||
76 | return null; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Overrides the magic methods handling from the Configuration Object API. |
||
81 | * |
||
82 | * Blocks the parents feature once it has been used. |
||
83 | * |
||
84 | * @param object[] $parents |
||
85 | */ |
||
86 | public function attachParents(array $parents) |
||
93 | |||
94 | /** |
||
95 | * @see attachParents() |
||
96 | * |
||
97 | * @param object $parent |
||
98 | * @param bool $direct |
||
99 | */ |
||
100 | public function attachParent($parent, $direct = true) |
||
108 | |||
109 | /** |
||
110 | * Overrides the magic methods handling from the Configuration Object API: a |
||
111 | * magic setter method must be accessible only for this API, otherwise an |
||
112 | * exception must be thrown. |
||
113 | * |
||
114 | * @param string $property |
||
115 | * @param string $type |
||
116 | * @param array $arguments |
||
117 | * @return mixed |
||
118 | * @throws PropertyNotAccessibleException |
||
119 | */ |
||
120 | protected function handlePropertyMagicMethod($property, $type, array $arguments) |
||
131 | |||
132 | /** |
||
133 | * @param array $data |
||
134 | * @param string $property |
||
135 | * @param string $name |
||
136 | */ |
||
137 | protected static function forceNameForProperty(&$data, $property, $name = 'name') |
||
147 | } |
||
148 |