1 | <?php |
||
20 | class AbstractFormDefinition |
||
21 | { |
||
22 | use MagicMethodsTrait; |
||
23 | use ParentsTrait { |
||
24 | attachParent as private attachParentInternal; |
||
25 | attachParents as private attachParentsInternal; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $parentsAttached = false; |
||
32 | |||
33 | /** |
||
34 | * @todo |
||
35 | */ |
||
36 | protected function checkDefinitionFreezeState() |
||
42 | |||
43 | /** |
||
44 | * @return bool |
||
45 | */ |
||
46 | protected function isDefinitionFrozen() |
||
51 | |||
52 | /** |
||
53 | * @return FormDefinitionState |
||
54 | */ |
||
55 | protected function getDefinitionState() |
||
65 | |||
66 | /** |
||
67 | * @param object[] $parents |
||
68 | */ |
||
69 | public function attachParents(array $parents) |
||
76 | |||
77 | /** |
||
78 | * @param object $parent |
||
79 | * @param bool $direct |
||
80 | */ |
||
81 | public function attachParent($parent, $direct = true) |
||
87 | |||
88 | /** |
||
89 | * @todo |
||
90 | * |
||
91 | * @param mixed $name |
||
92 | * @param array $arguments |
||
93 | * @return mixed |
||
94 | * @throws MethodNotFoundException |
||
95 | */ |
||
96 | public function __call($name, $arguments) |
||
97 | { |
||
98 | if ($this->isDefinitionFrozen()) { |
||
99 | if ('get' !== substr($name, 0, 3)) { |
||
100 | $this->throwFrozenStateException(); |
||
101 | } |
||
102 | |||
103 | try { |
||
104 | $result = $this->handleMagicMethods($name, $arguments); |
||
105 | } catch (MethodNotFoundException $exception) { |
||
106 | throw $exception; |
||
107 | } |
||
108 | } else { |
||
109 | $result = $this->handleMagicMethods($name, $arguments); |
||
110 | } |
||
111 | |||
112 | return $result; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @todo |
||
117 | */ |
||
118 | private function throwFrozenStateException() |
||
122 | } |
||
123 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: