1 | <?php |
||
21 | class EntityModel { |
||
22 | /** |
||
23 | * Service to work with rows |
||
24 | * |
||
25 | * ALL DB ACCESS SHOULD BE DONE VIA ROW OPERATOR! NO DIRECT ACCESS TO DB IS ALLOWED! |
||
26 | * |
||
27 | * @var \DbRowDirectOperator $rowOperator |
||
28 | */ |
||
29 | protected $rowOperator; |
||
30 | /** |
||
31 | * Name of table for this entity |
||
32 | * |
||
33 | * @var string $tableName |
||
34 | */ |
||
35 | protected $tableName = '_table'; |
||
36 | |||
37 | /** |
||
38 | * Name of key field field in this table |
||
39 | * |
||
40 | * @var string $idFieldName |
||
41 | */ |
||
42 | // TODO - remove |
||
43 | protected $idFieldName = 'id'; |
||
44 | |||
45 | /** |
||
46 | * Name of exception class that would be thrown |
||
47 | * |
||
48 | * Uses for calling when you don't know which exact exception should be called |
||
49 | * On Entity\EntityModel's children should be used exception class name |
||
50 | * |
||
51 | * @var string $exceptionClass |
||
52 | */ |
||
53 | protected $exceptionClass = 'Entity\EntityException'; |
||
54 | protected $entityContainerClass = '\Entity\EntityContainer'; |
||
55 | |||
56 | /** |
||
57 | * Property list and description |
||
58 | * |
||
59 | * propertyName => array( |
||
60 | * P_DB_FIELD => 'dbFieldName', - directly converts property to field and vice versa |
||
61 | * ) |
||
62 | * |
||
63 | * @var array[] $properties |
||
64 | */ |
||
65 | protected $properties = array(); |
||
66 | |||
67 | /** |
||
68 | * @var \Common\Accessors $accessors |
||
69 | */ |
||
70 | protected $accessors; |
||
71 | |||
72 | |||
73 | /** |
||
74 | * Entity\EntityModel constructor. |
||
75 | * |
||
76 | * @param \Common\GlobalContainer $gc |
||
77 | */ |
||
78 | public function __construct($gc) { |
||
83 | |||
84 | /** |
||
85 | * @param EntityContainer $that |
||
86 | * @param string $accessor |
||
87 | */ |
||
88 | protected function processRow($that, $accessor) { |
||
103 | |||
104 | /** |
||
105 | * Import DB row state into object properties |
||
106 | * |
||
107 | * @param EntityContainer $cEntity |
||
108 | * @param array $row |
||
109 | */ |
||
110 | public function importRow($cEntity, $row) { |
||
118 | |||
119 | /** |
||
120 | * @param array $array |
||
121 | * |
||
122 | * @return EntityContainer |
||
123 | */ |
||
124 | public function fromArray($array) { |
||
133 | |||
134 | /** |
||
135 | * Exports object properties to DB row state with ID |
||
136 | * |
||
137 | * @param EntityContainer $cEntity |
||
138 | */ |
||
139 | public function exportRow($cEntity) { |
||
143 | |||
144 | /** |
||
145 | * @return EntityContainer |
||
146 | */ |
||
147 | public function buildContainer() { |
||
155 | |||
156 | |||
157 | /** |
||
158 | * @param EntityContainer $cEntity |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function isEmpty($cEntity) { |
||
165 | |||
166 | /** |
||
167 | * @param EntityContainer $cEntity |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | // TODO - Loaded flag ????? |
||
172 | public function isNew($cEntity) { |
||
175 | |||
176 | |||
177 | // /** |
||
178 | // * Clears only properties which declared in $properties array |
||
179 | // * |
||
180 | // * @param EntityContainer $cEntity |
||
181 | // */ |
||
182 | // public function clearProperties($cEntity) { |
||
183 | // foreach ($this->properties as $propertyName => $propertyData) { |
||
184 | // unset($cEntity->$propertyName); |
||
185 | // } |
||
186 | // } |
||
187 | |||
188 | |||
189 | /** |
||
190 | * @return \DbRowDirectOperator |
||
191 | */ |
||
192 | public function getRowOperator() { |
||
195 | |||
196 | /** |
||
197 | * @param string $value |
||
198 | */ |
||
199 | public function setTableName($value) { |
||
202 | |||
203 | /** |
||
204 | * Gets entity's table name |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | public function getTableName() { |
||
211 | |||
212 | // /** |
||
213 | // * @param string $value |
||
214 | // */ |
||
215 | // public function setIdFieldName($value) { |
||
216 | // $this->idField = $value; |
||
217 | // } |
||
218 | // /** |
||
219 | // * Gets entity's DB ID field name (which is unique within entity set) |
||
220 | // * |
||
221 | // * @return string |
||
222 | // */ |
||
223 | // public function getIdFieldName() { |
||
224 | // return $this->idField; |
||
225 | // } |
||
226 | |||
227 | /** |
||
228 | * @return array[] |
||
229 | */ |
||
230 | public function getProperties() { |
||
233 | |||
234 | /** |
||
235 | * @param $array |
||
236 | */ |
||
237 | public function extendProperties($array) { |
||
240 | |||
241 | /** |
||
242 | * @return \Common\Accessors |
||
243 | */ |
||
244 | public function getAccessors() { |
||
247 | |||
248 | } |
||
249 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.