1 | <?php |
||
21 | class Entity |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * The definition how this entity looks like. |
||
26 | * @var EntityDefinition |
||
27 | */ |
||
28 | protected $definition; |
||
29 | |||
30 | /** |
||
31 | * Holds the key value data of the entity. |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $entity; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Converts a given value to the given type. |
||
39 | * |
||
40 | * @param mixed $value |
||
41 | * the value to convert |
||
42 | * @param string $type |
||
43 | * the type to convert to like 'integer' or 'float' |
||
44 | * |
||
45 | * @return mixed |
||
46 | * the converted value |
||
47 | */ |
||
48 | 35 | protected function toType($value, $type) |
|
59 | |||
60 | |||
61 | /** |
||
62 | * Constructor. |
||
63 | * |
||
64 | * @param EntityDefinition $definition |
||
65 | * the definition how this entity looks |
||
66 | */ |
||
67 | 39 | public function __construct(EntityDefinition $definition) |
|
72 | |||
73 | /** |
||
74 | * Sets a field value pair of this entity. |
||
75 | * |
||
76 | * @param string $field |
||
77 | * the field |
||
78 | * @param mixed $value |
||
79 | * the value |
||
80 | */ |
||
81 | 39 | public function set($field, $value) |
|
85 | |||
86 | /** |
||
87 | * Gets the raw value of a field no matter what type it is. |
||
88 | * This is usefull for input validation for example. |
||
89 | * |
||
90 | * @param string $field |
||
91 | * the field |
||
92 | * |
||
93 | * @return mixed |
||
94 | * null on invalid field or else the raw value |
||
95 | */ |
||
96 | 6 | public function getRaw($field) |
|
103 | |||
104 | /** |
||
105 | * Gets the value of a field in its specific type. |
||
106 | * |
||
107 | * @param string $field |
||
108 | * the field |
||
109 | * |
||
110 | * @return mixed |
||
111 | * null on invalid field, an integer if the definition says that the |
||
112 | * type of the field is an integer, a boolean if the field is a boolean or |
||
113 | * else the raw value |
||
114 | */ |
||
115 | 35 | public function get($field) |
|
128 | |||
129 | /** |
||
130 | * Gets the entity definition. |
||
131 | * |
||
132 | * @return EntityDefinition |
||
133 | * the definition |
||
134 | */ |
||
135 | 12 | public function getDefinition() |
|
139 | |||
140 | /** |
||
141 | * Populates the entities fields from the requests parameters. |
||
142 | * |
||
143 | * @param Request $request |
||
144 | * the request to take the field data from |
||
145 | */ |
||
146 | 5 | public function populateViaRequest(Request $request) |
|
175 | |||
176 | } |
||
177 |