1
|
|
|
<?php |
2
|
|
|
namespace keeko\core\model\serializer; |
3
|
|
|
|
4
|
|
|
use keeko\framework\model\AbstractSerializer; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
*/ |
8
|
|
|
class CountrySerializer extends AbstractSerializer { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param mixed $model |
12
|
|
|
* @param array $fields |
13
|
|
|
*/ |
14
|
|
|
public function getAttributes($model, array $fields = null) { |
15
|
|
|
return [ |
16
|
|
|
'id' => $model->Id(), |
17
|
|
|
'numeric' => $model->Numeric(), |
18
|
|
|
'alpha_2' => $model->Alpha2(), |
19
|
|
|
'alpha_3' => $model->Alpha3(), |
20
|
|
|
'short_name' => $model->ShortName(), |
21
|
|
|
'ioc' => $model->Ioc(), |
22
|
|
|
'tld' => $model->Tld(), |
23
|
|
|
'phone' => $model->Phone(), |
24
|
|
|
'capital' => $model->Capital(), |
25
|
|
|
'postal_code_format' => $model->PostalCodeFormat(), |
26
|
|
|
'postal_code_regex' => $model->PostalCodeRegex(), |
27
|
|
|
'continent_id' => $model->ContinentId(), |
28
|
|
|
'currency_id' => $model->CurrencyId(), |
29
|
|
|
'type_id' => $model->TypeId(), |
30
|
|
|
'subtype_id' => $model->SubtypeId(), |
31
|
|
|
'sovereignity_id' => $model->SovereignityId(), |
32
|
|
|
'formal_name' => $model->FormalName(), |
33
|
|
|
'formal_native_name' => $model->FormalNativeName(), |
34
|
|
|
'short_native_name' => $model->ShortNativeName(), |
35
|
|
|
'bbox_sw_lat' => $model->BboxSwLat(), |
36
|
|
|
'bbox_sw_lng' => $model->BboxSwLng(), |
37
|
|
|
'bbox_ne_lat' => $model->BboxNeLat(), |
38
|
|
|
'bbox_ne_lng' => $model->BboxNeLng(), |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
*/ |
44
|
|
|
public function getFields() { |
45
|
|
|
return ['id', 'numeric', 'alpha_2', 'alpha_3', 'short_name', 'ioc', 'tld', 'phone', 'capital', 'postal_code_format', 'postal_code_regex', 'continent_id', 'currency_id', 'type_id', 'subtype_id', 'sovereignity_id', 'formal_name', 'formal_native_name', 'short_native_name', 'bbox_sw_lat', 'bbox_sw_lng', 'bbox_ne_lat', 'bbox_ne_lng']; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param mixed $model |
50
|
|
|
*/ |
51
|
|
|
public function getId($model) { |
|
|
|
|
52
|
|
|
return $model->getId(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
*/ |
57
|
|
|
public function getSortFields() { |
58
|
|
|
return ['id', 'numeric', 'alpha_2', 'alpha_3', 'short_name', 'ioc', 'tld', 'phone', 'capital', 'postal_code_format', 'postal_code_regex', 'continent_id', 'currency_id', 'type_id', 'subtype_id', 'sovereignity_id', 'formal_name', 'formal_native_name', 'short_native_name', 'bbox_sw_lat', 'bbox_sw_lng', 'bbox_ne_lat', 'bbox_ne_lng']; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param mixed $model |
63
|
|
|
*/ |
64
|
|
|
public function getType($model) { |
65
|
|
|
return 'core/country'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param mixed $model |
70
|
|
|
* @param mixed $data |
71
|
|
|
*/ |
72
|
|
|
public function hydrate($model, $data) { |
73
|
|
|
// this model is read-only! |
74
|
|
|
return $model; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.