1 | 2 | simandl | <?php |
2 | | | |
3 | | | namespace Phem\Libraries\UI\Model; |
4 | | | |
5 | | | use Doctrine\Common\Annotations\AnnotationReader; |
6 | | | use Phem\Core\Collection; |
7 | | | use Phem\Core\Object; |
8 | | | use Phem\Environment\EnvironmentManager; |
9 | | | use Phem\Libraries\UI\Annotations\ContentAttr; |
10 | | | use Phem\Libraries\UI\Annotations\DomAttr; |
11 | | | use Phem\Libraries\UI\Annotations\NoUpdateAttr; |
12 | | | use Phem\Libraries\UI\Annotations\StyleAttr; |
13 | | | use Phem\ToolSuite; |
14 | | | use Ratchet\Wamp\Exception; |
15 | | | use ReflectionProperty; |
16 | | | |
17 | | | /** |
18 | | | * @author Jakub PetrĹžĂlka <petrzilka@czweb.net> |
19 | | | */ |
20 | | | abstract class Control extends Component |
21 | | | { |
22 | | | protected $name; |
23 | | | protected $id; |
24 | | | protected $classes; |
25 | | | protected $parent; |
26 | | | |
27 | | | |
28 | | | /** |
29 | | | * @var Position |
30 | | | */ |
31 | | | protected $position; |
32 | | | |
33 | | | /** |
34 | | | * @var Size |
35 | | | */ |
36 | | | protected $size; |
37 | | | |
38 | | | public abstract function getValue(); |
39 | | | |
40 | | | protected abstract function setValue($value); |
41 | | | |
42 | | | function __construct($parent) |
43 | | | { |
44 | | | $this->parent = $parent; |
45 | | | $this->position = new Position(); |
46 | | | $this->size = new Size(); |
47 | | | $this->classes = new Collection(); |
48 | | | } |
49 | | | |
50 | | | /* public function __call($method, $args) |
51 | | | { |
52 | | | if(method_exists($this, $method)) |
53 | | | { |
54 | | | call_user_func_array(array($this,$method), $args); |
55 | | | if ((ToolSuite::startsWith($method, 'set') !== false)&&($method != "setValue")) |
56 | | | { |
57 | | | $attrName = lcfirst(substr($method, 3)); |
58 | | | |
59 | | | $reflectionProp = new ReflectionProperty($this,$attrName); |
60 | | | |
61 | | | $annotationReader = new AnnotationReader(); |
62 | | | $propAnnotations = $annotationReader |
63 | | | ->getPropertyAnnotations($reflectionProp); |
64 | | | |
65 | | | $foundAnnotations = new Collection(); |
66 | | | |
67 | | | foreach ($propAnnotations as $annotation) |
68 | | | { |
69 | | | if (($annotation instanceof NoUpdateAttr) |
70 | | | ||($annotation instanceof DomAttr) |
71 | | | ||($annotation instanceof ContentAttr) |
72 | | | ||($annotation instanceof StyleAttr)) |
73 | | | { |
74 | | | $foundAnnotations->add($annotation); |
75 | | | } |
76 | | | } |
77 | | | |
78 | | | if ($foundAnnotations->count() > 1) |
79 | | | { |
80 | | | throw new Exception(get_class($this) . "::" . $method . |
81 | | | "() - attribute must have either 0 or 1 annotation from NoUpdateAttr, DomAttr, ContentAttr, StyleAttr"); |
82 | | | } |
83 | | | else if ($foundAnnotations->count() == 1) |
84 | | | { |
85 | | | $annotation = $foundAnnotations->getFirst(); |
86 | | | |
87 | | | if ($annotation instanceof NoUpdateAttr) |
88 | | | { |
89 | | | return; |
90 | | | } |
91 | | | |
92 | | | $change = new Change(); |
93 | | | $change->setAttrName($annotation->name); |
94 | | | $change->setData($args[0]); |
95 | | | $change->setObjectName($this->getFullName()); |
96 | | | |
97 | | | if ($annotation instanceof StyleAttr) |
98 | | | { |
99 | | | $change->setType(ChangeType::CHANGE_STYLE); |
100 | | | } |
101 | | | else if ($annotation instanceof DomAttr) |
102 | | | { |
103 | | | |
104 | | | $change->setType(ChangeType::CHANGE_ATTR); |
105 | | | } |
106 | | | else if ($annotation instanceof ContentAttr) |
107 | | | { |
108 | | | $change->setType(ChangeType::UPDATE_CONTENT); |
109 | | | } |
110 | | | } |
111 | | | else |
112 | | | { |
113 | | | $twig = EnvironmentManager::getTwig(); |
114 | | | $data = $twig->render('@Phem/UI/' . $this->getType() . '.twig',array("control"=>$this)); |
115 | | | |
116 | | | $change = new Change(); |
117 | | | $change->setType(ChangeType::REPLACE); |
118 | | | $change->setData($data); |
119 | | | $change->setObjectName($this->getFullName()); |
120 | | | } |
121 | | | |
122 | | | $this->getWorkspace()->getChanges()->put($this->getFullName()."_".$attrName,$change); |
123 | | | } |
124 | | | } |
125 | | | } */ |
126 | | | |
127 | | | public function getType() |
128 | | | { |
129 | | | return ToolSuite::getRelativeClassName($this); |
130 | | | } |
131 | | | |
132 | | | public function getTemplateName() |
133 | | | { |
134 | | | return $this->getType(); |
135 | | | } |
136 | | | |
137 | | | public function getWorkspace() |
138 | | | { |
139 | | | $parent = $this; |
140 | | | while (!is_a($parent, '\Phem\Libraries\UI\Model\Workspace')) |
141 | | | { |
142 | | | $parent = $parent->getParent(); |
143 | | | } |
144 | | | return $parent; |
145 | | | } |
146 | | | |
147 | | | public function getName() |
148 | | | { |
149 | | | return $this->name; |
150 | | | } |
151 | | | |
152 | | | protected function setName($name) |
153 | | | { |
154 | | | $this->name = $name; |
155 | | | } |
156 | | | |
157 | | | public function getId() |
158 | | | { |
159 | | | return $this->id; |
160 | | | } |
161 | | | |
162 | | | public function setId($id) |
163 | | | { |
164 | | | $this->id = $id; |
165 | | | } |
166 | | | |
167 | | | public function getClasses() |
168 | | | { |
169 | | | return $this->classes; |
170 | | | } |
171 | | | |
172 | | | public function setClasses($classes) |
173 | | | { |
174 | | | $this->classes = $classes; |
175 | | | } |
176 | | | |
177 | | | public function getPosition() |
178 | | | { |
179 | | | return $this->position; |
180 | | | } |
181 | | | |
182 | | | protected function setPosition(Position $position) |
183 | | | { |
184 | | | $this->position = $position; |
185 | | | } |
186 | | | |
187 | | | public function getSize() |
188 | | | { |
189 | | | return $this->size; |
190 | | | } |
191 | | | |
192 | | | protected function setSize(Size $size) |
193 | | | { |
194 | | | $this->size = $size; |
195 | | | } |
196 | | | |
197 | | | public function getParent() |
198 | | | { |
199 | | | return $this->parent; |
200 | | | } |
201 | | | |
202 | | | } |