Geocoder\Provider\GoogleMaps::executeQuery PHP Méthode

executeQuery() private méthode

private executeQuery ( string $query )
$query string
    private function executeQuery($query)
    {
        $query = $this->buildQuery($query);
        $request = $this->getMessageFactory()->createRequest('GET', $query);
        $content = (string) $this->getHttpClient()->sendRequest($request)->getBody();
        // Throw exception if invalid clientID and/or privateKey used with GoogleMapsBusinessProvider
        if (strpos($content, "Provided 'signature' is not valid for the provided client ID") !== false) {
            throw new InvalidCredentials(sprintf('Invalid client ID / API Key %s', $query));
        }
        if (empty($content)) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        $json = json_decode($content);
        // API error
        if (!isset($json)) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        if ('REQUEST_DENIED' === $json->status && 'The provided API key is invalid.' === $json->error_message) {
            throw new InvalidCredentials(sprintf('API key is invalid %s', $query));
        }
        if ('REQUEST_DENIED' === $json->status) {
            throw new Exception(sprintf('API access denied. Request: %s - Message: %s', $query, $json->error_message));
        }
        // you are over your quota
        if ('OVER_QUERY_LIMIT' === $json->status) {
            throw new QuotaExceeded(sprintf('Daily quota exceeded %s', $query));
        }
        // no result
        if (!isset($json->results) || !count($json->results) || 'OK' !== $json->status) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        $results = [];
        foreach ($json->results as $result) {
            $resultSet = $this->getDefaults();
            // update address components
            foreach ($result->address_components as $component) {
                foreach ($component->types as $type) {
                    $this->updateAddressComponent($resultSet, $type, $component);
                }
            }
            // update coordinates
            $coordinates = $result->geometry->location;
            $resultSet['latitude'] = $coordinates->lat;
            $resultSet['longitude'] = $coordinates->lng;
            $resultSet['bounds'] = null;
            if (isset($result->geometry->bounds)) {
                $resultSet['bounds'] = array('south' => $result->geometry->bounds->southwest->lat, 'west' => $result->geometry->bounds->southwest->lng, 'north' => $result->geometry->bounds->northeast->lat, 'east' => $result->geometry->bounds->northeast->lng);
            } elseif ('ROOFTOP' === $result->geometry->location_type) {
                // Fake bounds
                $resultSet['bounds'] = array('south' => $coordinates->lat, 'west' => $coordinates->lng, 'north' => $coordinates->lat, 'east' => $coordinates->lng);
            }
            $results[] = array_merge($this->getDefaults(), $resultSet);
        }
        return $this->returnResults($results);
    }