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

executeQuery() private méthode

private executeQuery ( string $query )
$query string
    private function executeQuery($query)
    {
        if (null !== $this->getLocale()) {
            // Locale code transformation: for example from it_IT to it
            $query = sprintf('%s&lang=%s', $query, substr($this->getLocale(), 0, 2));
        }
        $request = $this->getMessageFactory()->createRequest('GET', $query);
        $content = (string) $this->getHttpClient()->sendRequest($request)->getBody();
        if (empty($content)) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        if (null === ($json = json_decode($content))) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        if (isset($json->totalResultsCount) && empty($json->totalResultsCount)) {
            throw new NoResult(sprintf('No places found for query "%s".', $query));
        }
        $data = $json->geonames;
        if (empty($data)) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        $results = [];
        foreach ($data as $item) {
            $bounds = null;
            if (isset($item->bbox)) {
                $bounds = array('south' => $item->bbox->south, 'west' => $item->bbox->west, 'north' => $item->bbox->north, 'east' => $item->bbox->east);
            }
            $adminLevels = [];
            for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++$level) {
                $adminNameProp = 'adminName' . $level;
                $adminCodeProp = 'adminCode' . $level;
                if (!empty($item->{$adminNameProp}) || !empty($item->{$adminCodeProp})) {
                    $adminLevels[] = ['name' => empty($item->{$adminNameProp}) ? null : $item->{$adminNameProp}, 'code' => empty($item->{$adminCodeProp}) ? null : $item->{$adminCodeProp}, 'level' => $level];
                }
            }
            $results[] = array_merge($this->getDefaults(), ['latitude' => isset($item->lat) ? $item->lat : null, 'longitude' => isset($item->lng) ? $item->lng : null, 'bounds' => $bounds, 'locality' => isset($item->name) ? $item->name : null, 'adminLevels' => $adminLevels, 'country' => isset($item->countryName) ? $item->countryName : null, 'countryCode' => isset($item->countryCode) ? $item->countryCode : null, 'timezone' => isset($item->timezone->timeZoneId) ? $item->timezone->timeZoneId : null]);
        }
        return $this->returnResults($results);
    }