/** * Constructor; which optionally sets config details. * * @param array $configuration Defaults to empty array if none provided * * @return Services_OpenStreetMap */ public function __construct($configuration = array()) { $config = new Services_OpenStreetMap_Config(); $this->setConfig($config); $transport = new Services_OpenStreetMap_Transport_HTTP(); $transport->setConfig($config); $this->setTransport($transport); $config->setTransport($transport); $config->setValue($configuration); $version = $config->getValue('api_version'); $api = "Services_OpenStreetMap_API_V" . str_replace('.', '', $version); $this->api = new $api(); $this->api->setTransport($transport); $this->api->setConfig($config); }
/** * Send request to OSM server and return the response. * * @param string $url URL * @param string $method GET (default)/POST/PUT * @param string $user user (optional for read-only actions) * @param string $password password (optional for read-only actions) * @param string $body body (optional) * @param array $post_data (optional) * @param array $headers (optional) * * @access public * @return HTTP_Request2_Response * @todo Consider just returning the content? * @throws Services_OpenStreetMap_Exception If something unexpected has * happened while conversing with * the server. */ public function getResponse($url, $method = HTTP_Request2::METHOD_GET, $user = null, $password = null, $body = null, array $post_data = null, array $headers = null) { $arguments = array($url, $method, $user, $password, $body, implode(":", (array) $post_data), implode(":", (array) $headers)); $id = md5(implode(":", $arguments)); $data = $this->cache->get($id); if ($data) { $response = new HTTP_Request2_Response(); $response->setStatus(200); $response->setBody($data); return $response; } $response = parent::getResponse($url, $method, $user, $password, $body, $post_data, $headers); $this->cache->save($id, $response->getBody()); return $response; }