@@ -21,22 +21,22 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class LatLngBounds extends AbstractObject { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var LatLng |
|
| 26 | - */ |
|
| 27 | - protected $northeast = null; |
|
| 24 | + /** |
|
| 25 | + * @var LatLng |
|
| 26 | + */ |
|
| 27 | + protected $northeast = null; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var LatLng |
|
| 31 | - */ |
|
| 32 | - protected $southwest = null; |
|
| 29 | + /** |
|
| 30 | + * @var LatLng |
|
| 31 | + */ |
|
| 32 | + protected $southwest = null; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected $typeCheck = [ |
|
| 38 | - LatLngBoundsFields::NORTHEAST => LatLng::class, |
|
| 39 | - LatLngBoundsFields::SOUTHWEST => LatLng::class |
|
| 40 | - ]; |
|
| 34 | + /** |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected $typeCheck = [ |
|
| 38 | + LatLngBoundsFields::NORTHEAST => LatLng::class, |
|
| 39 | + LatLngBoundsFields::SOUTHWEST => LatLng::class |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -25,27 +25,27 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class Geometry extends AbstractObject { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var Location |
|
| 30 | - */ |
|
| 31 | - protected $location = null; |
|
| 28 | + /** |
|
| 29 | + * @var Location |
|
| 30 | + */ |
|
| 31 | + protected $location = null; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var Viewport |
|
| 35 | - */ |
|
| 36 | - protected $viewport = null; |
|
| 33 | + /** |
|
| 34 | + * @var Viewport |
|
| 35 | + */ |
|
| 36 | + protected $viewport = null; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $location_type = null; |
|
| 38 | + /** |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $location_type = null; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $typeCheck = [ |
|
| 47 | - GeometryFields::LOCATION => Location::class, |
|
| 48 | - GeometryFields::VIEWPORT => Viewport::class, |
|
| 49 | - GeometryFields::LOCATION_TYPE => 'string' |
|
| 50 | - ]; |
|
| 43 | + /** |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $typeCheck = [ |
|
| 47 | + GeometryFields::LOCATION => Location::class, |
|
| 48 | + GeometryFields::VIEWPORT => Viewport::class, |
|
| 49 | + GeometryFields::LOCATION_TYPE => 'string' |
|
| 50 | + ]; |
|
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |
@@ -21,53 +21,53 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class LatLng extends AbstractObject { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var float |
|
| 26 | - */ |
|
| 27 | - protected $lat = 0; |
|
| 24 | + /** |
|
| 25 | + * @var float |
|
| 26 | + */ |
|
| 27 | + protected $lat = 0; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var float |
|
| 31 | - */ |
|
| 32 | - protected $lng = 0; |
|
| 29 | + /** |
|
| 30 | + * @var float |
|
| 31 | + */ |
|
| 32 | + protected $lng = 0; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected $typeCheck = [ |
|
| 38 | - LatLngFields::LAT => 'float', |
|
| 39 | - LatLngFields::LNG => 'float', |
|
| 40 | - ]; |
|
| 34 | + /** |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected $typeCheck = [ |
|
| 38 | + LatLngFields::LAT => 'float', |
|
| 39 | + LatLngFields::LNG => 'float', |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Return the latitude, 0 if null |
|
| 44 | - * |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getLat(): string { |
|
| 42 | + /** |
|
| 43 | + * Return the latitude, 0 if null |
|
| 44 | + * |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getLat(): string { |
|
| 48 | 48 | |
| 49 | - return $this->lat ?? 0; |
|
| 50 | - } |
|
| 49 | + return $this->lat ?? 0; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Return the longitude, 0 if null |
|
| 54 | - * |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function getLng(): string { |
|
| 52 | + /** |
|
| 53 | + * Return the longitude, 0 if null |
|
| 54 | + * |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function getLng(): string { |
|
| 58 | 58 | |
| 59 | - return $this->lng ?? 0; |
|
| 60 | - } |
|
| 59 | + return $this->lng ?? 0; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function __toString(): string { |
|
| 62 | + /** |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function __toString(): string { |
|
| 66 | 66 | |
| 67 | - return implode(',', [ |
|
| 68 | - $this->getLat(), |
|
| 69 | - $this->getLng() |
|
| 70 | - ]); |
|
| 71 | - } |
|
| 67 | + return implode(',', [ |
|
| 68 | + $this->getLat(), |
|
| 69 | + $this->getLng() |
|
| 70 | + ]); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | \ No newline at end of file |
@@ -19,160 +19,160 @@ |
||
| 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 | - // TODO: Implement __call() method. |
|
| 159 | - $action = null; |
|
| 160 | - preg_match('/(?<=(g|s)et)([A-Za-z0-9])\w+/', $name, $match); |
|
| 161 | - |
|
| 162 | - $camel_field = (empty($match[0])) ? null : $match[0]; |
|
| 163 | - |
|
| 164 | - $snake_field = camel2Snake($camel_field); |
|
| 165 | - |
|
| 166 | - $field_type = (empty($this->typeCheck[$snake_field])) ? null : $this->typeCheck[$snake_field]; |
|
| 167 | - |
|
| 168 | - if (!empty($match[1]) && $field_type) { |
|
| 169 | - switch ($match[1]) { |
|
| 170 | - case 's': |
|
| 171 | - return $this->$snake_field = $this->parseFieldValue($field_type, current($arguments)); |
|
| 172 | - case 'g': |
|
| 173 | - return $this->$snake_field; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 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 | + // TODO: Implement __call() method. |
|
| 159 | + $action = null; |
|
| 160 | + preg_match('/(?<=(g|s)et)([A-Za-z0-9])\w+/', $name, $match); |
|
| 161 | + |
|
| 162 | + $camel_field = (empty($match[0])) ? null : $match[0]; |
|
| 163 | + |
|
| 164 | + $snake_field = camel2Snake($camel_field); |
|
| 165 | + |
|
| 166 | + $field_type = (empty($this->typeCheck[$snake_field])) ? null : $this->typeCheck[$snake_field]; |
|
| 167 | + |
|
| 168 | + if (!empty($match[1]) && $field_type) { |
|
| 169 | + switch ($match[1]) { |
|
| 170 | + case 's': |
|
| 171 | + return $this->$snake_field = $this->parseFieldValue($field_type, current($arguments)); |
|
| 172 | + case 'g': |
|
| 173 | + return $this->$snake_field; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | 178 | } |
| 179 | 179 | \ No newline at end of file |
@@ -21,78 +21,78 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class Api { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var GoogleMapsApi |
|
| 26 | - */ |
|
| 27 | - protected $googleMapsApi = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - const SERVICE_ENDPOINT = null; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Api constructor. |
|
| 36 | - * |
|
| 37 | - * @param array $config |
|
| 38 | - */ |
|
| 39 | - public function __construct(array $config = []) { |
|
| 40 | - |
|
| 41 | - $service_config = $this->getServiceConfig($config); |
|
| 42 | - $this->setGoogleMapsApi(new GoogleMapsApi($service_config)); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return GoogleMapsApi |
|
| 47 | - */ |
|
| 48 | - public function getGoogleMapsApi(): GoogleMapsApi { |
|
| 49 | - |
|
| 50 | - return $this->googleMapsApi; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param GoogleMapsApi $googleMapsApi |
|
| 55 | - * |
|
| 56 | - * @return Api |
|
| 57 | - */ |
|
| 58 | - public function setGoogleMapsApi(GoogleMapsApi $googleMapsApi): Api { |
|
| 59 | - |
|
| 60 | - $this->googleMapsApi = $googleMapsApi; |
|
| 61 | - |
|
| 62 | - return $this; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function getServiceEndpoint(): string { |
|
| 69 | - |
|
| 70 | - return static::SERVICE_ENDPOINT; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param array $config |
|
| 75 | - * |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - protected function getServiceConfig(array $config = []): array { |
|
| 79 | - |
|
| 80 | - return array_merge($config, [ |
|
| 81 | - GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint() |
|
| 82 | - ]); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param array $params |
|
| 87 | - * |
|
| 88 | - * @return mixed |
|
| 89 | - */ |
|
| 90 | - abstract public function createRequest(array $params): GoogleMapsRequest; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param GoogleMapsRequest $request |
|
| 94 | - * |
|
| 95 | - * @return GoogleMapsResultsCollection |
|
| 96 | - */ |
|
| 97 | - abstract public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection; |
|
| 24 | + /** |
|
| 25 | + * @var GoogleMapsApi |
|
| 26 | + */ |
|
| 27 | + protected $googleMapsApi = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + const SERVICE_ENDPOINT = null; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Api constructor. |
|
| 36 | + * |
|
| 37 | + * @param array $config |
|
| 38 | + */ |
|
| 39 | + public function __construct(array $config = []) { |
|
| 40 | + |
|
| 41 | + $service_config = $this->getServiceConfig($config); |
|
| 42 | + $this->setGoogleMapsApi(new GoogleMapsApi($service_config)); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return GoogleMapsApi |
|
| 47 | + */ |
|
| 48 | + public function getGoogleMapsApi(): GoogleMapsApi { |
|
| 49 | + |
|
| 50 | + return $this->googleMapsApi; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param GoogleMapsApi $googleMapsApi |
|
| 55 | + * |
|
| 56 | + * @return Api |
|
| 57 | + */ |
|
| 58 | + public function setGoogleMapsApi(GoogleMapsApi $googleMapsApi): Api { |
|
| 59 | + |
|
| 60 | + $this->googleMapsApi = $googleMapsApi; |
|
| 61 | + |
|
| 62 | + return $this; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function getServiceEndpoint(): string { |
|
| 69 | + |
|
| 70 | + return static::SERVICE_ENDPOINT; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param array $config |
|
| 75 | + * |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + protected function getServiceConfig(array $config = []): array { |
|
| 79 | + |
|
| 80 | + return array_merge($config, [ |
|
| 81 | + GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint() |
|
| 82 | + ]); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param array $params |
|
| 87 | + * |
|
| 88 | + * @return mixed |
|
| 89 | + */ |
|
| 90 | + abstract public function createRequest(array $params): GoogleMapsRequest; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param GoogleMapsRequest $request |
|
| 94 | + * |
|
| 95 | + * @return GoogleMapsResultsCollection |
|
| 96 | + */ |
|
| 97 | + abstract public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection; |
|
| 98 | 98 | } |
| 99 | 99 | \ No newline at end of file |
@@ -16,169 +16,169 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | abstract class AbstractCollection { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $items = []; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 27 | - protected $index = 0; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * AbstractCollection constructor. |
|
| 31 | - * |
|
| 32 | - * @param null|array $items |
|
| 33 | - */ |
|
| 34 | - public function __construct(?array $items = []) { |
|
| 35 | - |
|
| 36 | - $this->setItems($items); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param array $items |
|
| 41 | - * |
|
| 42 | - * @return AbstractCollection |
|
| 43 | - */ |
|
| 44 | - protected function setItems(?array $items = []) { |
|
| 45 | - |
|
| 46 | - if (is_array($items) && count($items)) { |
|
| 47 | - foreach ($items as $item) { |
|
| 48 | - $this->addItem($item); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - return $this; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param $item |
|
| 57 | - * |
|
| 58 | - * @return AbstractCollection |
|
| 59 | - */ |
|
| 60 | - public function addItem($item) { |
|
| 61 | - |
|
| 62 | - $item = $this->parseItem($item); |
|
| 63 | - array_push($this->items, $item); |
|
| 64 | - |
|
| 65 | - return $this; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param $item |
|
| 70 | - * |
|
| 71 | - * @return mixed |
|
| 72 | - */ |
|
| 73 | - protected function parseItem($item) { |
|
| 74 | - |
|
| 75 | - return $item; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function toArray(): array { |
|
| 82 | - |
|
| 83 | - return $this->items; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param $index |
|
| 88 | - * |
|
| 89 | - * @return mixed|null |
|
| 90 | - */ |
|
| 91 | - public function get(int $index) { |
|
| 92 | - |
|
| 93 | - return isset($this->items[$index]) ? $this->items[$index] : null; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return int |
|
| 98 | - */ |
|
| 99 | - public function count(): int { |
|
| 100 | - |
|
| 101 | - return count($this->items); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return string |
|
| 106 | - */ |
|
| 107 | - public function toJson(): string { |
|
| 108 | - |
|
| 109 | - return json_encode($this->toArray()); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function __toString(): string { |
|
| 116 | - |
|
| 117 | - return implode(',', $this->toArray()); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return int |
|
| 122 | - */ |
|
| 123 | - public function getLastIndex(): int { |
|
| 124 | - |
|
| 125 | - $last_position = $this->count() - 1; |
|
| 126 | - |
|
| 127 | - return ($last_position) < 0 ? 0 : $last_position; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Move the index at the specified position |
|
| 132 | - * |
|
| 133 | - * @param int|null $index |
|
| 134 | - * |
|
| 135 | - * @return mixed|null |
|
| 136 | - */ |
|
| 137 | - public function seek(?int $index = 0) { |
|
| 138 | - |
|
| 139 | - $this->index = ($index < $this->count()) ? $index : $this->getLastIndex(); |
|
| 140 | - |
|
| 141 | - return $this->get($this->index); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Return the current position of the index |
|
| 146 | - * |
|
| 147 | - * @return int |
|
| 148 | - */ |
|
| 149 | - public function position(): int { |
|
| 150 | - |
|
| 151 | - return $this->index; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Return the current object |
|
| 156 | - * |
|
| 157 | - * @return mixed|null |
|
| 158 | - */ |
|
| 159 | - public function current() { |
|
| 160 | - |
|
| 161 | - return $this->get($this->index); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Move index to first position and return current element |
|
| 166 | - * |
|
| 167 | - * @return mixed|null |
|
| 168 | - */ |
|
| 169 | - public function first() { |
|
| 170 | - |
|
| 171 | - return $this->seek(); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Move index at the end of collection and return current element |
|
| 176 | - * |
|
| 177 | - * @return mixed|null |
|
| 178 | - */ |
|
| 179 | - public function last() { |
|
| 180 | - |
|
| 181 | - return $this->seek($this->getLastIndex()); |
|
| 182 | - } |
|
| 19 | + /** |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $items = []; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | + protected $index = 0; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * AbstractCollection constructor. |
|
| 31 | + * |
|
| 32 | + * @param null|array $items |
|
| 33 | + */ |
|
| 34 | + public function __construct(?array $items = []) { |
|
| 35 | + |
|
| 36 | + $this->setItems($items); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param array $items |
|
| 41 | + * |
|
| 42 | + * @return AbstractCollection |
|
| 43 | + */ |
|
| 44 | + protected function setItems(?array $items = []) { |
|
| 45 | + |
|
| 46 | + if (is_array($items) && count($items)) { |
|
| 47 | + foreach ($items as $item) { |
|
| 48 | + $this->addItem($item); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param $item |
|
| 57 | + * |
|
| 58 | + * @return AbstractCollection |
|
| 59 | + */ |
|
| 60 | + public function addItem($item) { |
|
| 61 | + |
|
| 62 | + $item = $this->parseItem($item); |
|
| 63 | + array_push($this->items, $item); |
|
| 64 | + |
|
| 65 | + return $this; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param $item |
|
| 70 | + * |
|
| 71 | + * @return mixed |
|
| 72 | + */ |
|
| 73 | + protected function parseItem($item) { |
|
| 74 | + |
|
| 75 | + return $item; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function toArray(): array { |
|
| 82 | + |
|
| 83 | + return $this->items; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param $index |
|
| 88 | + * |
|
| 89 | + * @return mixed|null |
|
| 90 | + */ |
|
| 91 | + public function get(int $index) { |
|
| 92 | + |
|
| 93 | + return isset($this->items[$index]) ? $this->items[$index] : null; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return int |
|
| 98 | + */ |
|
| 99 | + public function count(): int { |
|
| 100 | + |
|
| 101 | + return count($this->items); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return string |
|
| 106 | + */ |
|
| 107 | + public function toJson(): string { |
|
| 108 | + |
|
| 109 | + return json_encode($this->toArray()); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function __toString(): string { |
|
| 116 | + |
|
| 117 | + return implode(',', $this->toArray()); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return int |
|
| 122 | + */ |
|
| 123 | + public function getLastIndex(): int { |
|
| 124 | + |
|
| 125 | + $last_position = $this->count() - 1; |
|
| 126 | + |
|
| 127 | + return ($last_position) < 0 ? 0 : $last_position; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Move the index at the specified position |
|
| 132 | + * |
|
| 133 | + * @param int|null $index |
|
| 134 | + * |
|
| 135 | + * @return mixed|null |
|
| 136 | + */ |
|
| 137 | + public function seek(?int $index = 0) { |
|
| 138 | + |
|
| 139 | + $this->index = ($index < $this->count()) ? $index : $this->getLastIndex(); |
|
| 140 | + |
|
| 141 | + return $this->get($this->index); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Return the current position of the index |
|
| 146 | + * |
|
| 147 | + * @return int |
|
| 148 | + */ |
|
| 149 | + public function position(): int { |
|
| 150 | + |
|
| 151 | + return $this->index; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Return the current object |
|
| 156 | + * |
|
| 157 | + * @return mixed|null |
|
| 158 | + */ |
|
| 159 | + public function current() { |
|
| 160 | + |
|
| 161 | + return $this->get($this->index); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Move index to first position and return current element |
|
| 166 | + * |
|
| 167 | + * @return mixed|null |
|
| 168 | + */ |
|
| 169 | + public function first() { |
|
| 170 | + |
|
| 171 | + return $this->seek(); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Move index at the end of collection and return current element |
|
| 176 | + * |
|
| 177 | + * @return mixed|null |
|
| 178 | + */ |
|
| 179 | + public function last() { |
|
| 180 | + |
|
| 181 | + return $this->seek($this->getLastIndex()); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | } |
| 185 | 185 | \ No newline at end of file |
@@ -23,250 +23,250 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class GoogleMapsApi { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Google Maps Geocode Service API url |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - private $api_url = "https://maps.googleapis.com/maps/api/"; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * your own Google Maps API key |
|
| 34 | - * @var string |
|
| 35 | - * @see https://developers.google.com/maps/documentation/javascript/get-api-key |
|
| 36 | - */ |
|
| 37 | - private $key = ''; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Google Maps API sensor |
|
| 41 | - * @var string - true|false |
|
| 42 | - */ |
|
| 43 | - private $sensor = 'false'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Google Maps API service name |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - private $service_endpoint = ''; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - private $response = null; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var GoogleMapsClient |
|
| 58 | - */ |
|
| 59 | - private $client = null; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - private $type = null; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var GoogleMapsApi |
|
| 68 | - */ |
|
| 69 | - protected static $instance = null; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var GoogleMapsRequest |
|
| 73 | - */ |
|
| 74 | - protected $request = null; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * GoogleMapsApi constructor. |
|
| 78 | - * |
|
| 79 | - * @param array $config |
|
| 80 | - */ |
|
| 81 | - public function __construct(array $config = []) { |
|
| 82 | - |
|
| 83 | - // Set "API key" |
|
| 84 | - $key = (empty($config[GoogleMapsApiConfigFields::KEY])) ? '' : $config[GoogleMapsApiConfigFields::KEY]; |
|
| 85 | - $this->setKey($key); |
|
| 86 | - |
|
| 87 | - // Set "sensor" |
|
| 88 | - $sensor = (empty($config[GoogleMapsApiConfigFields::SENSOR])) ? '' : $config[GoogleMapsApiConfigFields::SENSOR]; |
|
| 89 | - $this->setSensor($sensor); |
|
| 90 | - |
|
| 91 | - // Set the endpoint |
|
| 92 | - $service_endpoint = (empty($config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT])) ? '' : $config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT]; |
|
| 93 | - $this->setServiceEndpoint($service_endpoint); |
|
| 94 | - |
|
| 95 | - // Set Client |
|
| 96 | - $this->setClient(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function getApiUrl(): string { |
|
| 103 | - |
|
| 104 | - return $this->api_url; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $key |
|
| 109 | - * |
|
| 110 | - * @return GoogleMapsApi |
|
| 111 | - */ |
|
| 112 | - public function setKey(string $key): GoogleMapsApi { |
|
| 113 | - |
|
| 114 | - $this->key = $key; |
|
| 115 | - |
|
| 116 | - return $this; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public function getKey(): string { |
|
| 123 | - |
|
| 124 | - return $this->key; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Set sensor parameter |
|
| 129 | - * |
|
| 130 | - * @param bool $sensor |
|
| 131 | - * |
|
| 132 | - * @return GoogleMapsApi |
|
| 133 | - */ |
|
| 134 | - public function setSensor(bool $sensor): GoogleMapsApi { |
|
| 135 | - |
|
| 136 | - if ($sensor === false) { |
|
| 137 | - $sensor = 'false'; |
|
| 138 | - } |
|
| 139 | - $this->sensor = $sensor; |
|
| 140 | - |
|
| 141 | - return $this; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - public function getSensor(): string { |
|
| 148 | - |
|
| 149 | - return $this->sensor ? 'true' : 'false'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param GoogleMapsClient|null $client |
|
| 154 | - * |
|
| 155 | - * @return GoogleMapsApi |
|
| 156 | - */ |
|
| 157 | - public function setClient(?GoogleMapsClient $client = null): GoogleMapsApi { |
|
| 158 | - |
|
| 159 | - $this->client = $client ?? new GoogleMapsClient(); |
|
| 160 | - |
|
| 161 | - return $this; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @return GoogleMapsClient |
|
| 166 | - */ |
|
| 167 | - public function getClient() { |
|
| 168 | - |
|
| 169 | - return $this->client; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @return GoogleMapsRequest |
|
| 174 | - */ |
|
| 175 | - public function getRequest(): GoogleMapsRequest { |
|
| 176 | - |
|
| 177 | - return $this->request; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - public function getServiceEndpoint(): string { |
|
| 184 | - |
|
| 185 | - return $this->service_endpoint; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param string $service_endpoint |
|
| 190 | - */ |
|
| 191 | - public function setServiceEndpoint(string $service_endpoint) { |
|
| 192 | - |
|
| 193 | - $this->service_endpoint = $service_endpoint; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @param string $type |
|
| 198 | - * |
|
| 199 | - * @return GoogleMapsApi |
|
| 200 | - */ |
|
| 201 | - protected function setType(string $type): GoogleMapsApi { |
|
| 202 | - |
|
| 203 | - $this->type = $type; |
|
| 204 | - |
|
| 205 | - return $this; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @return string |
|
| 210 | - * @throws RequestException |
|
| 211 | - */ |
|
| 212 | - public function getUrl(): string { |
|
| 26 | + /** |
|
| 27 | + * Google Maps Geocode Service API url |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + private $api_url = "https://maps.googleapis.com/maps/api/"; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * your own Google Maps API key |
|
| 34 | + * @var string |
|
| 35 | + * @see https://developers.google.com/maps/documentation/javascript/get-api-key |
|
| 36 | + */ |
|
| 37 | + private $key = ''; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Google Maps API sensor |
|
| 41 | + * @var string - true|false |
|
| 42 | + */ |
|
| 43 | + private $sensor = 'false'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Google Maps API service name |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + private $service_endpoint = ''; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + private $response = null; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var GoogleMapsClient |
|
| 58 | + */ |
|
| 59 | + private $client = null; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + private $type = null; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var GoogleMapsApi |
|
| 68 | + */ |
|
| 69 | + protected static $instance = null; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var GoogleMapsRequest |
|
| 73 | + */ |
|
| 74 | + protected $request = null; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * GoogleMapsApi constructor. |
|
| 78 | + * |
|
| 79 | + * @param array $config |
|
| 80 | + */ |
|
| 81 | + public function __construct(array $config = []) { |
|
| 82 | + |
|
| 83 | + // Set "API key" |
|
| 84 | + $key = (empty($config[GoogleMapsApiConfigFields::KEY])) ? '' : $config[GoogleMapsApiConfigFields::KEY]; |
|
| 85 | + $this->setKey($key); |
|
| 86 | + |
|
| 87 | + // Set "sensor" |
|
| 88 | + $sensor = (empty($config[GoogleMapsApiConfigFields::SENSOR])) ? '' : $config[GoogleMapsApiConfigFields::SENSOR]; |
|
| 89 | + $this->setSensor($sensor); |
|
| 90 | + |
|
| 91 | + // Set the endpoint |
|
| 92 | + $service_endpoint = (empty($config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT])) ? '' : $config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT]; |
|
| 93 | + $this->setServiceEndpoint($service_endpoint); |
|
| 94 | + |
|
| 95 | + // Set Client |
|
| 96 | + $this->setClient(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function getApiUrl(): string { |
|
| 103 | + |
|
| 104 | + return $this->api_url; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $key |
|
| 109 | + * |
|
| 110 | + * @return GoogleMapsApi |
|
| 111 | + */ |
|
| 112 | + public function setKey(string $key): GoogleMapsApi { |
|
| 113 | + |
|
| 114 | + $this->key = $key; |
|
| 115 | + |
|
| 116 | + return $this; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public function getKey(): string { |
|
| 123 | + |
|
| 124 | + return $this->key; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Set sensor parameter |
|
| 129 | + * |
|
| 130 | + * @param bool $sensor |
|
| 131 | + * |
|
| 132 | + * @return GoogleMapsApi |
|
| 133 | + */ |
|
| 134 | + public function setSensor(bool $sensor): GoogleMapsApi { |
|
| 135 | + |
|
| 136 | + if ($sensor === false) { |
|
| 137 | + $sensor = 'false'; |
|
| 138 | + } |
|
| 139 | + $this->sensor = $sensor; |
|
| 140 | + |
|
| 141 | + return $this; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + public function getSensor(): string { |
|
| 148 | + |
|
| 149 | + return $this->sensor ? 'true' : 'false'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param GoogleMapsClient|null $client |
|
| 154 | + * |
|
| 155 | + * @return GoogleMapsApi |
|
| 156 | + */ |
|
| 157 | + public function setClient(?GoogleMapsClient $client = null): GoogleMapsApi { |
|
| 158 | + |
|
| 159 | + $this->client = $client ?? new GoogleMapsClient(); |
|
| 160 | + |
|
| 161 | + return $this; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @return GoogleMapsClient |
|
| 166 | + */ |
|
| 167 | + public function getClient() { |
|
| 168 | + |
|
| 169 | + return $this->client; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @return GoogleMapsRequest |
|
| 174 | + */ |
|
| 175 | + public function getRequest(): GoogleMapsRequest { |
|
| 176 | + |
|
| 177 | + return $this->request; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + public function getServiceEndpoint(): string { |
|
| 184 | + |
|
| 185 | + return $this->service_endpoint; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param string $service_endpoint |
|
| 190 | + */ |
|
| 191 | + public function setServiceEndpoint(string $service_endpoint) { |
|
| 192 | + |
|
| 193 | + $this->service_endpoint = $service_endpoint; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @param string $type |
|
| 198 | + * |
|
| 199 | + * @return GoogleMapsApi |
|
| 200 | + */ |
|
| 201 | + protected function setType(string $type): GoogleMapsApi { |
|
| 202 | + |
|
| 203 | + $this->type = $type; |
|
| 204 | + |
|
| 205 | + return $this; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @return string |
|
| 210 | + * @throws RequestException |
|
| 211 | + */ |
|
| 212 | + public function getUrl(): string { |
|
| 213 | 213 | |
| 214 | - $service_endpoint = $this->getServiceEndpoint(); |
|
| 215 | - if (!$service_endpoint) { |
|
| 216 | - throw new RequestException('Service name missing!'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - return $this->api_url . $service_endpoint . '/' . GoogleMapsResponseFormat::JSON; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @param GoogleMapsRequest $request |
|
| 224 | - * |
|
| 225 | - * @return GoogleMapsApi |
|
| 226 | - */ |
|
| 227 | - public function setRequest(GoogleMapsRequest $request) { |
|
| 228 | - |
|
| 229 | - $this->request = $request; |
|
| 230 | - |
|
| 231 | - return $this; |
|
| 232 | - } |
|
| 214 | + $service_endpoint = $this->getServiceEndpoint(); |
|
| 215 | + if (!$service_endpoint) { |
|
| 216 | + throw new RequestException('Service name missing!'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + return $this->api_url . $service_endpoint . '/' . GoogleMapsResponseFormat::JSON; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @param GoogleMapsRequest $request |
|
| 224 | + * |
|
| 225 | + * @return GoogleMapsApi |
|
| 226 | + */ |
|
| 227 | + public function setRequest(GoogleMapsRequest $request) { |
|
| 228 | + |
|
| 229 | + $this->request = $request; |
|
| 230 | + |
|
| 231 | + return $this; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * @return string |
|
| 236 | - */ |
|
| 237 | - public function getQuery(): string { |
|
| 234 | + /** |
|
| 235 | + * @return string |
|
| 236 | + */ |
|
| 237 | + public function getQuery(): string { |
|
| 238 | 238 | |
| 239 | - $api_query = http_build_query([ |
|
| 240 | - GoogleMapsRequestFields::KEY => $this->getKey(), |
|
| 241 | - GoogleMapsRequestFields::SENSOR => $this->getSensor(), |
|
| 242 | - ]); |
|
| 239 | + $api_query = http_build_query([ |
|
| 240 | + GoogleMapsRequestFields::KEY => $this->getKey(), |
|
| 241 | + GoogleMapsRequestFields::SENSOR => $this->getSensor(), |
|
| 242 | + ]); |
|
| 243 | 243 | |
| 244 | - $request_query = $this->getRequest()->getQuery(); |
|
| 244 | + $request_query = $this->getRequest()->getQuery(); |
|
| 245 | 245 | |
| 246 | - return implode('&', [ |
|
| 247 | - $api_query, |
|
| 248 | - $request_query |
|
| 249 | - ]); |
|
| 250 | - } |
|
| 246 | + return implode('&', [ |
|
| 247 | + $api_query, |
|
| 248 | + $request_query |
|
| 249 | + ]); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Perform the Google Maps API call |
|
| 254 | - * |
|
| 255 | - * @param GoogleMapsRequest $request |
|
| 256 | - * |
|
| 257 | - * @return Http\GoogleMapsResponse|string |
|
| 258 | - */ |
|
| 259 | - public function get(GoogleMapsRequest $request) { |
|
| 252 | + /** |
|
| 253 | + * Perform the Google Maps API call |
|
| 254 | + * |
|
| 255 | + * @param GoogleMapsRequest $request |
|
| 256 | + * |
|
| 257 | + * @return Http\GoogleMapsResponse|string |
|
| 258 | + */ |
|
| 259 | + public function get(GoogleMapsRequest $request) { |
|
| 260 | 260 | |
| 261 | - $this->setRequest($request); |
|
| 261 | + $this->setRequest($request); |
|
| 262 | 262 | |
| 263 | - $url = $this->getUrl(); |
|
| 263 | + $url = $this->getUrl(); |
|
| 264 | 264 | |
| 265 | - $query = $this->getQuery(); |
|
| 265 | + $query = $this->getQuery(); |
|
| 266 | 266 | |
| 267 | - $this->response = $this->getClient()->get($url, $query); |
|
| 267 | + $this->response = $this->getClient()->get($url, $query); |
|
| 268 | 268 | |
| 269 | - return $this->response; |
|
| 270 | - } |
|
| 269 | + return $this->response; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | 272 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class GoogleMapsResponseFormat { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * string: json |
|
| 21 | - */ |
|
| 22 | - const JSON = 'json'; |
|
| 19 | + /** |
|
| 20 | + * string: json |
|
| 21 | + */ |
|
| 22 | + const JSON = 'json'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * string: xml |
|
| 26 | - * NOT supported in this version |
|
| 27 | - */ |
|
| 28 | - const XML = 'xml'; |
|
| 24 | + /** |
|
| 25 | + * string: xml |
|
| 26 | + * NOT supported in this version |
|
| 27 | + */ |
|
| 28 | + const XML = 'xml'; |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -16,18 +16,18 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class GoogleMapsApiConfigFields { |
| 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: service_endpoint |
|
| 31 | - */ |
|
| 32 | - const SERVICE_ENDPOINT = 'service_endpoint'; |
|
| 29 | + /** |
|
| 30 | + * string: service_endpoint |
|
| 31 | + */ |
|
| 32 | + const SERVICE_ENDPOINT = 'service_endpoint'; |
|
| 33 | 33 | } |
| 34 | 34 | \ No newline at end of file |