1
|
|
|
<?php |
2
|
|
|
namespace keeko\core\serializer\base; |
3
|
|
|
|
4
|
|
|
use keeko\framework\utils\HydrateUtils; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
*/ |
8
|
|
|
trait ApplicationSerializerTrait { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param mixed $model |
12
|
|
|
* @param array $fields |
13
|
|
|
*/ |
14
|
|
|
public function getAttributes($model, array $fields = null) { |
|
|
|
|
15
|
|
|
return [ |
16
|
|
|
'class_name' => $model->ClassName(), |
17
|
|
|
'id' => $model->Id(), |
18
|
|
|
'name' => $model->Name(), |
19
|
|
|
'title' => $model->Title(), |
20
|
|
|
'description' => $model->Description(), |
21
|
|
|
'installed_version' => $model->InstalledVersion(), |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
*/ |
27
|
|
|
public function getFields() { |
28
|
|
|
return ['class_name', 'id', 'name', 'title', 'description', 'installed_version']; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param mixed $model |
33
|
|
|
*/ |
34
|
|
|
public function getId($model) { |
|
|
|
|
35
|
|
|
return $model->getId(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
*/ |
40
|
|
|
public function getRelationships() { |
41
|
|
|
return [ |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
*/ |
47
|
|
|
public function getSortFields() { |
48
|
|
|
return ['class_name', 'id', 'name', 'title', 'description', 'installed_version']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param mixed $model |
53
|
|
|
*/ |
54
|
|
|
public function getType($model) { |
|
|
|
|
55
|
|
|
return 'core/application'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param mixed $model |
60
|
|
|
* @param mixed $data |
61
|
|
|
*/ |
62
|
|
|
public function hydrate($model, $data) { |
|
|
|
|
63
|
|
|
// attributes |
64
|
|
|
$attribs = isset($data['attributes']) ? $data['attributes'] : []; |
65
|
|
|
|
66
|
|
|
$model = HydrateUtils::hydrate($attribs, $model, ['class_name', 'id', 'name', 'title', 'description', 'installed_version']); |
67
|
|
|
|
68
|
|
|
// relationships |
69
|
|
|
$this->hydrateRelationships($model, $data); |
|
|
|
|
70
|
|
|
|
71
|
|
|
return $model; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.