@@ -16,19 +16,19 @@ |
||
16 | 16 | */ |
17 | 17 | class GeometryFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string: location |
|
21 | - */ |
|
22 | - const LOCATION = 'location'; |
|
19 | + /** |
|
20 | + * string: location |
|
21 | + */ |
|
22 | + const LOCATION = 'location'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * string: location_type |
|
26 | - */ |
|
27 | - const LOCATION_TYPE = 'location_type'; |
|
24 | + /** |
|
25 | + * string: location_type |
|
26 | + */ |
|
27 | + const LOCATION_TYPE = 'location_type'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * string: viewport |
|
31 | - */ |
|
32 | - const VIEWPORT = 'viewport'; |
|
29 | + /** |
|
30 | + * string: viewport |
|
31 | + */ |
|
32 | + const VIEWPORT = 'viewport'; |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -16,44 +16,44 @@ |
||
16 | 16 | */ |
17 | 17 | class GoogleMapsResultFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string address_components |
|
21 | - */ |
|
22 | - const ADDRESS_COMPONENTS = 'address_components'; |
|
23 | - |
|
24 | - /** |
|
25 | - * string formatted_address |
|
26 | - */ |
|
27 | - const FORMATTED_ADDRESS = 'formatted_address'; |
|
28 | - |
|
29 | - /** |
|
30 | - * string geometry |
|
31 | - */ |
|
32 | - const GEOMETRY = 'geometry'; |
|
33 | - |
|
34 | - /** |
|
35 | - * string viewport |
|
36 | - */ |
|
37 | - const VIEWPORT = 'viewport'; |
|
38 | - |
|
39 | - /** |
|
40 | - * string place_id |
|
41 | - */ |
|
42 | - const PLACE_ID = 'place_id'; |
|
43 | - |
|
44 | - /** |
|
45 | - * string location_type |
|
46 | - */ |
|
47 | - const LOCATION_TYPE = 'location_type'; |
|
48 | - |
|
49 | - /** |
|
50 | - * string types |
|
51 | - */ |
|
52 | - const TYPES = 'types'; |
|
53 | - |
|
54 | - /** |
|
55 | - * string location |
|
56 | - */ |
|
57 | - const LOCATION = 'location'; |
|
19 | + /** |
|
20 | + * string address_components |
|
21 | + */ |
|
22 | + const ADDRESS_COMPONENTS = 'address_components'; |
|
23 | + |
|
24 | + /** |
|
25 | + * string formatted_address |
|
26 | + */ |
|
27 | + const FORMATTED_ADDRESS = 'formatted_address'; |
|
28 | + |
|
29 | + /** |
|
30 | + * string geometry |
|
31 | + */ |
|
32 | + const GEOMETRY = 'geometry'; |
|
33 | + |
|
34 | + /** |
|
35 | + * string viewport |
|
36 | + */ |
|
37 | + const VIEWPORT = 'viewport'; |
|
38 | + |
|
39 | + /** |
|
40 | + * string place_id |
|
41 | + */ |
|
42 | + const PLACE_ID = 'place_id'; |
|
43 | + |
|
44 | + /** |
|
45 | + * string location_type |
|
46 | + */ |
|
47 | + const LOCATION_TYPE = 'location_type'; |
|
48 | + |
|
49 | + /** |
|
50 | + * string types |
|
51 | + */ |
|
52 | + const TYPES = 'types'; |
|
53 | + |
|
54 | + /** |
|
55 | + * string location |
|
56 | + */ |
|
57 | + const LOCATION = 'location'; |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -16,28 +16,28 @@ |
||
16 | 16 | */ |
17 | 17 | class GoogleMapsRequestFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string: key |
|
21 | - */ |
|
22 | - const KEY = 'key'; |
|
19 | + /** |
|
20 | + * string: key |
|
21 | + */ |
|
22 | + const KEY = 'key'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * string: sensor |
|
26 | - */ |
|
27 | - const SENSOR = 'sensor'; |
|
24 | + /** |
|
25 | + * string: sensor |
|
26 | + */ |
|
27 | + const SENSOR = 'sensor'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * string: latlng |
|
31 | - */ |
|
32 | - const LATLNG = 'latlng'; |
|
29 | + /** |
|
30 | + * string: latlng |
|
31 | + */ |
|
32 | + const LATLNG = 'latlng'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * string: address |
|
36 | - */ |
|
37 | - const ADDRESS = 'address'; |
|
34 | + /** |
|
35 | + * string: address |
|
36 | + */ |
|
37 | + const ADDRESS = 'address'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * string: place_id |
|
41 | - */ |
|
42 | - const PLACE_ID = 'place_id'; |
|
39 | + /** |
|
40 | + * string: place_id |
|
41 | + */ |
|
42 | + const PLACE_ID = 'place_id'; |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -16,13 +16,13 @@ |
||
16 | 16 | */ |
17 | 17 | class LatLngBoundsFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string : northeast |
|
21 | - */ |
|
22 | - const NORTHEAST = 'northeast'; |
|
19 | + /** |
|
20 | + * string : northeast |
|
21 | + */ |
|
22 | + const NORTHEAST = 'northeast'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * string : southwest |
|
26 | - */ |
|
27 | - const SOUTHWEST = 'southwest'; |
|
24 | + /** |
|
25 | + * string : southwest |
|
26 | + */ |
|
27 | + const SOUTHWEST = 'southwest'; |
|
28 | 28 | } |
29 | 29 | \ No newline at end of file |
@@ -16,19 +16,19 @@ |
||
16 | 16 | */ |
17 | 17 | class AddressComponentFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string: long_name |
|
21 | - */ |
|
22 | - const LONG_NAME = 'long_name'; |
|
19 | + /** |
|
20 | + * string: long_name |
|
21 | + */ |
|
22 | + const LONG_NAME = 'long_name'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * string: short_name |
|
26 | - */ |
|
27 | - const SHORT_NAME = 'short_name'; |
|
24 | + /** |
|
25 | + * string: short_name |
|
26 | + */ |
|
27 | + const SHORT_NAME = 'short_name'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * string: types |
|
31 | - */ |
|
32 | - const TYPES = 'types'; |
|
29 | + /** |
|
30 | + * string: types |
|
31 | + */ |
|
32 | + const TYPES = 'types'; |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -16,19 +16,19 @@ |
||
16 | 16 | */ |
17 | 17 | class GoogleMapsResponseFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string: results |
|
21 | - */ |
|
22 | - const RESULTS = 'results'; |
|
19 | + /** |
|
20 | + * string: results |
|
21 | + */ |
|
22 | + const RESULTS = 'results'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * string: status |
|
26 | - */ |
|
27 | - const STATUS = 'status'; |
|
24 | + /** |
|
25 | + * string: status |
|
26 | + */ |
|
27 | + const STATUS = 'status'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * string: error_message |
|
31 | - */ |
|
32 | - const ERROR_MESSAGE = 'error_message'; |
|
29 | + /** |
|
30 | + * string: error_message |
|
31 | + */ |
|
32 | + const ERROR_MESSAGE = 'error_message'; |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -16,13 +16,13 @@ |
||
16 | 16 | */ |
17 | 17 | class LatLngFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string - latitude |
|
21 | - */ |
|
22 | - const LAT = 'lat'; |
|
19 | + /** |
|
20 | + * string - latitude |
|
21 | + */ |
|
22 | + const LAT = 'lat'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * string - longitude |
|
26 | - */ |
|
27 | - const LNG = 'lng'; |
|
24 | + /** |
|
25 | + * string - longitude |
|
26 | + */ |
|
27 | + const LNG = 'lng'; |
|
28 | 28 | } |
29 | 29 | \ No newline at end of file |
@@ -19,158 +19,158 @@ |
||
19 | 19 | */ |
20 | 20 | abstract class AbstractObject { |
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $typeCheck = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $required = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $errors = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * AbstractObject constructor. |
|
39 | - * |
|
40 | - * @param array $args |
|
41 | - */ |
|
42 | - public function __construct(?array $args = []) { |
|
43 | - |
|
44 | - $this->setArgs($args); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @param array $args |
|
49 | - * |
|
50 | - * @throws Exception |
|
51 | - */ |
|
52 | - protected function setArgs(array $args) { |
|
53 | - |
|
54 | - foreach ($this->typeCheck as $field_name => $field_type) { |
|
55 | - if (empty($args[$field_name]) || is_null($args[$field_name])) { |
|
56 | - if ($this->isFieldRequired($field_name)) { |
|
57 | - $this->addError('Missing "' . $field_name . '" in ' . static::class); |
|
58 | - } |
|
59 | - } else { |
|
60 | - $this->$field_name = $this->parseFieldValue($field_type, $args[$field_name]); |
|
61 | - } |
|
62 | - } |
|
63 | - $this->throwErrors(); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param string $field_name |
|
68 | - * |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - protected function isFieldRequired(string $field_name): bool { |
|
72 | - |
|
73 | - return in_array($field_name, $this->required); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $error |
|
78 | - * |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function addError(string $error): array { |
|
82 | - |
|
83 | - array_push($this->errors, $error); |
|
84 | - |
|
85 | - return $this->errors; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $field_type |
|
90 | - * @param string $field_value |
|
91 | - * |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - protected function parseFieldValue(string $field_type, $field_value) { |
|
95 | - |
|
96 | - switch ($field_type) { |
|
97 | - case 'string': |
|
98 | - case 'int': |
|
99 | - case 'float': |
|
100 | - case 'array': |
|
101 | - return $field_value; |
|
102 | - default: |
|
103 | - return ($field_value instanceof $field_type) ? $field_value : new $field_type($field_value); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @throws Exception |
|
109 | - */ |
|
110 | - protected function throwErrors() { |
|
111 | - |
|
112 | - if (count($this->errors)) { |
|
113 | - throw new Exception(implode(', ', $this->errors)); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function toJson(): string { |
|
121 | - |
|
122 | - return json_encode($this->toArray()); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function toArray(): array { |
|
129 | - |
|
130 | - $fields = get_object_vars($this); |
|
131 | - |
|
132 | - foreach ($fields as $field_name => $field_value) { |
|
133 | - |
|
134 | - if (!is_scalar($field_value) && method_exists($field_value, 'toJson')) { |
|
135 | - $fields[$field_name] = $field_value->toArray(); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - return $fields; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function __toString(): string { |
|
146 | - |
|
147 | - return implode(',', $this->toArray()); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param $name |
|
152 | - * @param $arguments |
|
153 | - * |
|
154 | - * @return mixed |
|
155 | - */ |
|
156 | - public function __call($name, $arguments) { |
|
157 | - |
|
158 | - preg_match('/(?<=(g|s)et)([A-Za-z0-9])\w+/', $name, $match); |
|
159 | - |
|
160 | - $camel_field = (empty($match[0])) ? '' : $match[0]; |
|
161 | - |
|
162 | - $snake_field = camel2Snake($camel_field); |
|
163 | - |
|
164 | - $field_type = (empty($this->typeCheck[$snake_field])) ? null : $this->typeCheck[$snake_field]; |
|
165 | - |
|
166 | - if (!empty($match[1]) && $field_type) { |
|
167 | - switch ($match[1]) { |
|
168 | - case 's': |
|
169 | - return $this->$snake_field = $this->parseFieldValue($field_type, current($arguments)); |
|
170 | - case 'g': |
|
171 | - return $this->$snake_field; |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $typeCheck = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $required = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $errors = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * AbstractObject constructor. |
|
39 | + * |
|
40 | + * @param array $args |
|
41 | + */ |
|
42 | + public function __construct(?array $args = []) { |
|
43 | + |
|
44 | + $this->setArgs($args); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @param array $args |
|
49 | + * |
|
50 | + * @throws Exception |
|
51 | + */ |
|
52 | + protected function setArgs(array $args) { |
|
53 | + |
|
54 | + foreach ($this->typeCheck as $field_name => $field_type) { |
|
55 | + if (empty($args[$field_name]) || is_null($args[$field_name])) { |
|
56 | + if ($this->isFieldRequired($field_name)) { |
|
57 | + $this->addError('Missing "' . $field_name . '" in ' . static::class); |
|
58 | + } |
|
59 | + } else { |
|
60 | + $this->$field_name = $this->parseFieldValue($field_type, $args[$field_name]); |
|
61 | + } |
|
62 | + } |
|
63 | + $this->throwErrors(); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param string $field_name |
|
68 | + * |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + protected function isFieldRequired(string $field_name): bool { |
|
72 | + |
|
73 | + return in_array($field_name, $this->required); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $error |
|
78 | + * |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function addError(string $error): array { |
|
82 | + |
|
83 | + array_push($this->errors, $error); |
|
84 | + |
|
85 | + return $this->errors; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $field_type |
|
90 | + * @param string $field_value |
|
91 | + * |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + protected function parseFieldValue(string $field_type, $field_value) { |
|
95 | + |
|
96 | + switch ($field_type) { |
|
97 | + case 'string': |
|
98 | + case 'int': |
|
99 | + case 'float': |
|
100 | + case 'array': |
|
101 | + return $field_value; |
|
102 | + default: |
|
103 | + return ($field_value instanceof $field_type) ? $field_value : new $field_type($field_value); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @throws Exception |
|
109 | + */ |
|
110 | + protected function throwErrors() { |
|
111 | + |
|
112 | + if (count($this->errors)) { |
|
113 | + throw new Exception(implode(', ', $this->errors)); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function toJson(): string { |
|
121 | + |
|
122 | + return json_encode($this->toArray()); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function toArray(): array { |
|
129 | + |
|
130 | + $fields = get_object_vars($this); |
|
131 | + |
|
132 | + foreach ($fields as $field_name => $field_value) { |
|
133 | + |
|
134 | + if (!is_scalar($field_value) && method_exists($field_value, 'toJson')) { |
|
135 | + $fields[$field_name] = $field_value->toArray(); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + return $fields; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function __toString(): string { |
|
146 | + |
|
147 | + return implode(',', $this->toArray()); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param $name |
|
152 | + * @param $arguments |
|
153 | + * |
|
154 | + * @return mixed |
|
155 | + */ |
|
156 | + public function __call($name, $arguments) { |
|
157 | + |
|
158 | + preg_match('/(?<=(g|s)et)([A-Za-z0-9])\w+/', $name, $match); |
|
159 | + |
|
160 | + $camel_field = (empty($match[0])) ? '' : $match[0]; |
|
161 | + |
|
162 | + $snake_field = camel2Snake($camel_field); |
|
163 | + |
|
164 | + $field_type = (empty($this->typeCheck[$snake_field])) ? null : $this->typeCheck[$snake_field]; |
|
165 | + |
|
166 | + if (!empty($match[1]) && $field_type) { |
|
167 | + switch ($match[1]) { |
|
168 | + case 's': |
|
169 | + return $this->$snake_field = $this->parseFieldValue($field_type, current($arguments)); |
|
170 | + case 'g': |
|
171 | + return $this->$snake_field; |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | 176 | } |
177 | 177 | \ No newline at end of file |