1 | <?php |
||
16 | abstract class AbstractObject implements JsonSerializable |
||
17 | { |
||
18 | /** |
||
19 | * Construct an object from the corresponding row of a bound database table |
||
20 | * |
||
21 | * @param array $databaseRecord Associative array of fields |
||
22 | * |
||
23 | * @uses Object::validateParams() |
||
24 | * |
||
25 | * @throws ObjectException If an empty database record is provided |
||
26 | */ |
||
27 | 20 | public function __construct($databaseRecord) |
|
33 | |||
34 | /** |
||
35 | * Validate (and filter) a row of database information before applying it to the object |
||
36 | * |
||
37 | * @param array $databaseRow Associative array |
||
38 | * @return array Filtered and validated |
||
39 | * @throws ObjectException If no parameters are provided |
||
40 | */ |
||
41 | 20 | protected function validateParams($databaseRow) |
|
42 | { |
||
43 | /* TODO Convert MySQL timestamp to SOAP timestamp for portability */ |
||
44 | 20 | if (is_array($databaseRow)) { |
|
45 | 19 | return $databaseRow; |
|
46 | } else { |
||
47 | 3 | throw new ObjectException( |
|
48 | 3 | 'No parameters provided to from which construct object', |
|
49 | 3 | ObjectException::MISSING_DATABASE_RECORD |
|
50 | ); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Prepare the object for JSON serialization |
||
56 | * |
||
57 | * @see JsonSerializable::jsonSerialize() |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | 8 | public function jsonSerialize() |
|
65 | } |
||
66 |