default services conflit ?
This commit is contained in:
46
old.vendor/geocoder-php/common-http/CHANGELOG.md
Normal file
46
old.vendor/geocoder-php/common-http/CHANGELOG.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Change Log
|
||||
|
||||
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
|
||||
|
||||
## 4.4.0
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for PHP 8.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Drop support for PHP 7.2
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade PHPUnit to version 9
|
||||
|
||||
## 4.3.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Drop support for PHP < 7.2
|
||||
|
||||
## 4.2.0
|
||||
|
||||
## 4.1.0
|
||||
|
||||
### Changed
|
||||
|
||||
- Refactored `AbstractHttpProvider::getUrlContents` to split it up to different functions. We now
|
||||
got `AbstractHttpProvider::getUrlContents`, `AbstractHttpProvider::getRequest` and `AbstractHttpProvider::getParsedResponse`.
|
||||
|
||||
## 4.0.0
|
||||
|
||||
No changes since beta 2.
|
||||
|
||||
## 4.0.0-beta2
|
||||
|
||||
- Removed `AbstractHttpProvider::setMessageFactory`.
|
||||
- Removed `AbstractHttpProvider::getHttpClient`.
|
||||
- Make sure we have a `MessageFactory` in the constructor of `AbstractHttpProvider`.
|
||||
|
||||
## 4.0.0-beta1
|
||||
|
||||
First release of this library.
|
21
old.vendor/geocoder-php/common-http/LICENSE
Normal file
21
old.vendor/geocoder-php/common-http/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011 — William Durand <william.durand1@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the Geocoder package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace Geocoder\Http\Provider;
|
||||
|
||||
use Geocoder\Exception\InvalidCredentials;
|
||||
use Geocoder\Exception\InvalidServerResponse;
|
||||
use Geocoder\Exception\QuotaExceeded;
|
||||
use Geocoder\Provider\AbstractProvider;
|
||||
use Http\Message\MessageFactory;
|
||||
use Http\Discovery\MessageFactoryDiscovery;
|
||||
use Http\Client\HttpClient;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
abstract class AbstractHttpProvider extends AbstractProvider
|
||||
{
|
||||
/**
|
||||
* @var HttpClient
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var MessageFactory
|
||||
*/
|
||||
private $messageFactory;
|
||||
|
||||
/**
|
||||
* @param HttpClient $client
|
||||
* @param MessageFactory|null $factory
|
||||
*/
|
||||
public function __construct(HttpClient $client, MessageFactory $factory = null)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->messageFactory = $factory ?: MessageFactoryDiscovery::find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL and return contents. If content is empty, an exception will be thrown.
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws InvalidServerResponse
|
||||
*/
|
||||
protected function getUrlContents(string $url): string
|
||||
{
|
||||
$request = $this->getRequest($url);
|
||||
|
||||
return $this->getParsedResponse($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
protected function getRequest(string $url): RequestInterface
|
||||
{
|
||||
return $this->getMessageFactory()->createRequest('GET', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request and return contents. If content is empty, an exception will be thrown.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws InvalidServerResponse
|
||||
*/
|
||||
protected function getParsedResponse(RequestInterface $request): string
|
||||
{
|
||||
$response = $this->getHttpClient()->sendRequest($request);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
if (401 === $statusCode || 403 === $statusCode) {
|
||||
throw new InvalidCredentials();
|
||||
} elseif (429 === $statusCode) {
|
||||
throw new QuotaExceeded();
|
||||
} elseif ($statusCode >= 300) {
|
||||
throw InvalidServerResponse::create((string) $request->getUri(), $statusCode);
|
||||
}
|
||||
|
||||
$body = (string) $response->getBody();
|
||||
if (empty($body)) {
|
||||
throw InvalidServerResponse::emptyResponse((string) $request->getUri());
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTP adapter.
|
||||
*
|
||||
* @return HttpClient
|
||||
*/
|
||||
protected function getHttpClient(): HttpClient
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MessageFactory
|
||||
*/
|
||||
protected function getMessageFactory(): MessageFactory
|
||||
{
|
||||
return $this->messageFactory;
|
||||
}
|
||||
}
|
26
old.vendor/geocoder-php/common-http/Readme.md
Normal file
26
old.vendor/geocoder-php/common-http/Readme.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Common classes for HTTP based Geocoders
|
||||
|
||||
[](http://travis-ci.org/geocoder-php/php-common-http)
|
||||
[](https://packagist.org/packages/geocoder-php/common-http)
|
||||
[](https://packagist.org/packages/geocoder-php/common-http)
|
||||
[](https://packagist.org/packages/geocoder-php/common-http)
|
||||
[](https://scrutinizer-ci.com/g/geocoder-php/php-common-http)
|
||||
[](https://scrutinizer-ci.com/g/geocoder-php/php-common-http)
|
||||
[](LICENSE)
|
||||
|
||||
This package has dependency on HTTP related libraries. Such as the great [HTTPlug](http://httplug.io/) and [PSR7](http://www.php-fig.org/psr/psr-7/).
|
||||
It does contain a an `AbstractHttpProvider`.
|
||||
|
||||
### Install
|
||||
|
||||
In 99% of the cases you do **not** want to install this package directly. You are more likely to install one provider.
|
||||
Have a look at [the documentation](https://github.com/geocoder-php/Geocoder) to see the different providers.
|
||||
|
||||
```bash
|
||||
composer require geocoder-php/common-http
|
||||
```
|
||||
|
||||
### Contribute
|
||||
|
||||
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
|
||||
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues).
|
52
old.vendor/geocoder-php/common-http/composer.json
Normal file
52
old.vendor/geocoder-php/common-http/composer.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "geocoder-php/common-http",
|
||||
"type": "library",
|
||||
"description": "Common files for HTTP based Geocoders",
|
||||
"keywords": [
|
||||
"http geocoder"
|
||||
],
|
||||
"homepage": "http://geocoder-php.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0",
|
||||
"php-http/client-implementation": "^1.0",
|
||||
"php-http/discovery": "^1.6",
|
||||
"php-http/httplug": "^1.0 || ^2.0",
|
||||
"php-http/message-factory": "^1.0.2",
|
||||
"psr/http-message": "^1.0",
|
||||
"psr/http-message-implementation": "^1.0",
|
||||
"willdurand/geocoder": "^4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"nyholm/psr7": "^1.0",
|
||||
"php-http/message": "^1.0",
|
||||
"php-http/mock-client": "^1.0",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"symfony/stopwatch": "~2.5"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Geocoder\\Http\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit",
|
||||
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
|
||||
}
|
||||
}
|
3
old.vendor/geocoder-php/google-maps-provider/.gitignore
vendored
Normal file
3
old.vendor/geocoder-php/google-maps-provider/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
60
old.vendor/geocoder-php/google-maps-provider/CHANGELOG.md
Normal file
60
old.vendor/geocoder-php/google-maps-provider/CHANGELOG.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Change Log
|
||||
|
||||
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
|
||||
|
||||
## 4.6.0
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for PHP 8.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Drop support for PHP 7.2
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade PHPUnit to version 9
|
||||
|
||||
## 4.5.0
|
||||
|
||||
### Added
|
||||
|
||||
- Added `postal_code_suffix` field
|
||||
|
||||
### Removed
|
||||
|
||||
- Drop support for PHP < 7.2
|
||||
|
||||
## 4.4.0
|
||||
|
||||
### Added
|
||||
|
||||
- Added [partial_match](https://developers.google.com/maps/documentation/geocoding/intro#Results)
|
||||
> `partial_match` indicates that the geocoder did not return an exact match for the original request, though it was able to match part of the requested address. You may wish to examine the original request for misspellings and/or an incomplete address.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix "*Administrative level X is defined twice*" issue
|
||||
|
||||
## 4.3.0
|
||||
|
||||
### Added
|
||||
|
||||
- Added [component filtering](https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering).
|
||||
|
||||
## 4.2.0
|
||||
|
||||
### Added
|
||||
|
||||
- Added the `$channel` constructor parameter.
|
||||
|
||||
## 4.1.0
|
||||
|
||||
### Added
|
||||
|
||||
- Support for `SubLocality`.
|
||||
|
||||
## 4.0.0
|
||||
|
||||
First release of this library.
|
486
old.vendor/geocoder-php/google-maps-provider/GoogleMaps.php
Normal file
486
old.vendor/geocoder-php/google-maps-provider/GoogleMaps.php
Normal file
@@ -0,0 +1,486 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the Geocoder package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace Geocoder\Provider\GoogleMaps;
|
||||
|
||||
use Geocoder\Collection;
|
||||
use Geocoder\Exception\InvalidCredentials;
|
||||
use Geocoder\Exception\InvalidServerResponse;
|
||||
use Geocoder\Exception\QuotaExceeded;
|
||||
use Geocoder\Exception\UnsupportedOperation;
|
||||
use Geocoder\Http\Provider\AbstractHttpProvider;
|
||||
use Geocoder\Model\AddressBuilder;
|
||||
use Geocoder\Model\AddressCollection;
|
||||
use Geocoder\Provider\GoogleMaps\Model\GoogleAddress;
|
||||
use Geocoder\Provider\Provider;
|
||||
use Geocoder\Query\GeocodeQuery;
|
||||
use Geocoder\Query\ReverseQuery;
|
||||
use Http\Client\HttpClient;
|
||||
|
||||
/**
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
*/
|
||||
final class GoogleMaps extends AbstractHttpProvider implements Provider
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const GEOCODE_ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const REVERSE_ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=%F,%F';
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $region;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $apiKey;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $clientId;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $privateKey;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $channel;
|
||||
|
||||
/**
|
||||
* Google Maps for Business
|
||||
* https://developers.google.com/maps/documentation/business/
|
||||
* Maps for Business is no longer accepting new signups.
|
||||
*
|
||||
* @param HttpClient $client An HTTP adapter
|
||||
* @param string $clientId Your Client ID
|
||||
* @param string $privateKey Your Private Key (optional)
|
||||
* @param string $region Region biasing (optional)
|
||||
* @param string $apiKey Google Geocoding API key (optional)
|
||||
* @param string $channel Google Channel parameter (optional)
|
||||
*
|
||||
* @return GoogleMaps
|
||||
*/
|
||||
public static function business(
|
||||
HttpClient $client,
|
||||
string $clientId,
|
||||
string $privateKey = null,
|
||||
string $region = null,
|
||||
string $apiKey = null,
|
||||
string $channel = null
|
||||
) {
|
||||
$provider = new self($client, $region, $apiKey);
|
||||
$provider->clientId = $clientId;
|
||||
$provider->privateKey = $privateKey;
|
||||
$provider->channel = $channel;
|
||||
|
||||
return $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HttpClient $client An HTTP adapter
|
||||
* @param string $region Region biasing (optional)
|
||||
* @param string $apiKey Google Geocoding API key (optional)
|
||||
*/
|
||||
public function __construct(HttpClient $client, string $region = null, string $apiKey = null)
|
||||
{
|
||||
parent::__construct($client);
|
||||
|
||||
$this->region = $region;
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
public function geocodeQuery(GeocodeQuery $query): Collection
|
||||
{
|
||||
// Google API returns invalid data if IP address given
|
||||
// This API doesn't handle IPs
|
||||
if (filter_var($query->getText(), FILTER_VALIDATE_IP)) {
|
||||
throw new UnsupportedOperation('The GoogleMaps provider does not support IP addresses, only street addresses.');
|
||||
}
|
||||
|
||||
$url = sprintf(self::GEOCODE_ENDPOINT_URL_SSL, rawurlencode($query->getText()));
|
||||
if (null !== $bounds = $query->getBounds()) {
|
||||
$url .= sprintf(
|
||||
'&bounds=%s,%s|%s,%s',
|
||||
$bounds->getSouth(),
|
||||
$bounds->getWest(),
|
||||
$bounds->getNorth(),
|
||||
$bounds->getEast()
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== $components = $query->getData('components')) {
|
||||
$serializedComponents = is_string($components) ? $components : $this->serializeComponents($components);
|
||||
$url .= sprintf('&components=%s', urlencode($serializedComponents));
|
||||
}
|
||||
|
||||
return $this->fetchUrl($url, $query->getLocale(), $query->getLimit(), $query->getData('region', $this->region));
|
||||
}
|
||||
|
||||
public function reverseQuery(ReverseQuery $query): Collection
|
||||
{
|
||||
$coordinate = $query->getCoordinates();
|
||||
$url = sprintf(self::REVERSE_ENDPOINT_URL_SSL, $coordinate->getLatitude(), $coordinate->getLongitude());
|
||||
|
||||
if (null !== $locationType = $query->getData('location_type')) {
|
||||
$url .= '&location_type='.urlencode($locationType);
|
||||
}
|
||||
|
||||
if (null !== $resultType = $query->getData('result_type')) {
|
||||
$url .= '&result_type='.urlencode($resultType);
|
||||
}
|
||||
|
||||
return $this->fetchUrl($url, $query->getLocale(), $query->getLimit(), $query->getData('region', $this->region));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'google_maps';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param string $locale
|
||||
*
|
||||
* @return string query with extra params
|
||||
*/
|
||||
private function buildQuery(string $url, string $locale = null, string $region = null): string
|
||||
{
|
||||
if (null === $this->apiKey && null === $this->clientId) {
|
||||
throw new InvalidCredentials('You must provide an API key. Keyless access was removed in June, 2016');
|
||||
}
|
||||
|
||||
if (null !== $locale) {
|
||||
$url = sprintf('%s&language=%s', $url, $locale);
|
||||
}
|
||||
|
||||
if (null !== $region) {
|
||||
$url = sprintf('%s®ion=%s', $url, $region);
|
||||
}
|
||||
|
||||
if (null !== $this->apiKey) {
|
||||
$url = sprintf('%s&key=%s', $url, $this->apiKey);
|
||||
}
|
||||
|
||||
if (null !== $this->clientId) {
|
||||
$url = sprintf('%s&client=%s', $url, $this->clientId);
|
||||
|
||||
if (null !== $this->channel) {
|
||||
$url = sprintf('%s&channel=%s', $url, $this->channel);
|
||||
}
|
||||
|
||||
if (null !== $this->privateKey) {
|
||||
$url = $this->signQuery($url);
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param string $locale
|
||||
* @param int $limit
|
||||
* @param string $region
|
||||
*
|
||||
* @return AddressCollection
|
||||
*
|
||||
* @throws InvalidServerResponse
|
||||
* @throws InvalidCredentials
|
||||
*/
|
||||
private function fetchUrl(string $url, string $locale = null, int $limit, string $region = null): AddressCollection
|
||||
{
|
||||
$url = $this->buildQuery($url, $locale, $region);
|
||||
$content = $this->getUrlContents($url);
|
||||
$json = $this->validateResponse($url, $content);
|
||||
|
||||
// no result
|
||||
if (!isset($json->results) || !count($json->results) || 'OK' !== $json->status) {
|
||||
return new AddressCollection([]);
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach ($json->results as $result) {
|
||||
$builder = new AddressBuilder($this->getName());
|
||||
$this->parseCoordinates($builder, $result);
|
||||
|
||||
// set official Google place id
|
||||
if (isset($result->place_id)) {
|
||||
$builder->setValue('id', $result->place_id);
|
||||
}
|
||||
|
||||
// update address components
|
||||
foreach ($result->address_components as $component) {
|
||||
foreach ($component->types as $type) {
|
||||
$this->updateAddressComponent($builder, $type, $component);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var GoogleAddress $address */
|
||||
$address = $builder->build(GoogleAddress::class);
|
||||
$address = $address->withId($builder->getValue('id'));
|
||||
if (isset($result->geometry->location_type)) {
|
||||
$address = $address->withLocationType($result->geometry->location_type);
|
||||
}
|
||||
if (isset($result->types)) {
|
||||
$address = $address->withResultType($result->types);
|
||||
}
|
||||
if (isset($result->formatted_address)) {
|
||||
$address = $address->withFormattedAddress($result->formatted_address);
|
||||
}
|
||||
|
||||
$results[] = $address
|
||||
->withStreetAddress($builder->getValue('street_address'))
|
||||
->withIntersection($builder->getValue('intersection'))
|
||||
->withPolitical($builder->getValue('political'))
|
||||
->withColloquialArea($builder->getValue('colloquial_area'))
|
||||
->withWard($builder->getValue('ward'))
|
||||
->withNeighborhood($builder->getValue('neighborhood'))
|
||||
->withPremise($builder->getValue('premise'))
|
||||
->withSubpremise($builder->getValue('subpremise'))
|
||||
->withNaturalFeature($builder->getValue('natural_feature'))
|
||||
->withAirport($builder->getValue('airport'))
|
||||
->withPark($builder->getValue('park'))
|
||||
->withPointOfInterest($builder->getValue('point_of_interest'))
|
||||
->withEstablishment($builder->getValue('establishment'))
|
||||
->withSubLocalityLevels($builder->getValue('subLocalityLevel', []))
|
||||
->withPostalCodeSuffix($builder->getValue('postal_code_suffix'))
|
||||
->withPartialMatch($result->partial_match ?? false);
|
||||
|
||||
if (count($results) >= $limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new AddressCollection($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update current resultSet with given key/value.
|
||||
*
|
||||
* @param AddressBuilder $builder
|
||||
* @param string $type Component type
|
||||
* @param object $values The component values
|
||||
*/
|
||||
private function updateAddressComponent(AddressBuilder $builder, string $type, $values)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'postal_code':
|
||||
$builder->setPostalCode($values->long_name);
|
||||
|
||||
break;
|
||||
|
||||
case 'locality':
|
||||
case 'postal_town':
|
||||
$builder->setLocality($values->long_name);
|
||||
|
||||
break;
|
||||
|
||||
case 'administrative_area_level_1':
|
||||
case 'administrative_area_level_2':
|
||||
case 'administrative_area_level_3':
|
||||
case 'administrative_area_level_4':
|
||||
case 'administrative_area_level_5':
|
||||
$builder->addAdminLevel(intval(substr($type, -1)), $values->long_name, $values->short_name);
|
||||
|
||||
break;
|
||||
|
||||
case 'sublocality_level_1':
|
||||
case 'sublocality_level_2':
|
||||
case 'sublocality_level_3':
|
||||
case 'sublocality_level_4':
|
||||
case 'sublocality_level_5':
|
||||
$subLocalityLevel = $builder->getValue('subLocalityLevel', []);
|
||||
$subLocalityLevel[] = [
|
||||
'level' => intval(substr($type, -1)),
|
||||
'name' => $values->long_name,
|
||||
'code' => $values->short_name,
|
||||
];
|
||||
$builder->setValue('subLocalityLevel', $subLocalityLevel);
|
||||
|
||||
break;
|
||||
|
||||
case 'country':
|
||||
$builder->setCountry($values->long_name);
|
||||
$builder->setCountryCode($values->short_name);
|
||||
|
||||
break;
|
||||
|
||||
case 'street_number':
|
||||
$builder->setStreetNumber($values->long_name);
|
||||
|
||||
break;
|
||||
|
||||
case 'route':
|
||||
$builder->setStreetName($values->long_name);
|
||||
|
||||
break;
|
||||
|
||||
case 'sublocality':
|
||||
$builder->setSubLocality($values->long_name);
|
||||
|
||||
break;
|
||||
|
||||
case 'street_address':
|
||||
case 'intersection':
|
||||
case 'political':
|
||||
case 'colloquial_area':
|
||||
case 'ward':
|
||||
case 'neighborhood':
|
||||
case 'premise':
|
||||
case 'subpremise':
|
||||
case 'natural_feature':
|
||||
case 'airport':
|
||||
case 'park':
|
||||
case 'point_of_interest':
|
||||
case 'establishment':
|
||||
case 'postal_code_suffix':
|
||||
$builder->setValue($type, $values->long_name);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a URL with a given crypto key
|
||||
* Note that this URL must be properly URL-encoded
|
||||
* src: http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/UrlSigner.php-source.
|
||||
*
|
||||
* @param string $query Query to be signed
|
||||
*
|
||||
* @return string $query query with signature appended
|
||||
*/
|
||||
private function signQuery(string $query): string
|
||||
{
|
||||
$url = parse_url($query);
|
||||
|
||||
$urlPartToSign = $url['path'].'?'.$url['query'];
|
||||
|
||||
// Decode the private key into its binary format
|
||||
$decodedKey = base64_decode(str_replace(['-', '_'], ['+', '/'], $this->privateKey));
|
||||
|
||||
// Create a signature using the private key and the URL-encoded
|
||||
// string using HMAC SHA1. This signature will be binary.
|
||||
$signature = hash_hmac('sha1', $urlPartToSign, $decodedKey, true);
|
||||
|
||||
$encodedSignature = str_replace(['+', '/'], ['-', '_'], base64_encode($signature));
|
||||
|
||||
return sprintf('%s&signature=%s', $query, $encodedSignature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the component query parameter.
|
||||
*
|
||||
* @param array $components
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function serializeComponents(array $components): string
|
||||
{
|
||||
return implode('|', array_map(function ($name, $value) {
|
||||
return sprintf('%s:%s', $name, $value);
|
||||
}, array_keys($components), $components));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the response content and validate it to make sure it does not have any errors.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $content
|
||||
*
|
||||
* @return \Stdclass result form json_decode()
|
||||
*
|
||||
* @throws InvalidCredentials
|
||||
* @throws InvalidServerResponse
|
||||
* @throws QuotaExceeded
|
||||
*/
|
||||
private function validateResponse(string $url, $content)
|
||||
{
|
||||
// Throw exception if invalid clientID and/or privateKey used with GoogleMapsBusinessProvider
|
||||
if (false !== strpos($content, "Provided 'signature' is not valid for the provided client ID")) {
|
||||
throw new InvalidCredentials(sprintf('Invalid client ID / API Key %s', $url));
|
||||
}
|
||||
|
||||
$json = json_decode($content);
|
||||
|
||||
// API error
|
||||
if (!isset($json)) {
|
||||
throw InvalidServerResponse::create($url);
|
||||
}
|
||||
|
||||
if ('REQUEST_DENIED' === $json->status && 'The provided API key is invalid.' === $json->error_message) {
|
||||
throw new InvalidCredentials(sprintf('API key is invalid %s', $url));
|
||||
}
|
||||
|
||||
if ('REQUEST_DENIED' === $json->status) {
|
||||
throw new InvalidServerResponse(sprintf('API access denied. Request: %s - Message: %s', $url, $json->error_message));
|
||||
}
|
||||
|
||||
// you are over your quota
|
||||
if ('OVER_QUERY_LIMIT' === $json->status) {
|
||||
throw new QuotaExceeded(sprintf('Daily quota exceeded %s', $url));
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse coordinates and bounds.
|
||||
*
|
||||
* @param AddressBuilder $builder
|
||||
* @param \Stdclass $result
|
||||
*/
|
||||
private function parseCoordinates(AddressBuilder $builder, $result)
|
||||
{
|
||||
$coordinates = $result->geometry->location;
|
||||
$builder->setCoordinates($coordinates->lat, $coordinates->lng);
|
||||
|
||||
if (isset($result->geometry->bounds)) {
|
||||
$builder->setBounds(
|
||||
$result->geometry->bounds->southwest->lat,
|
||||
$result->geometry->bounds->southwest->lng,
|
||||
$result->geometry->bounds->northeast->lat,
|
||||
$result->geometry->bounds->northeast->lng
|
||||
);
|
||||
} elseif (isset($result->geometry->viewport)) {
|
||||
$builder->setBounds(
|
||||
$result->geometry->viewport->southwest->lat,
|
||||
$result->geometry->viewport->southwest->lng,
|
||||
$result->geometry->viewport->northeast->lat,
|
||||
$result->geometry->viewport->northeast->lng
|
||||
);
|
||||
} elseif ('ROOFTOP' === $result->geometry->location_type) {
|
||||
// Fake bounds
|
||||
$builder->setBounds(
|
||||
$coordinates->lat,
|
||||
$coordinates->lng,
|
||||
$coordinates->lat,
|
||||
$coordinates->lng
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
21
old.vendor/geocoder-php/google-maps-provider/LICENSE
Normal file
21
old.vendor/geocoder-php/google-maps-provider/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011 — William Durand <william.durand1@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@@ -0,0 +1,561 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the Geocoder package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace Geocoder\Provider\GoogleMaps\Model;
|
||||
|
||||
use Geocoder\Model\Address;
|
||||
use Geocoder\Model\AdminLevel;
|
||||
use Geocoder\Model\AdminLevelCollection;
|
||||
|
||||
/**
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
final class GoogleAddress extends Address
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $locationType;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $resultType = [];
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $formattedAddress;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $streetAddress;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $intersection;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $postalCodeSuffix;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $political;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $colloquialArea;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $ward;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $neighborhood;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $premise;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $subpremise;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $naturalFeature;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $airport;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $park;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $pointOfInterest;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $establishment;
|
||||
|
||||
/**
|
||||
* @var AdminLevelCollection
|
||||
*/
|
||||
private $subLocalityLevels;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $partialMatch;
|
||||
|
||||
/**
|
||||
* @param string|null $id
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withId(string $id = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->id = $id;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://developers.google.com/places/place-id
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $locationType
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withLocationType(string $locationType = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->locationType = $locationType;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLocationType()
|
||||
{
|
||||
return $this->locationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResultType(): array
|
||||
{
|
||||
return $this->resultType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $resultType
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withResultType(array $resultType)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->resultType = $resultType;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFormattedAddress()
|
||||
{
|
||||
return $this->formattedAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $formattedAddress
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withFormattedAddress(string $formattedAddress = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->formattedAddress = $formattedAddress;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAirport()
|
||||
{
|
||||
return $this->airport;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $airport
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withAirport(string $airport = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->airport = $airport;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getColloquialArea()
|
||||
{
|
||||
return $this->colloquialArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $colloquialArea
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withColloquialArea(string $colloquialArea = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->colloquialArea = $colloquialArea;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIntersection()
|
||||
{
|
||||
return $this->intersection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $intersection
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withIntersection(string $intersection = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->intersection = $intersection;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPostalCodeSuffix()
|
||||
{
|
||||
return $this->postalCodeSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $postalCodeSuffix
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withPostalCodeSuffix(string $postalCodeSuffix = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->postalCodeSuffix = $postalCodeSuffix;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNaturalFeature()
|
||||
{
|
||||
return $this->naturalFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $naturalFeature
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withNaturalFeature(string $naturalFeature = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->naturalFeature = $naturalFeature;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNeighborhood()
|
||||
{
|
||||
return $this->neighborhood;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $neighborhood
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withNeighborhood(string $neighborhood = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->neighborhood = $neighborhood;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPark()
|
||||
{
|
||||
return $this->park;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $park
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withPark(string $park = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->park = $park;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPointOfInterest()
|
||||
{
|
||||
return $this->pointOfInterest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $pointOfInterest
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withPointOfInterest(string $pointOfInterest = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->pointOfInterest = $pointOfInterest;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPolitical()
|
||||
{
|
||||
return $this->political;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $political
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withPolitical(string $political = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->political = $political;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPremise()
|
||||
{
|
||||
return $this->premise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $premise
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withPremise(string $premise = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->premise = $premise;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStreetAddress()
|
||||
{
|
||||
return $this->streetAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $streetAddress
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withStreetAddress(string $streetAddress = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->streetAddress = $streetAddress;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSubpremise()
|
||||
{
|
||||
return $this->subpremise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $subpremise
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withSubpremise(string $subpremise = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->subpremise = $subpremise;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getWard()
|
||||
{
|
||||
return $this->ward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $ward
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withWard(string $ward = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->ward = $ward;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getEstablishment()
|
||||
{
|
||||
return $this->establishment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $establishment
|
||||
*
|
||||
* @return GoogleAddress
|
||||
*/
|
||||
public function withEstablishment(string $establishment = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->establishment = $establishment;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AdminLevelCollection
|
||||
*/
|
||||
public function getSubLocalityLevels()
|
||||
{
|
||||
return $this->subLocalityLevels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $subLocalityLevel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withSubLocalityLevels(array $subLocalityLevel)
|
||||
{
|
||||
$subLocalityLevels = [];
|
||||
foreach ($subLocalityLevel as $level) {
|
||||
if (empty($level['level'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $level['name'] ?? $level['code'] ?? '';
|
||||
if (empty($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subLocalityLevels[] = new AdminLevel($level['level'], $name, $level['code'] ?? null);
|
||||
}
|
||||
|
||||
$subLocalityLevels = array_unique($subLocalityLevels);
|
||||
|
||||
$new = clone $this;
|
||||
$new->subLocalityLevels = new AdminLevelCollection($subLocalityLevels);
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPartialMatch()
|
||||
{
|
||||
return $this->partialMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $partialMatch
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withPartialMatch(bool $partialMatch)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->partialMatch = $partialMatch;
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
53
old.vendor/geocoder-php/google-maps-provider/Readme.md
Normal file
53
old.vendor/geocoder-php/google-maps-provider/Readme.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Google Maps Geocoder provider
|
||||
[](http://travis-ci.org/geocoder-php/google-maps-provider)
|
||||
[](https://packagist.org/packages/geocoder-php/google-maps-provider)
|
||||
[](https://packagist.org/packages/geocoder-php/google-maps-provider)
|
||||
[](https://packagist.org/packages/geocoder-php/google-maps-provider)
|
||||
[](https://scrutinizer-ci.com/g/geocoder-php/google-maps-provider)
|
||||
[](https://scrutinizer-ci.com/g/geocoder-php/google-maps-provider)
|
||||
[](LICENSE)
|
||||
|
||||
This is the Google Maps provider from the PHP Geocoder. This is a **READ ONLY** repository. See the
|
||||
[main repo](https://github.com/geocoder-php/Geocoder) for information and documentation.
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
$httpClient = new \Http\Adapter\Guzzle6\Client();
|
||||
|
||||
// You must provide an API key
|
||||
$provider = new \Geocoder\Provider\GoogleMaps\GoogleMaps($httpClient, null, 'your-api-key');
|
||||
|
||||
$result = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));
|
||||
```
|
||||
|
||||
All requests require a valid API key, however google does have a [free tier](https://cloud.google.com/maps-platform/pricing/) available.
|
||||
Please see [this page for information on getting an API key](https://developers.google.com/maps/documentation/geocoding/get-api-key).
|
||||
|
||||
### Google Maps for Business
|
||||
|
||||
Previously, google offered a "Business" version of their APIs. The service has been deprecated, however existing clients
|
||||
can use the static `business` method on the provider to create a client:
|
||||
|
||||
```php
|
||||
|
||||
$httpClient = new \Http\Adapter\Guzzle6\Client();
|
||||
|
||||
// Client ID is required. Private key is optional.
|
||||
$provider = \Geocoder\Provider\GoogleMaps\GoogleMaps::business($httpClient, 'your-client-id', 'your-private-key');
|
||||
|
||||
$result = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));
|
||||
```
|
||||
|
||||
### Install
|
||||
|
||||
```bash
|
||||
composer require geocoder-php/google-maps-provider
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Contribute
|
||||
|
||||
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
|
||||
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues).
|
47
old.vendor/geocoder-php/google-maps-provider/composer.json
Normal file
47
old.vendor/geocoder-php/google-maps-provider/composer.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "geocoder-php/google-maps-provider",
|
||||
"type": "library",
|
||||
"description": "Geocoder GoogleMaps adapter",
|
||||
"keywords": [],
|
||||
"homepage": "http://geocoder-php.org/Geocoder/",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "William Durand",
|
||||
"email": "william.durand1@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0",
|
||||
"geocoder-php/common-http": "^4.0",
|
||||
"willdurand/geocoder": "^4.0"
|
||||
},
|
||||
"provide": {
|
||||
"geocoder-php/provider-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"geocoder-php/provider-integration-tests": "^1.0",
|
||||
"php-http/curl-client": "^2.2",
|
||||
"php-http/message": "^1.0",
|
||||
"phpunit/phpunit": "^9.5"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Geocoder\\Provider\\GoogleMaps\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit",
|
||||
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
|
||||
}
|
||||
}
|
3
old.vendor/geocoder-php/mapquest-provider/.gitignore
vendored
Normal file
3
old.vendor/geocoder-php/mapquest-provider/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
31
old.vendor/geocoder-php/mapquest-provider/CHANGELOG.md
Normal file
31
old.vendor/geocoder-php/mapquest-provider/CHANGELOG.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Change Log
|
||||
|
||||
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
|
||||
|
||||
## 4.2.0
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for PHP 8.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Drop support for PHP 7.2
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade PHPUnit to version 9
|
||||
|
||||
## 4.1.0
|
||||
|
||||
### Added
|
||||
|
||||
- Add `5BOX` support for address
|
||||
|
||||
### Removed
|
||||
|
||||
- Drop support for PHP < 7.2
|
||||
|
||||
## 4.0.0
|
||||
|
||||
First release of this library.
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Geocoder package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace Geocoder\Provider\MapQuest;
|
||||
|
||||
use Geocoder\Location;
|
||||
|
||||
interface GetAddressInterface
|
||||
{
|
||||
/**
|
||||
* @return Location|null
|
||||
*/
|
||||
public function getAddress();
|
||||
}
|
21
old.vendor/geocoder-php/mapquest-provider/LICENSE
Normal file
21
old.vendor/geocoder-php/mapquest-provider/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011 — William Durand <william.durand1@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
417
old.vendor/geocoder-php/mapquest-provider/MapQuest.php
Normal file
417
old.vendor/geocoder-php/mapquest-provider/MapQuest.php
Normal file
@@ -0,0 +1,417 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the Geocoder package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace Geocoder\Provider\MapQuest;
|
||||
|
||||
use Geocoder\Collection;
|
||||
use Geocoder\Exception\InvalidArgument;
|
||||
use Geocoder\Exception\InvalidCredentials;
|
||||
use Geocoder\Exception\InvalidServerResponse;
|
||||
use Geocoder\Exception\QuotaExceeded;
|
||||
use Geocoder\Exception\UnsupportedOperation;
|
||||
use Geocoder\Http\Provider\AbstractHttpProvider;
|
||||
use Geocoder\Location;
|
||||
use Geocoder\Model\Address;
|
||||
use Geocoder\Model\AddressCollection;
|
||||
use Geocoder\Model\AdminLevel;
|
||||
use Geocoder\Model\Bounds;
|
||||
use Geocoder\Model\Country;
|
||||
use Geocoder\Query\GeocodeQuery;
|
||||
use Geocoder\Query\ReverseQuery;
|
||||
use Geocoder\Provider\Provider;
|
||||
use Http\Client\HttpClient;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
*/
|
||||
final class MapQuest extends AbstractHttpProvider implements Provider
|
||||
{
|
||||
const DATA_KEY_ADDRESS = 'address';
|
||||
|
||||
const KEY_API_KEY = 'key';
|
||||
|
||||
const KEY_LOCATION = 'location';
|
||||
|
||||
const KEY_OUT_FORMAT = 'outFormat';
|
||||
|
||||
const KEY_MAX_RESULTS = 'maxResults';
|
||||
|
||||
const KEY_THUMB_MAPS = 'thumbMaps';
|
||||
|
||||
const KEY_INTL_MODE = 'intlMode';
|
||||
|
||||
const KEY_BOUNDING_BOX = 'boundingBox';
|
||||
|
||||
const KEY_LAT = 'lat';
|
||||
|
||||
const KEY_LNG = 'lng';
|
||||
|
||||
const MODE_5BOX = '5BOX';
|
||||
|
||||
const OPEN_BASE_URL = 'https://open.mapquestapi.com/geocoding/v1/';
|
||||
|
||||
const LICENSED_BASE_URL = 'https://www.mapquestapi.com/geocoding/v1/';
|
||||
|
||||
const GEOCODE_ENDPOINT = 'address';
|
||||
|
||||
const DEFAULT_GEOCODE_PARAMS = [
|
||||
self::KEY_LOCATION => '',
|
||||
self::KEY_OUT_FORMAT => 'json',
|
||||
self::KEY_API_KEY => '',
|
||||
];
|
||||
|
||||
const DEFAULT_GEOCODE_OPTIONS = [
|
||||
self::KEY_MAX_RESULTS => 3,
|
||||
self::KEY_THUMB_MAPS => false,
|
||||
];
|
||||
|
||||
const REVERSE_ENDPOINT = 'reverse';
|
||||
|
||||
const ADMIN_LEVEL_STATE = 1;
|
||||
|
||||
const ADMIN_LEVEL_COUNTY = 2;
|
||||
|
||||
/**
|
||||
* MapQuest offers two geocoding endpoints one commercial (true) and one open (false)
|
||||
* More information: http://developer.mapquest.com/web/tools/getting-started/platform/licensed-vs-open.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $licensed;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $useRoadPosition;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $apiKey;
|
||||
|
||||
/**
|
||||
* @param HttpClient $client an HTTP adapter
|
||||
* @param string $apiKey an API key
|
||||
* @param bool $licensed true to use MapQuest's licensed endpoints, default is false to use the open endpoints (optional)
|
||||
* @param bool $useRoadPosition true to use nearest point on a road for the entrance, false to use map display position
|
||||
*/
|
||||
public function __construct(HttpClient $client, string $apiKey, bool $licensed = false, bool $useRoadPosition = false)
|
||||
{
|
||||
if (empty($apiKey)) {
|
||||
throw new InvalidCredentials('No API key provided.');
|
||||
}
|
||||
|
||||
$this->apiKey = $apiKey;
|
||||
$this->licensed = $licensed;
|
||||
$this->useRoadPosition = $useRoadPosition;
|
||||
parent::__construct($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function geocodeQuery(GeocodeQuery $query): Collection
|
||||
{
|
||||
$params = static::DEFAULT_GEOCODE_PARAMS;
|
||||
$params[static::KEY_API_KEY] = $this->apiKey;
|
||||
|
||||
$options = static::DEFAULT_GEOCODE_OPTIONS;
|
||||
$options[static::KEY_MAX_RESULTS] = $query->getLimit();
|
||||
|
||||
$useGetQuery = true;
|
||||
|
||||
$address = $this->extractAddressFromQuery($query);
|
||||
if ($address instanceof Location) {
|
||||
$params[static::KEY_LOCATION] = $this->mapAddressToArray($address);
|
||||
$options[static::KEY_INTL_MODE] = static::MODE_5BOX;
|
||||
$useGetQuery = false;
|
||||
} else {
|
||||
$addressAsText = $query->getText();
|
||||
|
||||
if (!$addressAsText) {
|
||||
throw new InvalidArgument('Cannot geocode empty address');
|
||||
}
|
||||
|
||||
// This API doesn't handle IPs
|
||||
if (filter_var($addressAsText, FILTER_VALIDATE_IP)) {
|
||||
throw new UnsupportedOperation('The MapQuest provider does not support IP addresses, only street addresses.');
|
||||
}
|
||||
|
||||
$params[static::KEY_LOCATION] = $addressAsText;
|
||||
}
|
||||
|
||||
$bounds = $query->getBounds();
|
||||
if ($bounds instanceof Bounds) {
|
||||
$options[static::KEY_BOUNDING_BOX] = $this->mapBoundsToArray($bounds);
|
||||
$useGetQuery = false;
|
||||
}
|
||||
|
||||
if ($useGetQuery) {
|
||||
$params = $this->addOptionsForGetQuery($params, $options);
|
||||
|
||||
return $this->executeGetQuery(static::GEOCODE_ENDPOINT, $params);
|
||||
} else {
|
||||
$params = $this->addOptionsForPostQuery($params, $options);
|
||||
|
||||
return $this->executePostQuery(static::GEOCODE_ENDPOINT, $params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reverseQuery(ReverseQuery $query): Collection
|
||||
{
|
||||
$coordinates = $query->getCoordinates();
|
||||
$longitude = $coordinates->getLongitude();
|
||||
$latitude = $coordinates->getLatitude();
|
||||
|
||||
$params = [
|
||||
static::KEY_API_KEY => $this->apiKey,
|
||||
static::KEY_LAT => $latitude,
|
||||
static::KEY_LNG => $longitude,
|
||||
];
|
||||
|
||||
return $this->executeGetQuery(static::REVERSE_ENDPOINT, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'map_quest';
|
||||
}
|
||||
|
||||
private function extractAddressFromQuery(GeocodeQuery $query)
|
||||
{
|
||||
return $query->getData(static::DATA_KEY_ADDRESS);
|
||||
}
|
||||
|
||||
private function getUrl($endpoint): string
|
||||
{
|
||||
if ($this->licensed) {
|
||||
$baseUrl = static::LICENSED_BASE_URL;
|
||||
} else {
|
||||
$baseUrl = static::OPEN_BASE_URL;
|
||||
}
|
||||
|
||||
return $baseUrl.$endpoint;
|
||||
}
|
||||
|
||||
private function addGetQuery(string $url, array $params): string
|
||||
{
|
||||
return $url.'?'.http_build_query($params, '', '&', PHP_QUERY_RFC3986);
|
||||
}
|
||||
|
||||
private function addOptionsForGetQuery(array $params, array $options): array
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
if (false === $value) {
|
||||
$value = 'false';
|
||||
} elseif (true === $value) {
|
||||
$value = 'true';
|
||||
}
|
||||
$params[$key] = $value;
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
private function addOptionsForPostQuery(array $params, array $options): array
|
||||
{
|
||||
$params['options'] = $options;
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
private function executePostQuery(string $endpoint, array $params)
|
||||
{
|
||||
$url = $this->getUrl($endpoint);
|
||||
|
||||
$appKey = $params[static::KEY_API_KEY];
|
||||
unset($params[static::KEY_API_KEY]);
|
||||
$url .= '?key='.$appKey;
|
||||
|
||||
$requestBody = json_encode($params);
|
||||
$request = $this->getMessageFactory()->createRequest('POST', $url, [], $requestBody);
|
||||
|
||||
$response = $this->getHttpClient()->sendRequest($request);
|
||||
$content = $this->parseHttpResponse($response, $url);
|
||||
|
||||
return $this->parseResponseContent($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return AddressCollection
|
||||
*/
|
||||
private function executeGetQuery(string $endpoint, array $params): AddressCollection
|
||||
{
|
||||
$baseUrl = $this->getUrl($endpoint);
|
||||
$url = $this->addGetQuery($baseUrl, $params);
|
||||
|
||||
$content = $this->getUrlContents($url);
|
||||
|
||||
return $this->parseResponseContent($content);
|
||||
}
|
||||
|
||||
private function parseResponseContent(string $content): AddressCollection
|
||||
{
|
||||
$json = json_decode($content, true);
|
||||
|
||||
if (!isset($json['results']) || empty($json['results'])) {
|
||||
return new AddressCollection([]);
|
||||
}
|
||||
|
||||
$locations = $json['results'][0]['locations'];
|
||||
|
||||
if (empty($locations)) {
|
||||
return new AddressCollection([]);
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach ($locations as $location) {
|
||||
if ($location['street'] || $location['postalCode'] || $location['adminArea5'] || $location['adminArea4'] || $location['adminArea3']) {
|
||||
$admins = [];
|
||||
|
||||
$state = $location['adminArea3'];
|
||||
if ($state) {
|
||||
$code = null;
|
||||
if (2 == strlen($state)) {
|
||||
$code = $state;
|
||||
}
|
||||
$admins[] = [
|
||||
'name' => $state,
|
||||
'code' => $code,
|
||||
'level' => static::ADMIN_LEVEL_STATE,
|
||||
];
|
||||
}
|
||||
|
||||
if ($location['adminArea4']) {
|
||||
$admins[] = ['name' => $location['adminArea4'], 'level' => static::ADMIN_LEVEL_COUNTY];
|
||||
}
|
||||
|
||||
$position = $location['latLng'];
|
||||
if (!$this->useRoadPosition) {
|
||||
if ($location['displayLatLng']) {
|
||||
$position = $location['displayLatLng'];
|
||||
}
|
||||
}
|
||||
|
||||
$results[] = Address::createFromArray([
|
||||
'providedBy' => $this->getName(),
|
||||
'latitude' => $position['lat'],
|
||||
'longitude' => $position['lng'],
|
||||
'streetName' => $location['street'] ?: null,
|
||||
'locality' => $location['adminArea5'] ?: null,
|
||||
'subLocality' => $location['adminArea6'] ?: null,
|
||||
'postalCode' => $location['postalCode'] ?: null,
|
||||
'adminLevels' => $admins,
|
||||
'country' => $location['adminArea1'] ?: null,
|
||||
'countryCode' => $location['adminArea1'] ?: null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return new AddressCollection($results);
|
||||
}
|
||||
|
||||
private function mapAddressToArray(Location $address): array
|
||||
{
|
||||
$location = [];
|
||||
|
||||
$streetParts = [
|
||||
trim($address->getStreetNumber() ?: ''),
|
||||
trim($address->getStreetName() ?: ''),
|
||||
];
|
||||
$street = implode(' ', array_filter($streetParts));
|
||||
if ($street) {
|
||||
$location['street'] = $street;
|
||||
}
|
||||
|
||||
if ($address->getSubLocality()) {
|
||||
$location['adminArea6'] = $address->getSubLocality();
|
||||
$location['adminArea6Type'] = 'Neighborhood';
|
||||
}
|
||||
|
||||
if ($address->getLocality()) {
|
||||
$location['adminArea5'] = $address->getLocality();
|
||||
$location['adminArea5Type'] = 'City';
|
||||
}
|
||||
|
||||
/** @var AdminLevel $adminLevel */
|
||||
foreach ($address->getAdminLevels() as $adminLevel) {
|
||||
switch ($adminLevel->getLevel()) {
|
||||
case static::ADMIN_LEVEL_STATE:
|
||||
$state = $adminLevel->getCode();
|
||||
if (!$state) {
|
||||
$state = $adminLevel->getName();
|
||||
}
|
||||
$location['adminArea3'] = $state;
|
||||
$location['adminArea3Type'] = 'State';
|
||||
|
||||
break;
|
||||
case static::ADMIN_LEVEL_COUNTY:
|
||||
$county = $adminLevel->getName();
|
||||
$location['adminArea4'] = $county;
|
||||
$location['adminArea4Type'] = 'County';
|
||||
}
|
||||
}
|
||||
|
||||
$country = $address->getCountry();
|
||||
if ($country instanceof Country) {
|
||||
$code = $country->getCode();
|
||||
if (!$code) {
|
||||
$code = $country->getName();
|
||||
}
|
||||
$location['adminArea1'] = $code;
|
||||
$location['adminArea1Type'] = 'Country';
|
||||
}
|
||||
|
||||
$postalCode = $address->getPostalCode();
|
||||
if ($postalCode) {
|
||||
$location['postalCode'] = $address->getPostalCode();
|
||||
}
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
private function mapBoundsToArray(Bounds $bounds)
|
||||
{
|
||||
return [
|
||||
'ul' => [static::KEY_LAT => $bounds->getNorth(), static::KEY_LNG => $bounds->getWest()],
|
||||
'lr' => [static::KEY_LAT => $bounds->getSouth(), static::KEY_LNG => $bounds->getEast()],
|
||||
];
|
||||
}
|
||||
|
||||
protected function parseHttpResponse(ResponseInterface $response, string $url): string
|
||||
{
|
||||
$statusCode = $response->getStatusCode();
|
||||
if (401 === $statusCode || 403 === $statusCode) {
|
||||
throw new InvalidCredentials();
|
||||
} elseif (429 === $statusCode) {
|
||||
throw new QuotaExceeded();
|
||||
} elseif ($statusCode >= 300) {
|
||||
throw InvalidServerResponse::create($url, $statusCode);
|
||||
}
|
||||
|
||||
$body = (string) $response->getBody();
|
||||
if (empty($body)) {
|
||||
throw InvalidServerResponse::emptyResponse($url);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
78
old.vendor/geocoder-php/mapquest-provider/Readme.md
Normal file
78
old.vendor/geocoder-php/mapquest-provider/Readme.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# MapQuest Geocoder provider
|
||||
[](http://travis-ci.org/geocoder-php/mapquest-provider)
|
||||
[](https://packagist.org/packages/geocoder-php/mapquest-provider)
|
||||
[](https://packagist.org/packages/geocoder-php/mapquest-provider)
|
||||
[](https://packagist.org/packages/geocoder-php/mapquest-provider)
|
||||
[](https://scrutinizer-ci.com/g/geocoder-php/mapquest-provider)
|
||||
[](https://scrutinizer-ci.com/g/geocoder-php/mapquest-provider)
|
||||
[](LICENSE)
|
||||
|
||||
This is the MapQuest provider from the PHP Geocoder. This is a **READ ONLY** repository. See the
|
||||
[main repo](https://github.com/geocoder-php/Geocoder) for information and documentation.
|
||||
|
||||
### Install
|
||||
|
||||
```bash
|
||||
composer require geocoder-php/mapquest-provider
|
||||
```
|
||||
|
||||
### Geocode with more exact addresses
|
||||
|
||||
The MapQuest Provider allows you to create and pass geocode queries based on a full Address object of
|
||||
class `Geocoder\Model\Address` or any other object that implements `Geocoder\Location`.
|
||||
|
||||
This will take advantage of what MapQuest calls the 5-box Input address format.
|
||||
Quote from [MapQuest Developer: Specifying Locations](https://developer.mapquest.com/documentation/common/forming-locations/):
|
||||
> The 5-Box Input address format (which is compatible with JSON and XML),
|
||||
> allows for a higher degree of address specification by entering the full address in its individual location parameters.
|
||||
> The 5-Box Input format is beneficial as it bypasses the parsing functionality of the single-line request.
|
||||
|
||||
If you have an object of a class that implements `Geocoder\Location` stored in the variable `$address`,
|
||||
this new type of GeocodeQuery can be created with:
|
||||
```
|
||||
$query = GeocodeQuery::create('foobar');
|
||||
$query = $query->withData(MapQuest::DATA_KEY_ADDRESS, $address);
|
||||
```
|
||||
|
||||
If you want the GeocodeQuery to also work fine with all the other providers,
|
||||
you will need to convert the `$address` object to a text string first.
|
||||
Say you have stored this text string in the variable `$addressAsString`, the the example will read as follows:
|
||||
```
|
||||
$query = GeocodeQuery::create($addressAsString);
|
||||
$query = $query->withData(MapQuest::DATA_KEY_ADDRESS, $address);
|
||||
```
|
||||
|
||||
Here is a more complete example with use statements, and building of the address object:
|
||||
|
||||
**Example**
|
||||
```
|
||||
use Geocoder\Model\AddressBuilder;
|
||||
use Geocoder\Provider\MapQuest\MapQuest;
|
||||
use Geocoder\Query\GeocodeQuery;
|
||||
|
||||
$provider = new MapQuest($httpClient, $apiKey);
|
||||
|
||||
$addressBuilder = new AddressBuilder('Address provided by me');
|
||||
$addressBuilder
|
||||
->setStreetNumber(4868)
|
||||
->setStreetName('Payne Rd');
|
||||
->setLocality('Nashville');
|
||||
->setSubLocality('Antioch');
|
||||
->setAdminLevels([
|
||||
new AdminLevel(1, 'Tennessee', 'TN')
|
||||
])
|
||||
->setPostalCode('37013');
|
||||
->setCountry('USA');
|
||||
->setCountryCode('US');
|
||||
$address = $addressBuilder->build();
|
||||
|
||||
$query = GeocodeQuery::create('dummy data');
|
||||
$query = $query->withData(MapQuest::DATA_KEY_ADDRESS, $address);
|
||||
|
||||
$results = $provider->geocodeQuery($query);
|
||||
```
|
||||
|
||||
### Contribute
|
||||
|
||||
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
|
||||
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues).
|
47
old.vendor/geocoder-php/mapquest-provider/composer.json
Normal file
47
old.vendor/geocoder-php/mapquest-provider/composer.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "geocoder-php/mapquest-provider",
|
||||
"type": "library",
|
||||
"description": "Geocoder MapQuest adapter",
|
||||
"keywords": [],
|
||||
"homepage": "http://geocoder-php.org/Geocoder/",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "William Durand",
|
||||
"email": "william.durand1@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0",
|
||||
"geocoder-php/common-http": "^4.0",
|
||||
"willdurand/geocoder": "^4.0"
|
||||
},
|
||||
"provide": {
|
||||
"geocoder-php/provider-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"geocoder-php/provider-integration-tests": "^1.1",
|
||||
"php-http/curl-client": "^2.2",
|
||||
"php-http/message": "^1.0",
|
||||
"phpunit/phpunit": "^9.5"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Geocoder\\Provider\\MapQuest\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit",
|
||||
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user