1 | <?php |
||
26 | class AbstractClient |
||
27 | { |
||
28 | /** |
||
29 | * @var string response format. Can be json or xml. |
||
30 | */ |
||
31 | protected $format = 'json'; |
||
32 | /** |
||
33 | * @var string API endpoint |
||
34 | */ |
||
35 | protected $api = 'https://maps.googleapis.com/maps/api/place/{cmd}/{format}'; |
||
36 | /** |
||
37 | * @var string your API key |
||
38 | */ |
||
39 | protected $key; |
||
40 | /** |
||
41 | * @var \GuzzleHttp\Client a client to make requests to the API |
||
42 | */ |
||
43 | protected $guzzle; |
||
44 | /** |
||
45 | * @var bool returns arrays instead of stdObjects on decoding JSON responses |
||
46 | */ |
||
47 | protected $forceJsonArrayResponse = false; |
||
48 | |||
49 | /** |
||
50 | * AbstractClient constructor. |
||
51 | * |
||
52 | * @param $key |
||
53 | * @param string $format |
||
54 | * |
||
55 | * @throws InvalidArgumentException |
||
56 | */ |
||
57 | public function __construct($key, $format = 'json') |
||
66 | |||
67 | /** |
||
68 | * Required for child classes. |
||
69 | * |
||
70 | * @param string $cmd the command |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getUrl($cmd) |
||
78 | |||
79 | /** |
||
80 | * Sets the flag for decoding JSON method. |
||
81 | * |
||
82 | * @param bool $value |
||
83 | */ |
||
84 | public function forceJsonArrayResponse($value = true) |
||
88 | |||
89 | /** |
||
90 | * Makes a Url request and returns its response. |
||
91 | * |
||
92 | * @param string $cmd the command |
||
93 | * @param string $method the method 'get' or 'post' |
||
94 | * @param array $params the parameters to be bound to the call |
||
95 | * @param array $options the options to be attached to the client |
||
96 | * |
||
97 | * @return mixed|null |
||
98 | */ |
||
99 | protected function request($cmd, $method = 'get', $params = [], $options = []) |
||
114 | |||
115 | /** |
||
116 | * Parses response body in json or xml format as specified. |
||
117 | * |
||
118 | * @param string $contents |
||
119 | * |
||
120 | * @return mixed|SimpleXMLElement |
||
121 | */ |
||
122 | protected function parseResponse($contents) |
||
126 | |||
127 | /** |
||
128 | * Returns an option from an array. If not set return default value. |
||
129 | * |
||
130 | * @param array $options |
||
131 | * @param string $param |
||
132 | * @param mixed $default |
||
133 | * |
||
134 | * @return mixed|null |
||
135 | */ |
||
136 | protected function getParamValue($options, $param, $default = null) |
||
140 | |||
141 | /** |
||
142 | * Returns the guzzle client. |
||
143 | * |
||
144 | * @return \GuzzleHttp\Client |
||
145 | */ |
||
146 | protected function getGuzzleClient() |
||
154 | } |
||
155 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.