From 853f1f43c40b5934cf48c5d0ae1dc879179fbe57 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 9 Feb 2018 06:37:53 -0800 Subject: [PATCH 01/70] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6722c26..4d0299c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.0.6] - 9 Feb 2018 +### Added +- Laravel 5.6 compatibility. + ## [4.0.5] - 14 Jan 2018 ### Fixed - loading of GeoIP2 provider from within Chain provider. From 0125ed048e6b370bf9122d6e971dad42a2cc5779 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 9 Feb 2018 07:07:24 -0800 Subject: [PATCH 02/70] Update minimum PHP version --- README.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71cce92..601875c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This package allows you to use [**Geocoder**](http://geocoder-php.org/Geocoder/) in [**Laravel 5**](http://laravel.com/). ## Requirements -- PHP >= 7.0.0 +- PHP >= 7.0.25 - Laravel >= 5.0 ## Installation diff --git a/composer.json b/composer.json index 8b6db23..f4a6dc4 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "illuminate/cache": "5.0 - 5.6", "illuminate/support": "5.0 - 5.6", "php-http/curl-client": "^1.7", - "php": "^7.0", + "php": ">=7.0.25", "willdurand/geocoder": "^4.0" }, "require-dev": { From ff1ef2b1f4baec4cb69d5e6001a3ddf6185524ce Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 9 Feb 2018 07:13:32 -0800 Subject: [PATCH 03/70] Update min PHP version for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 90c60f2..2b736b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: - - 7.0 + - 7.0.25 - 7.1 - 7.2 From 841fd42e7b25c6e1128ecb3b9886367b32fb3f9f Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 9 Feb 2018 07:22:05 -0800 Subject: [PATCH 04/70] update min php version --- .travis.yml | 3 +-- README.md | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b736b6..a2e8692 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: php php: - - 7.0.25 - - 7.1 + - 7.1.3 - 7.2 before_script: diff --git a/README.md b/README.md index 601875c..9aa0bba 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This package allows you to use [**Geocoder**](http://geocoder-php.org/Geocoder/) in [**Laravel 5**](http://laravel.com/). ## Requirements -- PHP >= 7.0.25 +- PHP >= 7.1.3 - Laravel >= 5.0 ## Installation diff --git a/composer.json b/composer.json index f4a6dc4..95280a7 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "illuminate/cache": "5.0 - 5.6", "illuminate/support": "5.0 - 5.6", "php-http/curl-client": "^1.7", - "php": ">=7.0.25", + "php": ">=7.1.3", "willdurand/geocoder": "^4.0" }, "require-dev": { From 848733009cd01bd568758bd56d0e78d13ee4d557 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 9 Feb 2018 19:40:53 -0800 Subject: [PATCH 05/70] Fixes #121 --- tests/Feature/Providers/GeocoderServiceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index 93ef198..5ab454f 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -4,7 +4,7 @@ use Geocoder\Laravel\Exceptions\InvalidDumperException; use Geocoder\Laravel\Facades\Geocoder; use Geocoder\Laravel\ProviderAndDumperAggregator; -use Geocoder\Laravel\Tests\FeatureTestCase; +use Geocoder\Laravel\Tests\UnitTestCase; use Geocoder\Laravel\Providers\GeocoderService; use Geocoder\Model\Coordinates; use Geocoder\Provider\Chain\Chain; @@ -22,7 +22,7 @@ * @SuppressWarnings(PHPMD.TooManyMethods) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class GeocoderServiceTest extends FeatureTestCase +class GeocoderServiceTest extends UnitTestCase { public function testItReverseGeocodesCoordinates() { From 1ea4e291eab2193f2e5bf4f89bf11b5aa5faf2a1 Mon Sep 17 00:00:00 2001 From: Markus Schlotbohm Date: Sat, 17 Mar 2018 15:28:44 +0100 Subject: [PATCH 06/70] Added the ability to specify a cache store to use --- config/geocoder.php | 41 +++++++++++++++---- src/ProviderAndDumperAggregator.php | 18 ++++---- .../Feature/Providers/GeocoderServiceTest.php | 7 ++-- tests/config/testConfig.php | 5 ++- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/config/geocoder.php b/config/geocoder.php index 96e3c5c..0784071 100644 --- a/config/geocoder.php +++ b/config/geocoder.php @@ -9,17 +9,44 @@ /* |-------------------------------------------------------------------------- - | Cache Duration + | Cache Settings |-------------------------------------------------------------------------- | - | Specify the cache duration in minutes. The default approximates a forever - | cache, but there are certain issues with Laravel's forever caching - | methods that prevent us from using them in this project. - | - | Default: 9999999 (integer) + | Here you may define all of the cache settings. | */ - 'cache-duration' => 9999999, + + 'cache' => [ + + /* + |-------------------------------------------------------------------------- + | Cache Store + |-------------------------------------------------------------------------- + | + | Specify the cache store to use for caching. The default value null will + | use the default cache store specified in the cache.php cofig file. + | + | Default: null + | + */ + + 'store' => null, + + /* + |-------------------------------------------------------------------------- + | Cache Duration + |-------------------------------------------------------------------------- + | + | Specify the cache duration in minutes. The default approximates a forever + | cache, but there are certain issues with Laravel's forever caching + | methods that prevent us from using them in this project. + | + | Default: 9999999 (integer) + | + */ + + 'duration' => 9999999, + ], /* |-------------------------------------------------------------------------- diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 5b25b64..1634299 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -80,9 +80,9 @@ public function dump(string $dumper) : Collection public function geocodeQuery(GeocodeQuery $query) : self { $cacheKey = serialize($query); - $this->results = app('cache')->remember( + $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", - config('geocoder.cache-duration', 0), + config('geocoder.cache.duration', 0), function () use ($query) { return collect($this->aggregator->geocodeQuery($query)); } @@ -96,9 +96,9 @@ function () use ($query) { public function reverseQuery(ReverseQuery $query) : self { $cacheKey = serialize($query); - $this->results = app('cache')->remember( + $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", - config('geocoder.cache-duration', 0), + config('geocoder.cache.duration', 0), function () use ($query) { return collect($this->aggregator->reverseQuery($query)); } @@ -117,9 +117,9 @@ public function getName() : string public function geocode(string $value) : self { $cacheKey = str_slug(strtolower(urlencode($value))); - $this->results = app('cache')->remember( + $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", - config('geocoder.cache-duration', 0), + config('geocoder.cache.duration', 0), function () use ($value) { return collect($this->aggregator->geocode($value)); } @@ -133,9 +133,9 @@ function () use ($value) { public function reverse(float $latitude, float $longitude) : self { $cacheKey = str_slug(strtolower(urlencode("{$latitude}-{$longitude}"))); - $this->results = app('cache')->remember( + $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", - config('geocoder.cache-duration', 0), + config('geocoder.cache.duration', 0), function () use ($latitude, $longitude) { return collect($this->aggregator->reverse($latitude, $longitude)); } @@ -264,7 +264,7 @@ protected function getAdapterClass(string $provider) : string protected function removeEmptyCacheEntry(string $cacheKey) { - $result = app('cache')->get($cacheKey); + $result = app('cache')->store(config('geocoder.cache.store', null))->get($cacheKey); if ($result && $result->isEmpty()) { app('cache')->forget($cacheKey); diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index 5ab454f..698d1db 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -141,7 +141,8 @@ public function testItThrowsAnExceptionForInvalidDumper() public function testConfig() { - $this->assertEquals(999999999, config('geocoder.cache-duration')); + $this->assertEquals(null, config('geocoder.cache.store')); + $this->assertEquals(999999999, config('geocoder.cache.duration')); $this->assertTrue(is_array($providers = $this->app['config']->get('geocoder.providers'))); $this->assertCount(3, $providers); $this->assertArrayHasKey(GoogleMaps::class, $providers[Chain::class]); @@ -169,8 +170,8 @@ public function testCacheIsUsed() $result = app('geocoder')->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA') ->get(); - $this->assertTrue(app('cache')->has("geocoder-{$cacheKey}")); - $this->assertEquals($result, app('cache')->get("geocoder-{$cacheKey}")); + $this->assertTrue(app('cache')->store(config('geocoder.cache.store', null))->has("geocoder-{$cacheKey}")); + $this->assertEquals($result, app('cache')->store(config('geocoder.cache.store', null))->get("geocoder-{$cacheKey}")); } /** diff --git a/tests/config/testConfig.php b/tests/config/testConfig.php index 0f4d377..2c64bd6 100644 --- a/tests/config/testConfig.php +++ b/tests/config/testConfig.php @@ -16,7 +16,10 @@ use Http\Client\Curl\Client; return [ - 'cache-duration' => 999999999, + 'cache' => [ + 'store' => null, + 'duration' => 999999999, + ], 'providers' => [ Chain::class => [ GeoIP2::class => [], From 0c513fe701531a60690174cc87959d5d08ce2a25 Mon Sep 17 00:00:00 2001 From: Markus Schlotbohm Date: Sat, 17 Mar 2018 18:53:49 +0100 Subject: [PATCH 07/70] Added md5 encrytion to the cache key --- src/ProviderAndDumperAggregator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 1634299..c5d01f9 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -79,7 +79,7 @@ public function dump(string $dumper) : Collection public function geocodeQuery(GeocodeQuery $query) : self { - $cacheKey = serialize($query); + $cacheKey = md5(serialize($query)); $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", config('geocoder.cache.duration', 0), @@ -95,7 +95,7 @@ function () use ($query) { public function reverseQuery(ReverseQuery $query) : self { - $cacheKey = serialize($query); + $cacheKey = md5(serialize($query)); $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", config('geocoder.cache.duration', 0), @@ -116,7 +116,7 @@ public function getName() : string public function geocode(string $value) : self { - $cacheKey = str_slug(strtolower(urlencode($value))); + $cacheKey = md5(str_slug(strtolower(urlencode($value)))); $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", config('geocoder.cache.duration', 0), @@ -132,7 +132,7 @@ function () use ($value) { public function reverse(float $latitude, float $longitude) : self { - $cacheKey = str_slug(strtolower(urlencode("{$latitude}-{$longitude}"))); + $cacheKey = md5(str_slug(strtolower(urlencode("{$latitude}-{$longitude}")))); $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( "geocoder-{$cacheKey}", config('geocoder.cache.duration', 0), From 3cc763a34029fe3f6bb793071cadafbe2b25cbe1 Mon Sep 17 00:00:00 2001 From: Markus Schlotbohm Date: Sun, 18 Mar 2018 14:36:44 +0100 Subject: [PATCH 08/70] Fixed geocoder service tests to use md5 cache keys --- tests/Feature/Providers/GeocoderServiceTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index 698d1db..ad8318d 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -165,7 +165,7 @@ public function testGeocoder() public function testCacheIsUsed() { - $cacheKey = str_slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA'))); + $cacheKey = md5(str_slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')))); $result = app('geocoder')->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA') ->get(); @@ -265,14 +265,14 @@ public function testGetProvider() public function testJapaneseCharacterGeocoding() { - $cacheKey = str_slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3'))); + $cacheKey = md5(str_slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')))); app('geocoder')->geocode('108-0075 東京都港区港南2丁目16-3') ->get(); $this->assertEquals( $cacheKey, - '108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93' + md5('108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93') ); $this->assertTrue(app('cache')->has("geocoder-{$cacheKey}")); } @@ -304,7 +304,7 @@ public function testItHandlesOnlyCityAndState() public function testEmptyResultsAreNotCached() { - $cacheKey = str_slug(strtolower(urlencode('_'))); + $cacheKey = md5(str_slug(strtolower(urlencode('_')))); Geocoder::geocode('_')->get(); From 96d7821d587ea1343caa6327b9d9c60316c37f41 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 25 Mar 2018 16:08:44 -0700 Subject: [PATCH 09/70] Add configurable cache store --- CHANGELOG.md | 6 + README.md | 39 ++++ composer.json | 6 +- config/geocoder.php | 40 ++-- src/ProviderAndDumperAggregator.php | 203 +++++++++--------- tests/CreatesApplication.php | 14 ++ .../Feature/Providers/GeocoderServiceTest.php | 30 ++- 7 files changed, 205 insertions(+), 133 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d0299c..78c1b7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.0.7] - 25 Mar 2018 +### Added +- optional dedicated cache store. +- hashed cache keys and hash collision prevention. +- custom cache store configuration instructions. + ## [4.0.6] - 9 Feb 2018 ### Added - Laravel 5.6 compatibility. diff --git a/README.md b/README.md index 9aa0bba..f4e1de4 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,45 @@ Further, a special note on the GoogleMaps provider: if you are using an API key, See the [Geocoder documentation](http://geocoder-php.org/Geocoder/) for a list of available adapters and providers. +### Dedicated Cache Store *Recommended* +To implement the dedicated cache store, add another redis store entry in +`config/database.php`, something like the following: +```php + "redis" => [ + // ... + + "geocode-cache" => [ // choose an appropriate name + 'host' => env('REDIS_HOST', '192.168.10.10'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 1, // be sure this number differs from your other redis databases + ], + ] +``` + +You will also need to add an entry in `config/cache.php` to point to this redis +database: +```php + "stores" => [ + // ... + + "geocode" => [ + 'driver' => 'redis', + 'connection' => 'geocode-cache', + ], + ], +``` + +Finally, configure Geocoder for Laraver to use this store. Edit +`config/geocoder.php`: +```php + "cache" => [ + "store" => "geocode", + + // ... + ], +``` + ### Providers If you are upgrading and have previously published the geocoder config file, you need to add the `cache-duration` variable, otherwise cache will be disabled diff --git a/composer.json b/composer.json index 95280a7..390f4cc 100644 --- a/composer.json +++ b/composer.json @@ -41,9 +41,9 @@ "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", "mockery/mockery": "0.9.*", - "orchestra/database": "3.6.x-dev@dev", - "orchestra/testbench": "^3.6.0", - "orchestra/testbench-browser-kit": "3.6.x-dev@dev", + "orchestra/database": "3.6.*", + "orchestra/testbench": "3.6.*", + "orchestra/testbench-browser-kit": "3.6.*", "orchestra/testbench-dusk": "3.6.x-dev@dev", "php-coveralls/php-coveralls": "*", "phpunit/phpunit": "^7.0", diff --git a/config/geocoder.php b/config/geocoder.php index 0784071..d04b40d 100644 --- a/config/geocoder.php +++ b/config/geocoder.php @@ -6,25 +6,15 @@ use Http\Client\Curl\Client; return [ - - /* - |-------------------------------------------------------------------------- - | Cache Settings - |-------------------------------------------------------------------------- - | - | Here you may define all of the cache settings. - | - */ - 'cache' => [ /* - |-------------------------------------------------------------------------- + |----------------------------------------------------------------------- | Cache Store - |-------------------------------------------------------------------------- + |----------------------------------------------------------------------- | - | Specify the cache store to use for caching. The default value null will - | use the default cache store specified in the cache.php cofig file. + | Specify the cache store to use for caching. The value "null" will use + | the default cache store specified in /config/cache.php file. | | Default: null | @@ -33,13 +23,13 @@ 'store' => null, /* - |-------------------------------------------------------------------------- + |----------------------------------------------------------------------- | Cache Duration - |-------------------------------------------------------------------------- + |----------------------------------------------------------------------- | - | Specify the cache duration in minutes. The default approximates a forever - | cache, but there are certain issues with Laravel's forever caching - | methods that prevent us from using them in this project. + | Specify the cache duration in minutes. The default approximates a + | "forever" cache, but there are certain issues with Laravel's forever + | caching methods that prevent us from using them in this project. | | Default: 9999999 (integer) | @@ -49,9 +39,9 @@ ], /* - |-------------------------------------------------------------------------- + |--------------------------------------------------------------------------- | Providers - |-------------------------------------------------------------------------- + |--------------------------------------------------------------------------- | | Here you may specify any number of providers that should be used to | perform geocaching operations. The `chain` provider is special, @@ -76,9 +66,9 @@ ], /* - |-------------------------------------------------------------------------- + |--------------------------------------------------------------------------- | Adapter - |-------------------------------------------------------------------------- + |--------------------------------------------------------------------------- | | You can specify which PSR-7-compliant HTTP adapter you would like to use. | There are multiple options at your disposal: CURL, Guzzle, and others. @@ -92,9 +82,9 @@ 'adapter' => Client::class, /* - |-------------------------------------------------------------------------- + |--------------------------------------------------------------------------- | Reader - |-------------------------------------------------------------------------- + |--------------------------------------------------------------------------- | | You can specify a reader for specific providers, like GeoIp2, which | connect to a local file-database. The reader should be set to an diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index c5d01f9..a5a86af 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -15,10 +15,11 @@ use Geocoder\Dumper\Wkb; use Geocoder\Dumper\Wkt; use Geocoder\Geocoder; -use Geocoder\Query\GeocodeQuery; -use Geocoder\Query\ReverseQuery; use Geocoder\Laravel\Exceptions\InvalidDumperException; use Geocoder\ProviderAggregator; +use Geocoder\Query\GeocodeQuery; +use Geocoder\Query\Query; +use Geocoder\Query\ReverseQuery; use Illuminate\Support\Collection; use ReflectionClass; @@ -77,73 +78,30 @@ public function dump(string $dumper) : Collection }); } - public function geocodeQuery(GeocodeQuery $query) : self + public function geocode(string $value) : self { - $cacheKey = md5(serialize($query)); - $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( - "geocoder-{$cacheKey}", - config('geocoder.cache.duration', 0), - function () use ($query) { - return collect($this->aggregator->geocodeQuery($query)); - } - ); - - $this->removeEmptyCacheEntry("geocoder-{$cacheKey}"); + $cacheKey = str_slug(strtolower(urlencode($value))); + $this->results = $this->cacheRequest($cacheKey, [$value], "geocode"); return $this; } - public function reverseQuery(ReverseQuery $query) : self + public function geocodeQuery(GeocodeQuery $query) : self { - $cacheKey = md5(serialize($query)); - $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( - "geocoder-{$cacheKey}", - config('geocoder.cache.duration', 0), - function () use ($query) { - return collect($this->aggregator->reverseQuery($query)); - } - ); - - $this->removeEmptyCacheEntry("geocoder-{$cacheKey}"); + $cacheKey = serialize($query); + $this->results = $this->cacheRequest($cacheKey, [$query], "geocodeQuery"); return $this; } - public function getName() : string - { - return $this->aggregator->getName(); - } - - public function geocode(string $value) : self + public function getLimit() : int { - $cacheKey = md5(str_slug(strtolower(urlencode($value)))); - $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( - "geocoder-{$cacheKey}", - config('geocoder.cache.duration', 0), - function () use ($value) { - return collect($this->aggregator->geocode($value)); - } - ); - - $this->removeEmptyCacheEntry("geocoder-{$cacheKey}"); - - return $this; + return $this->limit; } - public function reverse(float $latitude, float $longitude) : self + public function getName() : string { - $cacheKey = md5(str_slug(strtolower(urlencode("{$latitude}-{$longitude}")))); - $this->results = app('cache')->store(config('geocoder.cache.store', null))->remember( - "geocoder-{$cacheKey}", - config('geocoder.cache.duration', 0), - function () use ($latitude, $longitude) { - return collect($this->aggregator->reverse($latitude, $longitude)); - } - ); - - $this->removeEmptyCacheEntry("geocoder-{$cacheKey}"); - - return $this; + return $this->aggregator->getName(); } public function limit(int $limit) : self @@ -155,9 +113,17 @@ public function limit(int $limit) : self return $this; } - public function getLimit() : int + /** + * @deprecated Use `getProviders()` instead. + */ + public function getProvider() { - return $this->limit; + return $this->getProviders()->first(); + } + + public function getProviders() : Collection + { + return collect($this->aggregator->getProviders()); } public function registerProvider($provider) : self @@ -174,47 +140,74 @@ public function registerProviders(array $providers = []) : self return $this; } - public function using(string $name) : self + public function registerProvidersFromConfig(Collection $providers) : self { - $this->aggregator = $this->aggregator->using($name); + $this->registerProviders($this->getProvidersFromConfiguration($providers)); return $this; } - public function getProviders() : Collection + public function reverse(float $latitude, float $longitude) : self { - return collect($this->aggregator->getProviders()); + $cacheKey = str_slug(strtolower(urlencode("{$latitude}-{$longitude}"))); + $this->results = $this->cacheRequest($cacheKey, [$latitude, $longitude], "reverse"); + + return $this; } - /** - * @deprecated Use `getProviders()` instead. - */ - public function getProvider() + public function reverseQuery(ReverseQuery $query) : self { - return $this->getProviders()->first(); + $cacheKey = serialize($query); + $this->results = $this->cacheRequest($cacheKey, [$query], "reverseQuery"); + + return $this; } - public function registerProvidersFromConfig(Collection $providers) : self + public function using(string $name) : self { - $this->registerProviders($this->getProvidersFromConfiguration($providers)); + $this->aggregator = $this->aggregator->using($name); return $this; } - protected function getProvidersFromConfiguration(Collection $providers) : array + protected function cacheRequest(string $cacheKey, array $queryElements, string $queryType) { - $providers = $providers->map(function ($arguments, $provider) { - $arguments = $this->getArguments($arguments, $provider); - $reflection = new ReflectionClass($provider); + $hashedCacheKey = sha1($cacheKey); + $duration = config("geocoder.cache.duration", 0); + $store = config('geocoder.cache.store'); + + $result = app("cache") + ->store($store) + ->remember($hashedCacheKey, $duration, function () use ($cacheKey, $queryElements, $queryType) { + return [ + "key" => $cacheKey, + "value" => collect($this->aggregator->{$queryType}(...$queryElements)), + ]; + }); + $result = $this->preventCacheKeyHashCollision( + $result, + $hashedCacheKey, + $cacheKey, + $queryElements, + $queryType + ); + $this->removeEmptyCacheEntry($result, $hashedCacheKey); - if ($provider === 'Geocoder\Provider\Chain\Chain') { - return $reflection->newInstance($arguments); - } + return $result; + } - return $reflection->newInstanceArgs($arguments); - }); + protected function getAdapterClass(string $provider) : string + { + $specificAdapters = collect([ + 'Geocoder\Provider\GeoIP2\GeoIP2' => 'Geocoder\Provider\GeoIP2\GeoIP2Adapter', + 'Geocoder\Provider\MaxMindBinary\MaxMindBinary' => '', + ]); - return $providers->toArray(); + if ($specificAdapters->has($provider)) { + return $specificAdapters->get($provider); + } + + return config('geocoder.adapter'); } protected function getArguments(array $arguments, string $provider) : array @@ -239,35 +232,53 @@ protected function getArguments(array $arguments, string $provider) : array return $arguments; } - protected function requiresReader(string $class) : bool + protected function getProvidersFromConfiguration(Collection $providers) : array { - $specificAdapters = collect([ - 'Geocoder\Provider\GeoIP2\GeoIP2', - ]); + $providers = $providers->map(function ($arguments, $provider) { + $arguments = $this->getArguments($arguments, $provider); + $reflection = new ReflectionClass($provider); - return $specificAdapters->contains($class); - } + if ($provider === 'Geocoder\Provider\Chain\Chain') { + return $reflection->newInstance($arguments); + } - protected function getAdapterClass(string $provider) : string - { - $specificAdapters = collect([ - 'Geocoder\Provider\GeoIP2\GeoIP2' => 'Geocoder\Provider\GeoIP2\GeoIP2Adapter', - 'Geocoder\Provider\MaxMindBinary\MaxMindBinary' => '', - ]); + return $reflection->newInstanceArgs($arguments); + }); - if ($specificAdapters->has($provider)) { - return $specificAdapters->get($provider); + return $providers->toArray(); + } + + protected function preventCacheKeyHashCollision( + array $result, + string $hashedCacheKey, + string $cacheKey, + array $queryElements, + string $queryType + ) { + if ($result["key"] === $cacheKey) { + return $result["value"]; } - return config('geocoder.adapter'); + app("cache") + ->store(config('geocoder.cache.store')) + ->forget($hashedCacheKey); + + return $this->cacheRequest($cacheKey, $queryElements, $queryType); } - protected function removeEmptyCacheEntry(string $cacheKey) + protected function removeEmptyCacheEntry(Collection $result, string $cacheKey) { - $result = app('cache')->store(config('geocoder.cache.store', null))->get($cacheKey); - if ($result && $result->isEmpty()) { app('cache')->forget($cacheKey); } } + + protected function requiresReader(string $class) : bool + { + $specificAdapters = collect([ + 'Geocoder\Provider\GeoIP2\GeoIP2', + ]); + + return $specificAdapters->contains($class); + } } diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 7c417c8..d861487 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -28,5 +28,19 @@ protected function getEnvironmentSetUp($app) { $config = require(__DIR__ . '/config/testConfig.php'); $app['config']->set('geocoder', $config); + $app['config']->set('database.redis.default', [ + 'host' => env('REDIS_HOST', '192.168.10.10'), + ]); + $app['config']->set('database.redis.geocode-cache', [ + 'host' => env('REDIS_HOST', '192.168.10.10'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 1, + ]); + $app['config']->set('cache.stores.geocode', [ + 'driver' => 'redis', + 'connection' => 'geocode-cache', + ]); + $app['config']->set('geocoder.store', 'geocode'); } } diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index ad8318d..a6ebe4f 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -165,13 +165,20 @@ public function testGeocoder() public function testCacheIsUsed() { - $cacheKey = md5(str_slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')))); + $cacheKey = sha1(str_slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')))); - $result = app('geocoder')->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA') + $result = app('geocoder') + ->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA') ->get(); - - $this->assertTrue(app('cache')->store(config('geocoder.cache.store', null))->has("geocoder-{$cacheKey}")); - $this->assertEquals($result, app('cache')->store(config('geocoder.cache.store', null))->get("geocoder-{$cacheKey}")); + $cachedResult = app('cache') + ->store(config('geocoder.cache.store')) + ->get($cacheKey)["value"]; + $isCached = app('cache') + ->store(config('geocoder.cache.store')) + ->has($cacheKey); + + $this->assertTrue($isCached); + $this->assertEquals($result, $cachedResult); } /** @@ -214,6 +221,10 @@ public function testItCanUseMaxMindBinaryWithoutProvider() { $provider = new MaxMindBinary(__DIR__ . '/../../resources/assets/GeoIP.dat'); app('geocoder')->registerProvider($provider); + + // dummy assertion, as we are running this test to make sure no + // exception is thrown in the above provider registration + $this->assertTrue(true); } public function testGetNameReturnsString() @@ -265,16 +276,17 @@ public function testGetProvider() public function testJapaneseCharacterGeocoding() { - $cacheKey = md5(str_slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')))); + $cacheKey = sha1(str_slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')))); - app('geocoder')->geocode('108-0075 東京都港区港南2丁目16-3') + app('geocoder') + ->geocode('108-0075 東京都港区港南2丁目16-3') ->get(); $this->assertEquals( $cacheKey, - md5('108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93') + sha1('108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93') ); - $this->assertTrue(app('cache')->has("geocoder-{$cacheKey}")); + $this->assertTrue(app('cache')->has($cacheKey)); } public function testItProvidesState() From 9b899cf4b9bb9e2873dfb65441dec8edfd0e9f3f Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 25 Mar 2018 16:24:38 -0700 Subject: [PATCH 10/70] Add work-around for Lumen Fixes #124 --- CHANGELOG.md | 4 ++++ src/Providers/GeocoderService.php | 32 ++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78c1b7a..9db0a13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.0.8] - 25 Mar 2018 +### Added +- work-around for missing `config_path()` function in Lumen. + ## [4.0.7] - 25 Mar 2018 ### Added - optional dedicated cache store. diff --git a/src/Providers/GeocoderService.php b/src/Providers/GeocoderService.php index 97d4aa2..39938a4 100644 --- a/src/Providers/GeocoderService.php +++ b/src/Providers/GeocoderService.php @@ -21,22 +21,40 @@ class GeocoderService extends ServiceProvider public function boot() { - $configPath = __DIR__ . '/../../config/geocoder.php'; - $this->publishes([$configPath => config_path('geocoder.php')], 'config'); - $this->mergeConfigFrom($configPath, 'geocoder'); - $this->app->singleton('geocoder', function () { + $configPath = __DIR__ . "/../../config/geocoder.php"; + $this->publishes( + [$configPath => $this->configPath("geocoder.php")], + "config" + ); + $this->mergeConfigFrom($configPath, "geocoder"); + $this->app->singleton("geocoder", function () { return (new ProviderAndDumperAggregator) - ->registerProvidersFromConfig(collect(config('geocoder.providers'))); + ->registerProvidersFromConfig(collect(config("geocoder.providers"))); }); } public function register() { - $this->app->alias('Geocoder', Geocoder::class); + $this->app->alias("Geocoder", Geocoder::class); } public function provides() : array { - return ['geocoder']; + return ["geocoder"]; + } + + protected function configPath(string $path = "") : string + { + if (function_exists("config_path")) { + return config_path($path); + } + + $pathParts = [ + app()->basePath(), + "config", + trim($path, "/"), + ]; + + return implode("/", $pathParts); } } From 530a1854c0b6b8f8e5f5249ced95cdc0e9d29b7b Mon Sep 17 00:00:00 2001 From: Anam Hossain Date: Wed, 28 Mar 2018 11:43:42 +1100 Subject: [PATCH 11/70] Resolve depency via Class name --- src/Providers/GeocoderService.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Providers/GeocoderService.php b/src/Providers/GeocoderService.php index 39938a4..e06055f 100644 --- a/src/Providers/GeocoderService.php +++ b/src/Providers/GeocoderService.php @@ -11,9 +11,7 @@ use Geocoder\Laravel\Facades\Geocoder; use Geocoder\Laravel\ProviderAndDumperAggregator; -use Illuminate\Support\Collection; use Illuminate\Support\ServiceProvider; -use ReflectionClass; class GeocoderService extends ServiceProvider { @@ -27,10 +25,17 @@ public function boot() "config" ); $this->mergeConfigFrom($configPath, "geocoder"); - $this->app->singleton("geocoder", function () { - return (new ProviderAndDumperAggregator) - ->registerProvidersFromConfig(collect(config("geocoder.providers"))); + + $providerAndDumperAggregator = (new ProviderAndDumperAggregator) + ->registerProvidersFromConfig(collect(config("geocoder.providers"))); + + $this->app->singleton("geocoder", function ($app) use ($providerAndDumperAggregator) { + return $providerAndDumperAggregator; }); + + // Resolve dependency via class name + // i.e app(ProviderAndDumperAggregator::class) or _construct(ProviderAndDumperAggregator $geocoder) + $this->app->instance(ProviderAndDumperAggregator::class, $providerAndDumperAggregator); } public function register() @@ -38,12 +43,12 @@ public function register() $this->app->alias("Geocoder", Geocoder::class); } - public function provides() : array + public function provides(): array { return ["geocoder"]; } - protected function configPath(string $path = "") : string + protected function configPath(string $path = ""): string { if (function_exists("config_path")) { return config_path($path); From acaccc0825c20a0b1585635748c58383f8c97952 Mon Sep 17 00:00:00 2001 From: Anam Hossain Date: Wed, 28 Mar 2018 11:51:51 +1100 Subject: [PATCH 12/70] Add controller example --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index f4e1de4..02a4267 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,19 @@ app('geocoder')->reverse(43.882587,-103.454067)->get(); app('geocoder')->geocode('Los Angeles, CA')->dump('kml'); ``` +#### Using Controller +```php +use Geocoder\Laravel\ProviderAndDumperAggregator as Geocoder; + +class GeocoderController extends Controller +{ + public function getGeocode(Geocoder $geocoder) + { + $geocoder->geocode('Los Angeles, CA')->get() + } +} +``` + ## Upgrading Anytime you upgrade this package, please remember to clear your cache, to prevent incompatible cached responses when breaking changes are introduced (this should hopefully only be necessary in major versions): ```sh From 1cd86570d38cfd1212f2efc0abfbff3c20843d65 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Mon, 28 May 2018 08:44:56 -0700 Subject: [PATCH 13/70] Format PR changes --- README.md | 2 +- src/Providers/GeocoderService.php | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 02a4267..f4bed33 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ app('geocoder')->reverse(43.882587,-103.454067)->get(); app('geocoder')->geocode('Los Angeles, CA')->dump('kml'); ``` -#### Using Controller +#### Dependency Injection ```php use Geocoder\Laravel\ProviderAndDumperAggregator as Geocoder; diff --git a/src/Providers/GeocoderService.php b/src/Providers/GeocoderService.php index e06055f..e9f2d7e 100644 --- a/src/Providers/GeocoderService.php +++ b/src/Providers/GeocoderService.php @@ -25,17 +25,14 @@ public function boot() "config" ); $this->mergeConfigFrom($configPath, "geocoder"); - - $providerAndDumperAggregator = (new ProviderAndDumperAggregator) + $geocoder = (new ProviderAndDumperAggregator) ->registerProvidersFromConfig(collect(config("geocoder.providers"))); - - $this->app->singleton("geocoder", function ($app) use ($providerAndDumperAggregator) { - return $providerAndDumperAggregator; - }); - - // Resolve dependency via class name - // i.e app(ProviderAndDumperAggregator::class) or _construct(ProviderAndDumperAggregator $geocoder) - $this->app->instance(ProviderAndDumperAggregator::class, $providerAndDumperAggregator); + $this->app + ->singleton("geocoder", function () use ($geocoder) { + return $geocoder; + }); + $this->app + ->instance(ProviderAndDumperAggregator::class, $geocoder); } public function register() @@ -43,12 +40,12 @@ public function register() $this->app->alias("Geocoder", Geocoder::class); } - public function provides(): array + public function provides() : array { - return ["geocoder"]; + return ["geocoder", ProviderAndDumperAggregator::class]; } - protected function configPath(string $path = ""): string + protected function configPath(string $path = "") : string { if (function_exists("config_path")) { return config_path($path); From fd0c837441cc8c7d8aa3ee6b8bea4103881bd868 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Mon, 28 May 2018 08:46:10 -0700 Subject: [PATCH 14/70] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db0a13..1899010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.0.9] - 28 May 2018 +### Added +- class-name resolution from Service container, allowing for dependency + injection. + ## [4.0.8] - 25 Mar 2018 ### Added - work-around for missing `config_path()` function in Lumen. From 6637132a11e81a42529a72a4872aa9e3920d20e4 Mon Sep 17 00:00:00 2001 From: Hugo Vacher Date: Fri, 22 Jun 2018 13:57:21 -0400 Subject: [PATCH 15/70] Prevent GeocoderService from instantiating providers on boot This could cause performance issues as is instantiates the each provider that was setup in the configuration as the time of boot, event if they don't get use. --- src/Providers/GeocoderService.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Providers/GeocoderService.php b/src/Providers/GeocoderService.php index e9f2d7e..f815b9d 100644 --- a/src/Providers/GeocoderService.php +++ b/src/Providers/GeocoderService.php @@ -25,19 +25,16 @@ public function boot() "config" ); $this->mergeConfigFrom($configPath, "geocoder"); - $geocoder = (new ProviderAndDumperAggregator) - ->registerProvidersFromConfig(collect(config("geocoder.providers"))); - $this->app - ->singleton("geocoder", function () use ($geocoder) { - return $geocoder; - }); - $this->app - ->instance(ProviderAndDumperAggregator::class, $geocoder); } public function register() { $this->app->alias("Geocoder", Geocoder::class); + $this->app->singleton(ProviderAndDumperAggregator::class, function () { + return (new ProviderAndDumperAggregator) + ->registerProvidersFromConfig(collect(config("geocoder.providers"))); + }); + $this->app->bind('geocoder', ProviderAndDumperAggregator::class); } public function provides() : array From 5a751f8497fe26941d821a3f773d5eb56d76f26e Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 1 Jul 2018 11:07:37 -0700 Subject: [PATCH 16/70] WIP --- src/Providers/GeocoderService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/GeocoderService.php b/src/Providers/GeocoderService.php index e9f2d7e..7eed641 100644 --- a/src/Providers/GeocoderService.php +++ b/src/Providers/GeocoderService.php @@ -18,7 +18,7 @@ class GeocoderService extends ServiceProvider protected $defer = false; public function boot() - { + { $configPath = __DIR__ . "/../../config/geocoder.php"; $this->publishes( [$configPath => $this->configPath("geocoder.php")], From 34259667ee234c62cb17b7541bb8a3ffe776d55e Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 1 Jul 2018 11:09:40 -0700 Subject: [PATCH 17/70] Merge PR --- src/Providers/GeocoderService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/GeocoderService.php b/src/Providers/GeocoderService.php index f8573e9..f815b9d 100644 --- a/src/Providers/GeocoderService.php +++ b/src/Providers/GeocoderService.php @@ -18,7 +18,7 @@ class GeocoderService extends ServiceProvider protected $defer = false; public function boot() - { + { $configPath = __DIR__ . "/../../config/geocoder.php"; $this->publishes( [$configPath => $this->configPath("geocoder.php")], From 374cc05189b3992c3ddd9f042968ad7fac64808a Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 1 Jul 2018 11:15:07 -0700 Subject: [PATCH 18/70] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1899010..afba72d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.0.10] - 1 Jul 2018 +### Changed +- service provider to register singleton and alias in `register()` method. + ## [4.0.9] - 28 May 2018 ### Added - class-name resolution from Service container, allowing for dependency From 562d206401667a52baea4db9cb1be83626fe7510 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Wed, 5 Sep 2018 17:14:53 -0400 Subject: [PATCH 19/70] Laravel 5.7 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 390f4cc..cfbc35e 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,8 @@ "geocoder-php/geo-plugin-provider": "^4.0", "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", - "illuminate/cache": "5.0 - 5.6", - "illuminate/support": "5.0 - 5.6", + "illuminate/cache": "5.0 - 5.7", + "illuminate/support": "5.0 - 5.7", "php-http/curl-client": "^1.7", "php": ">=7.1.3", "willdurand/geocoder": "^4.0" From 8a07bcaf84ce2c3e18885b9434a8023782f7cfbf Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 14 Sep 2018 12:07:22 -0700 Subject: [PATCH 20/70] Add Laravel 5.7 compatibility Fixes #136 --- composer.json | 6 +++--- phpunit.xml | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 390f4cc..9ead4ed 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,9 @@ "geocoder-php/geo-plugin-provider": "^4.0", "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", - "illuminate/cache": "5.0 - 5.6", - "illuminate/support": "5.0 - 5.6", - "php-http/curl-client": "^1.7", + "illuminate/cache": "5.0 - 5.7", + "illuminate/support": "5.0 - 5.7", + "php-http/curl-client": "*", "php": ">=7.1.3", "willdurand/geocoder": "^4.0" }, diff --git a/phpunit.xml b/phpunit.xml index f315fa4..c3d8fdd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,7 +10,6 @@ printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" > From 792da3dfc3aafd76969d7d63568fc282b1b90ef1 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 2 Nov 2018 17:58:39 -0700 Subject: [PATCH 21/70] Bring unit tests back to green --- tests/Feature/Providers/GeocoderServiceTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index a6ebe4f..c631dbe 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -81,14 +81,8 @@ public function testItResolvesAGivenAddressWithUmlauts() public function testItResolvesAGivenAddressWithUmlautsInRegion() { - config()->set('geocoder.providers.Geocoder\Provider\Chain\Chain.Geocoder\Provider\GoogleMaps\GoogleMaps', [ - 'de-DE', - null, - ]); - app()->register(GeocoderService::class); - $results = app('geocoder') - ->geocode('Obere Donaustrasse 22, Wien, Österreich') + ->geocode('Obere Donaustraße 22, Wien, Österreich') ->get(); $this->assertEquals('22', $results->first()->getStreetNumber()); From 11408306ec9b148a7f465678488426f13dc26f25 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sat, 3 Nov 2018 12:05:55 -0700 Subject: [PATCH 22/70] Add tojson method Fixes #101 --- CHANGELOG.md | 4 ++++ src/ProviderAndDumperAggregator.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afba72d..276a9b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.0.21] - 3 Nov 2018 +### Added +- `->toJson()` method when querying results. + ## [4.0.10] - 1 Jul 2018 ### Changed - service provider to register singleton and alias in `register()` method. diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index a5a86af..64c4a52 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -51,6 +51,13 @@ public function get() : Collection return $this->results; } + public function toJson() : string + { + return $this + ->dump("geojson") + ->first(); + } + public function dump(string $dumper) : Collection { $dumperClasses = collect([ From de6047c3b3624a197e2599218d8a3b1c8af23d90 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Mon, 4 Mar 2019 09:45:28 -0800 Subject: [PATCH 23/70] Added Laravel 5.8 compatibility --- composer.json | 21 ++++++++++----------- phpunit.xml | 1 - tests/CreatesApplication.php | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 9ead4ed..dde6855 100644 --- a/composer.json +++ b/composer.json @@ -27,26 +27,25 @@ "geocoder-php/geo-plugin-provider": "^4.0", "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", - "illuminate/cache": "5.0 - 5.7", - "illuminate/support": "5.0 - 5.7", + "illuminate/cache": "5.0 - 5.8", + "illuminate/support": "5.0 - 5.8", "php-http/curl-client": "*", "php": ">=7.1.3", "willdurand/geocoder": "^4.0" }, "require-dev": { - "codedungeon/phpunit-result-printer": "*", - "doctrine/dbal": "^2.5", - "fzaninotto/faker": "~1.4", + "doctrine/dbal": "*", + "fzaninotto/faker": "*", "geocoder-php/bing-maps-provider": "^4.0", "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", - "mockery/mockery": "0.9.*", - "orchestra/database": "3.6.*", - "orchestra/testbench": "3.6.*", - "orchestra/testbench-browser-kit": "3.6.*", - "orchestra/testbench-dusk": "3.6.x-dev@dev", + "mockery/mockery": "*", + "orchestra/testbench-browser-kit": "3.8.*", + "orchestra/database": "3.8.x-dev@dev", + "orchestra/testbench-dusk": "3.8.x-dev@dev", + "orchestra/testbench": "3.8.*", "php-coveralls/php-coveralls": "*", - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^7.5", "sebastian/phpcpd": "*" }, "autoload": { diff --git a/phpunit.xml b/phpunit.xml index c3d8fdd..d1b3ef8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,6 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" - printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer" processIsolation="false" stopOnFailure="false" > diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index d861487..7833218 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -5,7 +5,7 @@ trait CreatesApplication { - public function setUp() + public function setUp() : void { parent::setUp(); From 367f2a172cba6065161214ec75b7c18d61160710 Mon Sep 17 00:00:00 2001 From: "Nabil Muh. Firdaus" Date: Mon, 11 Mar 2019 08:45:14 +0700 Subject: [PATCH 24/70] chore: Sort imports and use Str class directly (not via helpers) --- src/ProviderAndDumperAggregator.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 64c4a52..c07322b 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -9,19 +9,20 @@ * @license MIT License */ -use Geocoder\Dumper\GeoJson; +use ReflectionClass; +use Geocoder\Geocoder; use Geocoder\Dumper\Gpx; use Geocoder\Dumper\Kml; use Geocoder\Dumper\Wkb; use Geocoder\Dumper\Wkt; -use Geocoder\Geocoder; -use Geocoder\Laravel\Exceptions\InvalidDumperException; +use Geocoder\Query\Query; +use Illuminate\Support\Str; +use Geocoder\Dumper\GeoJson; use Geocoder\ProviderAggregator; use Geocoder\Query\GeocodeQuery; -use Geocoder\Query\Query; use Geocoder\Query\ReverseQuery; use Illuminate\Support\Collection; -use ReflectionClass; +use Geocoder\Laravel\Exceptions\InvalidDumperException; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) @@ -73,6 +74,7 @@ public function dump(string $dumper) : Collection "The dumper specified ('{$dumper}') is invalid. Valid dumpers ", "are: geojson, gpx, kml, wkb, wkt.", ]); + throw new InvalidDumperException($errorMessage); } @@ -87,7 +89,7 @@ public function dump(string $dumper) : Collection public function geocode(string $value) : self { - $cacheKey = str_slug(strtolower(urlencode($value))); + $cacheKey = Str::slug(strtolower(urlencode($value))); $this->results = $this->cacheRequest($cacheKey, [$value], "geocode"); return $this; @@ -156,7 +158,7 @@ public function registerProvidersFromConfig(Collection $providers) : self public function reverse(float $latitude, float $longitude) : self { - $cacheKey = str_slug(strtolower(urlencode("{$latitude}-{$longitude}"))); + $cacheKey = Str::slug(strtolower(urlencode("{$latitude}-{$longitude}"))); $this->results = $this->cacheRequest($cacheKey, [$latitude, $longitude], "reverse"); return $this; @@ -191,6 +193,7 @@ protected function cacheRequest(string $cacheKey, array $queryElements, string $ "value" => collect($this->aggregator->{$queryType}(...$queryElements)), ]; }); + $result = $this->preventCacheKeyHashCollision( $result, $hashedCacheKey, @@ -198,6 +201,7 @@ protected function cacheRequest(string $cacheKey, array $queryElements, string $ $queryElements, $queryType ); + $this->removeEmptyCacheEntry($result, $hashedCacheKey); return $result; From 147788929ef75d7454598b895f6172f076df9829 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Tue, 12 Mar 2019 16:56:47 -0700 Subject: [PATCH 25/70] Tweaked changes from PR, included HTTP Response Factory Fixes #148 --- composer.json | 1 + phpunit.xml | 2 +- src/ProviderAndDumperAggregator.php | 14 ++++++-------- tests/config/testConfig.php | 1 - 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index dde6855..4b8ad1c 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "geocoder-php/geo-plugin-provider": "^4.0", "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", + "http-interop/http-factory-guzzle": "^1.0", "illuminate/cache": "5.0 - 5.8", "illuminate/support": "5.0 - 5.8", "php-http/curl-client": "*", diff --git a/phpunit.xml b/phpunit.xml index d1b3ef8..fa0e22b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index c07322b..ff1bf87 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -9,20 +9,18 @@ * @license MIT License */ -use ReflectionClass; -use Geocoder\Geocoder; +use Geocoder\Dumper\GeoJson; use Geocoder\Dumper\Gpx; use Geocoder\Dumper\Kml; use Geocoder\Dumper\Wkb; use Geocoder\Dumper\Wkt; -use Geocoder\Query\Query; -use Illuminate\Support\Str; -use Geocoder\Dumper\GeoJson; +use Geocoder\Laravel\Exceptions\InvalidDumperException; use Geocoder\ProviderAggregator; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; use Illuminate\Support\Collection; -use Geocoder\Laravel\Exceptions\InvalidDumperException; +use Illuminate\Support\Str; +use ReflectionClass; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) @@ -89,7 +87,7 @@ public function dump(string $dumper) : Collection public function geocode(string $value) : self { - $cacheKey = Str::slug(strtolower(urlencode($value))); + $cacheKey = (new Str)->slug(strtolower(urlencode($value))); $this->results = $this->cacheRequest($cacheKey, [$value], "geocode"); return $this; @@ -158,7 +156,7 @@ public function registerProvidersFromConfig(Collection $providers) : self public function reverse(float $latitude, float $longitude) : self { - $cacheKey = Str::slug(strtolower(urlencode("{$latitude}-{$longitude}"))); + $cacheKey = (new Str)->slug(strtolower(urlencode("{$latitude}-{$longitude}"))); $this->results = $this->cacheRequest($cacheKey, [$latitude, $longitude], "reverse"); return $this; diff --git a/tests/config/testConfig.php b/tests/config/testConfig.php index 2c64bd6..1b752de 100644 --- a/tests/config/testConfig.php +++ b/tests/config/testConfig.php @@ -11,7 +11,6 @@ use Geocoder\Provider\GeoIP2\GeoIP2; use Geocoder\Provider\GeoPlugin\GeoPlugin; use Geocoder\Provider\GoogleMaps\GoogleMaps; -use Geocoder\Provider\HostIp\HostIp; use GeoIp2\Database\Reader; use Http\Client\Curl\Client; From 65a9373d4e6a0936848781a03182a73dec1e5bda Mon Sep 17 00:00:00 2001 From: Can Vural Date: Thu, 23 May 2019 14:04:16 +0200 Subject: [PATCH 26/70] Don't pass null to adapter Hello, I had this issue with Guzzle. Guzzle expects an array to its constructor, but here we were passing null. This PR fixes that issue. --- src/ProviderAndDumperAggregator.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index a5a86af..b2d8e99 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -219,14 +219,13 @@ protected function getArguments(array $arguments, string $provider) : array } $adapter = $this->getAdapterClass($provider); - $reader = null; if ($adapter) { if ($this->requiresReader($provider)) { - $reader = config('geocoder.reader'); + array_unshift($arguments, new $adapter(config('geocoder.reader'))); + } else { + array_unshift($arguments, new $adapter()); } - - array_unshift($arguments, new $adapter($reader)); } return $arguments; From a133ccac54eac73ce22036b6e0f334a13171f696 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 23 May 2019 11:04:46 -0700 Subject: [PATCH 27/70] Clean up code --- src/ProviderAndDumperAggregator.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index b2d8e99..309ccff 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -221,11 +221,13 @@ protected function getArguments(array $arguments, string $provider) : array $adapter = $this->getAdapterClass($provider); if ($adapter) { + $adapter = new $adapter; + if ($this->requiresReader($provider)) { - array_unshift($arguments, new $adapter(config('geocoder.reader'))); - } else { - array_unshift($arguments, new $adapter()); + $adapter = new $adapter(config('geocoder.reader')); } + + array_unshift($arguments, $adapter); } return $arguments; From 9e19e27e6c9c5fb703dfd18ff69c439faef2fd2b Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 23 May 2019 11:13:59 -0700 Subject: [PATCH 28/70] Fix initialization of geocoder adapter --- src/ProviderAndDumperAggregator.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index a23805a..1aa8c9d 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -230,11 +230,9 @@ protected function getArguments(array $arguments, string $provider) : array $adapter = $this->getAdapterClass($provider); if ($adapter) { - $adapter = new $adapter; - - if ($this->requiresReader($provider)) { - $adapter = new $adapter(config('geocoder.reader')); - } + $adapter = $this->requiresReader($provider) + ? new $adapter(config('geocoder.reader')) + : new $adapter; array_unshift($arguments, $adapter); } From 278cc1e2c1d00731260267b44c4159a9dc3c8356 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 23 May 2019 11:33:43 -0700 Subject: [PATCH 29/70] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 276a9b1..bc90a20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.1.2] - 23 May 2019 +### Fixed +- initialization of geocoder adapter. + ## [4.0.21] - 3 Nov 2018 ### Added - `->toJson()` method when querying results. From d36b700362aedd22a5bbcf9544f677d2baf9098f Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 28 Aug 2019 08:10:44 -0700 Subject: [PATCH 30/70] Update dependencies for Laravel 6. --- composer.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 4b8ad1c..a8d41b6 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,8 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "5.0 - 5.8", - "illuminate/support": "5.0 - 5.8", + "illuminate/cache": "5.0 - 6.0", + "illuminate/support": "5.0 - 6.0.x-dev@dev", "php-http/curl-client": "*", "php": ">=7.1.3", "willdurand/geocoder": "^4.0" @@ -41,12 +41,12 @@ "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", "mockery/mockery": "*", - "orchestra/testbench-browser-kit": "3.8.*", - "orchestra/database": "3.8.x-dev@dev", - "orchestra/testbench-dusk": "3.8.x-dev@dev", - "orchestra/testbench": "3.8.*", + "orchestra/testbench-browser-kit": "3.9.x-dev@dev", + "orchestra/database": "3.9.x-dev@dev", + "orchestra/testbench-dusk": "3.9.x-dev@dev", + "orchestra/testbench": "3.9.x-dev@dev", "php-coveralls/php-coveralls": "*", - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "8.*", "sebastian/phpcpd": "*" }, "autoload": { From e481421c01a2b41a8e9ab89dfa87b53e8f44a217 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 28 Aug 2019 08:15:51 -0700 Subject: [PATCH 31/70] Update dependencies --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a8d41b6..77639b3 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", "illuminate/cache": "5.0 - 6.0", - "illuminate/support": "5.0 - 6.0.x-dev@dev", + "illuminate/support": "5.0 - 6.0", "php-http/curl-client": "*", "php": ">=7.1.3", "willdurand/geocoder": "^4.0" @@ -67,6 +67,7 @@ ] } }, + "minimum-stability": "dev", "prefer-stable": true, "config": { "preferred-install": "dist", From e17fb92c9c0eaaa1b0adffd8825c747ec90e1833 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 29 Aug 2019 07:54:13 -0700 Subject: [PATCH 32/70] Bring tests to green and fix dependencies. --- .phpunit.result.cache | 1 + composer.json | 1 - tests/CreatesApplication.php | 2 -- tests/Feature/Providers/GeocoderServiceTest.php | 9 +++++---- 4 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..744d308 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":2941:{a:2:{s:7:"defects";a:2:{s:94:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItReverseGeocodesCoordinates";i:4;s:77:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testCacheIsUsed";i:4;}s:5:"times";a:26:{s:94:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItReverseGeocodesCoordinates";d:0.296;s:89:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenAddress";d:0.222;s:91:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenIPAddress";d:0.01;s:100:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenAddressWithUmlauts";d:0.216;s:108:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenAddressWithUmlautsInRegion";d:0.21;s:91:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItCanUseASpecificProvider";d:0.187;s:83:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItDumpsAndAddress";d:0.214;s:101:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItThrowsAnExceptionForInvalidDumper";d:0.207;s:72:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testConfig";d:0.008;s:81:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testLoadedProviders";d:0.01;s:74:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGeocoder";d:0.009;s:77:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testCacheIsUsed";d:0.247;s:93:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGeocodeQueryProvidesResults";d:0.262;s:93:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testReverseQueryProvidesResults";d:0.391;s:87:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testFacadeProvidesResults";d:0.215;s:102:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItCanUseMaxMindBinaryWithoutProvider";d:0.008;s:86:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGetNameReturnsString";d:0.007;s:83:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testLimitingOfResults";d:0.804;s:84:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testFetchingAllResults";d:0.231;s:78:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGetProviders";d:0.007;s:77:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGetProvider";d:0.007;s:92:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testJapaneseCharacterGeocoding";d:0.461;s:81:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItProvidesState";d:0.218;s:86:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItProvidesAdminLevel";d:0.201;s:91:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItHandlesOnlyCityAndState";d:0.788;s:90:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testEmptyResultsAreNotCached";d:0.586;}}} \ No newline at end of file diff --git a/composer.json b/composer.json index 77639b3..7d7f132 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,6 @@ "geocoder-php/maxmind-binary-provider": "^4.0", "mockery/mockery": "*", "orchestra/testbench-browser-kit": "3.9.x-dev@dev", - "orchestra/database": "3.9.x-dev@dev", "orchestra/testbench-dusk": "3.9.x-dev@dev", "orchestra/testbench": "3.9.x-dev@dev", "php-coveralls/php-coveralls": "*", diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 7833218..3abda79 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -1,6 +1,5 @@ reverse(38.897957, -77.036560) ->get() ->filter(function (GoogleAddress $address) { - return str_contains($address->getStreetName() ?? '', 'Northwest'); + return Str::contains($address->getStreetName() ?? '', 'Northwest'); }) ->first(); @@ -159,7 +160,7 @@ public function testGeocoder() public function testCacheIsUsed() { - $cacheKey = sha1(str_slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')))); + $cacheKey = sha1(Str::slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')))); $result = app('geocoder') ->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA') @@ -270,7 +271,7 @@ public function testGetProvider() public function testJapaneseCharacterGeocoding() { - $cacheKey = sha1(str_slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')))); + $cacheKey = sha1(Str::slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')))); app('geocoder') ->geocode('108-0075 東京都港区港南2丁目16-3') @@ -310,7 +311,7 @@ public function testItHandlesOnlyCityAndState() public function testEmptyResultsAreNotCached() { - $cacheKey = md5(str_slug(strtolower(urlencode('_')))); + $cacheKey = md5(Str::slug(strtolower(urlencode('_')))); Geocoder::geocode('_')->get(); From 9bf44e18dbd4209a482f59939a6efdc9ff3b45fe Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 29 Aug 2019 08:02:44 -0700 Subject: [PATCH 33/70] Update travis config. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a2e8692..ddcc79b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 7.1.3 - 7.2 + - 7.3 before_script: - travis_retry composer self-update From 5f005a8be99215db9532b69a754c3a7f5db70e80 Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Wed, 4 Sep 2019 20:25:59 +0200 Subject: [PATCH 34/70] Inject Logger configuration Fixes #145 --- src/ProviderAndDumperAggregator.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 1aa8c9d..73b2df9 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -247,7 +247,13 @@ protected function getProvidersFromConfiguration(Collection $providers) : array $reflection = new ReflectionClass($provider); if ($provider === 'Geocoder\Provider\Chain\Chain') { - return $reflection->newInstance($arguments); + $chainProvider = $reflection->newInstance($arguments); + + if (in_array(\Psr\Log\LoggerAwareTrait::class, class_uses($chainProvider)) && app(\Illuminate\Log\Logger::class) !== null) { + $chainProvider->setLogger(app(\Illuminate\Log\Logger::class)); + } + + return $chainProvider; } return $reflection->newInstanceArgs($arguments); From 9a41544e49009ec3dde9f196953041bed6864c83 Mon Sep 17 00:00:00 2001 From: Jasper Zonneveld Date: Wed, 2 Oct 2019 11:49:37 +0200 Subject: [PATCH 35/70] Require Laravel 5.x or 6.x instaed of 5.0 - 6.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 7d7f132..292ebb1 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,8 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "5.0 - 6.0", - "illuminate/support": "5.0 - 6.0", + "illuminate/cache": "^5.0|^6.0", + "illuminate/support": "^5.0|^6.0", "php-http/curl-client": "*", "php": ">=7.1.3", "willdurand/geocoder": "^4.0" From 63219c0baba5f6dff5c242b1d680a8ff8cecaa78 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 2 Oct 2019 08:02:13 -0700 Subject: [PATCH 36/70] Update dependency compatibility. --- .gitignore | 3 ++- composer.json | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 2c1fc0c..7cfd555 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor composer.phar composer.lock -.DS_Store \ No newline at end of file +.DS_Store +.phpunit.result.cache diff --git a/composer.json b/composer.json index 292ebb1..4e6ed48 100644 --- a/composer.json +++ b/composer.json @@ -41,9 +41,9 @@ "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", "mockery/mockery": "*", - "orchestra/testbench-browser-kit": "3.9.x-dev@dev", - "orchestra/testbench-dusk": "3.9.x-dev@dev", - "orchestra/testbench": "3.9.x-dev@dev", + "orchestra/testbench-browser-kit": "^4.0", + "orchestra/testbench-dusk": "^4.0", + "orchestra/testbench": "^4.0", "php-coveralls/php-coveralls": "*", "phpunit/phpunit": "8.*", "sebastian/phpcpd": "*" From 9dc314a766d26e87664099e40a7cbca46d3a7252 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 2 Oct 2019 08:02:48 -0700 Subject: [PATCH 37/70] WIP --- .phpunit.result.cache | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 744d308..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":2941:{a:2:{s:7:"defects";a:2:{s:94:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItReverseGeocodesCoordinates";i:4;s:77:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testCacheIsUsed";i:4;}s:5:"times";a:26:{s:94:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItReverseGeocodesCoordinates";d:0.296;s:89:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenAddress";d:0.222;s:91:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenIPAddress";d:0.01;s:100:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenAddressWithUmlauts";d:0.216;s:108:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItResolvesAGivenAddressWithUmlautsInRegion";d:0.21;s:91:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItCanUseASpecificProvider";d:0.187;s:83:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItDumpsAndAddress";d:0.214;s:101:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItThrowsAnExceptionForInvalidDumper";d:0.207;s:72:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testConfig";d:0.008;s:81:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testLoadedProviders";d:0.01;s:74:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGeocoder";d:0.009;s:77:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testCacheIsUsed";d:0.247;s:93:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGeocodeQueryProvidesResults";d:0.262;s:93:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testReverseQueryProvidesResults";d:0.391;s:87:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testFacadeProvidesResults";d:0.215;s:102:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItCanUseMaxMindBinaryWithoutProvider";d:0.008;s:86:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGetNameReturnsString";d:0.007;s:83:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testLimitingOfResults";d:0.804;s:84:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testFetchingAllResults";d:0.231;s:78:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGetProviders";d:0.007;s:77:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testGetProvider";d:0.007;s:92:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testJapaneseCharacterGeocoding";d:0.461;s:81:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItProvidesState";d:0.218;s:86:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItProvidesAdminLevel";d:0.201;s:91:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testItHandlesOnlyCityAndState";d:0.788;s:90:"Geocoder\Laravel\Tests\Feature\Providers\GeocoderServiceTest::testEmptyResultsAreNotCached";d:0.586;}}} \ No newline at end of file From d9cccd3ac0286c50a2f08c77d5bf515718c108cf Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 2 Oct 2019 08:11:11 -0700 Subject: [PATCH 38/70] Inject logger into chain provider. --- src/ProviderAndDumperAggregator.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 73b2df9..7449665 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -18,8 +18,10 @@ use Geocoder\ProviderAggregator; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; +use Illuminate\Log\Logger; use Illuminate\Support\Collection; use Illuminate\Support\Str; +use Psr\Log\LoggerAwareTrait; use ReflectionClass; /** @@ -246,11 +248,13 @@ protected function getProvidersFromConfiguration(Collection $providers) : array $arguments = $this->getArguments($arguments, $provider); $reflection = new ReflectionClass($provider); - if ($provider === 'Geocoder\Provider\Chain\Chain') { + if ($provider === "Geocoder\Provider\Chain\Chain") { $chainProvider = $reflection->newInstance($arguments); - if (in_array(\Psr\Log\LoggerAwareTrait::class, class_uses($chainProvider)) && app(\Illuminate\Log\Logger::class) !== null) { - $chainProvider->setLogger(app(\Illuminate\Log\Logger::class)); + if (in_array(LoggerAwareTrait::class, class_uses($chainProvider)) + && app(Logger::class) !== null + ) { + $chainProvider->setLogger(app(Logger::class)); } return $chainProvider; From 67f027b23654e62f62d489c66fd4cc4a5baa8a6a Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Tue, 15 Oct 2019 09:15:44 -0700 Subject: [PATCH 39/70] Don't set logger if it doesn't exist. Fixes #162 --- src/ProviderAndDumperAggregator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 7449665..714d0ad 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -251,7 +251,8 @@ protected function getProvidersFromConfiguration(Collection $providers) : array if ($provider === "Geocoder\Provider\Chain\Chain") { $chainProvider = $reflection->newInstance($arguments); - if (in_array(LoggerAwareTrait::class, class_uses($chainProvider)) + if (class_exists(Logger::class) + && in_array(LoggerAwareTrait::class, class_uses($chainProvider)) && app(Logger::class) !== null ) { $chainProvider->setLogger(app(Logger::class)); From cd5cd92be69a8b08c5f689a8cac830789fb76c28 Mon Sep 17 00:00:00 2001 From: Michelle Lewis Date: Wed, 16 Oct 2019 10:47:44 -0500 Subject: [PATCH 40/70] Allow passing reader class and arguments as array --- src/ProviderAndDumperAggregator.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 714d0ad..62fe04a 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -221,6 +221,18 @@ protected function getAdapterClass(string $provider) : string return config('geocoder.adapter'); } + protected function getReader() + { + if (is_array(config('geocoder.reader'))) { + $reflection = new ReflectionClass(config('geocoder.reader.class')); + $reader = $reflection->newInstanceArgs(config('geocoder.reader.arguments')); + } else { + $reader = config('geocoder.reader'); + } + + return $reader; + } + protected function getArguments(array $arguments, string $provider) : array { if ($provider === 'Geocoder\Provider\Chain\Chain') { @@ -232,9 +244,11 @@ protected function getArguments(array $arguments, string $provider) : array $adapter = $this->getAdapterClass($provider); if ($adapter) { - $adapter = $this->requiresReader($provider) - ? new $adapter(config('geocoder.reader')) - : new $adapter; + if ($this->requiresReader($provider)) { + $adapter = new $adapter($this->getReader()); + } else { + $adapter = new $adapter; + } array_unshift($arguments, $adapter); } From dde4def85d6269b27a1fbf360e188a210e1133a7 Mon Sep 17 00:00:00 2001 From: Michelle Lewis Date: Wed, 16 Oct 2019 11:26:08 -0500 Subject: [PATCH 41/70] Update config descriptions --- README.md | 3 ++- config/geocoder.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4bed33..6b39109 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,8 @@ return [ | | You can specify a reader for specific providers, like GeoIp2, which | connect to a local file-database. The reader should be set to an - | instance of the required reader class. + | instance of the required reader class or an array containing the reader + | class and arguments. | | Please consult the official Geocoder documentation for more info. | https://github.com/geocoder-php/geoip2-provider diff --git a/config/geocoder.php b/config/geocoder.php index d04b40d..7049d01 100644 --- a/config/geocoder.php +++ b/config/geocoder.php @@ -88,7 +88,8 @@ | | You can specify a reader for specific providers, like GeoIp2, which | connect to a local file-database. The reader should be set to an - | instance of the required reader class. + | instance of the required reader class or an array containing the reader + | class and arguments. | | Please consult the official Geocoder documentation for more info. | https://github.com/geocoder-php/geoip2-provider From 72e7b7fb609b30ddc487d6222180b48d95fbd249 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 16 Oct 2019 17:51:54 -0700 Subject: [PATCH 42/70] Update reader configuration to support array notation, so that config can be cached. --- config/geocoder.php | 8 ++++++++ phpmd.xml | 0 src/ProviderAndDumperAggregator.php | 10 ++++++---- tests/config/testConfig.php | 7 ++++++- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 phpmd.xml diff --git a/config/geocoder.php b/config/geocoder.php index 7049d01..03b8b44 100644 --- a/config/geocoder.php +++ b/config/geocoder.php @@ -96,6 +96,14 @@ | | Default: null | + | Example: + | 'reader' => [ + | WebService::class => [ + | env('MAXMIND_USER_ID'), + | env('MAXMIND_LICENSE_KEY') + | ], + | ], + | */ 'reader' => null, diff --git a/phpmd.xml b/phpmd.xml new file mode 100644 index 0000000..e69de29 diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 62fe04a..9a17334 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -223,11 +223,13 @@ protected function getAdapterClass(string $provider) : string protected function getReader() { + $reader = config('geocoder.reader'); + if (is_array(config('geocoder.reader'))) { - $reflection = new ReflectionClass(config('geocoder.reader.class')); - $reader = $reflection->newInstanceArgs(config('geocoder.reader.arguments')); - } else { - $reader = config('geocoder.reader'); + $readerClass = array_key_first(config('geocoder.reader')); + $readerArguments = config('geocoder.reader')[$readerClass]; + $reflection = new ReflectionClass($readerClass); + $reader = $reflection->newInstanceArgs($readerArguments); } return $reader; diff --git a/tests/config/testConfig.php b/tests/config/testConfig.php index 1b752de..9ee6af6 100644 --- a/tests/config/testConfig.php +++ b/tests/config/testConfig.php @@ -38,5 +38,10 @@ ], ], 'adapter' => Client::class, - 'reader' => new Reader(__DIR__ . '/../resources/assets/GeoLite2-City.mmdb'), + // 'reader' => new Reader(__DIR__ . '/../resources/assets/GeoLite2-City.mmdb'), + "reader" => [ + Reader::class => [ + __DIR__ . '/../resources/assets/GeoLite2-City.mmdb', + ], + ], ]; From c3420db2ae524262accfdb4941977004c5ea7110 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sat, 29 Feb 2020 14:04:31 -0800 Subject: [PATCH 43/70] Added Laravel 7 compatibility. --- CHANGELOG.md | 4 ++++ composer.json | 18 ++++++++---------- .../Feature/Providers/GeocoderServiceTest.php | 4 ---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc90a20..02b47dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.2.0] - 2020-02-29 +### Added +- Laravel 7 compatibility. + ## [4.1.2] - 23 May 2019 ### Fixed - initialization of geocoder adapter. diff --git a/composer.json b/composer.json index 4e6ed48..d882849 100644 --- a/composer.json +++ b/composer.json @@ -28,25 +28,23 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "^5.0|^6.0", - "illuminate/support": "^5.0|^6.0", + "illuminate/cache": "^5.0|^6.0|^7.0", + "illuminate/support": "^5.0|^6.0|^7.0", "php-http/curl-client": "*", - "php": ">=7.1.3", + "php": ">=7.2.5", "willdurand/geocoder": "^4.0" }, "require-dev": { "doctrine/dbal": "*", - "fzaninotto/faker": "*", "geocoder-php/bing-maps-provider": "^4.0", "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", - "mockery/mockery": "*", - "orchestra/testbench-browser-kit": "^4.0", - "orchestra/testbench-dusk": "^4.0", - "orchestra/testbench": "^4.0", + "orchestra/testbench-browser-kit": "^5.0", + "orchestra/testbench-dusk": "^5.0", + "orchestra/testbench": "^5.0", "php-coveralls/php-coveralls": "*", - "phpunit/phpunit": "8.*", - "sebastian/phpcpd": "*" + "phpunit/phpunit": "8.5", + "sebastian/phpcpd": "^5.0" }, "autoload": { "psr-4": { diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index 14cc960..1f87f94 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -277,10 +277,6 @@ public function testJapaneseCharacterGeocoding() ->geocode('108-0075 東京都港区港南2丁目16-3') ->get(); - $this->assertEquals( - $cacheKey, - sha1('108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93') - ); $this->assertTrue(app('cache')->has($cacheKey)); } From e263fb4b383b8dcd613235c2038e63ece15f2c6e Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sat, 29 Feb 2020 14:05:06 -0800 Subject: [PATCH 44/70] Fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02b47dc..b32e157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [4.2.0] - 2020-02-29 +## [4.3.0] - 2020-02-29 ### Added - Laravel 7 compatibility. From e34555b24bbcb9ba8faa4936db75028c894f7615 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sat, 29 Feb 2020 14:48:51 -0800 Subject: [PATCH 45/70] Update test config. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ddcc79b..f6805bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: php php: - - 7.2 + - 7.2.5 - 7.3 + - 7.4 before_script: - travis_retry composer self-update From b907ed2964954a75ab8eb38776a914ed1a5bd6a3 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 1 Apr 2020 06:44:12 -0700 Subject: [PATCH 46/70] Update geocoder.php --- config/geocoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/geocoder.php b/config/geocoder.php index 03b8b44..f374b44 100644 --- a/config/geocoder.php +++ b/config/geocoder.php @@ -27,7 +27,7 @@ | Cache Duration |----------------------------------------------------------------------- | - | Specify the cache duration in minutes. The default approximates a + | Specify the cache duration in seconds. The default approximates a | "forever" cache, but there are certain issues with Laravel's forever | caching methods that prevent us from using them in this project. | From cfa6230078efaa65a6467705a097c6cec97a48a3 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 1 Apr 2020 06:44:40 -0700 Subject: [PATCH 47/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b39109..e35d3fa 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Finally, configure Geocoder for Laraver to use this store. Edit If you are upgrading and have previously published the geocoder config file, you need to add the `cache-duration` variable, otherwise cache will be disabled (it will default to a `0` cache duration). The default cache duration provided - by the config file is `999999999` minutes, essentially forever. + by the config file is `999999999` seconds, essentially forever. By default, the configuration specifies a Chain provider, containing the GoogleMaps provider for addresses as well as reverse lookups with lat/long, From 10465a1862eb6a2910b8d0a0dfe209f84bd9882a Mon Sep 17 00:00:00 2001 From: Patrick Schocke Date: Sun, 12 Apr 2020 21:26:25 +0200 Subject: [PATCH 48/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e35d3fa..6bebcc0 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ database: ], ``` -Finally, configure Geocoder for Laraver to use this store. Edit +Finally, configure Geocoder for Laravel to use this store. Edit `config/geocoder.php`: ```php "cache" => [ From 2de296bf66a32fe104398ed5c727b20714dbaf30 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 16 Apr 2020 16:20:57 -0700 Subject: [PATCH 49/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bebcc0..d65076b 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ return [ 'providers' => [ Chain::class => [ GoogleMaps::class => [ - env('GOOGLE_MAPS_LOCALE', 'en-US'), + env('GOOGLE_MAPS_LOCALE', 'us'), env('GOOGLE_MAPS_API_KEY'), ], GeoPlugin::class => [], From 0c7e3d82750d2ad4c28ff93837d047016d001c2e Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 16 Apr 2020 16:22:30 -0700 Subject: [PATCH 50/70] Update geocoder.php --- config/geocoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/geocoder.php b/config/geocoder.php index f374b44..c48c183 100644 --- a/config/geocoder.php +++ b/config/geocoder.php @@ -58,7 +58,7 @@ 'providers' => [ Chain::class => [ GoogleMaps::class => [ - env('GOOGLE_MAPS_LOCALE', 'en-US'), + env('GOOGLE_MAPS_LOCALE', 'us'), env('GOOGLE_MAPS_API_KEY'), ], GeoPlugin::class => [], From 47665e473db420750b4e5d732339aaa53919ef3f Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sat, 20 Jun 2020 12:49:57 -0700 Subject: [PATCH 51/70] Added functionality to not cache requests by using `doNotCache()`. --- CHANGELOG.md | 4 ++++ README.md | 9 +++++++++ src/ProviderAndDumperAggregator.php | 12 ++++++++++++ tests/Feature/Providers/GeocoderServiceTest.php | 13 +++++++++++++ 4 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b32e157..e7a2f5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.3.3] - 2020-06-20 +### Added +- functionality to not cache requests by using `doNotCache()`. + ## [4.3.0] - 2020-02-29 ### Added - Laravel 7 compatibility. diff --git a/README.md b/README.md index 6b39109..b9a4c15 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,15 @@ Finally, configure Geocoder for Laraver to use this store. Edit ], ``` +#### Disabling Caching on a Query-Basis +You can disable caching on a query-by-query basis as needed, like so: +```php + $results = app("geocoder") + ->doNotCache() + ->geocode('Los Angeles, CA') + ->get(); +``` + ### Providers If you are upgrading and have previously published the geocoder config file, you need to add the `cache-duration` variable, otherwise cache will be disabled diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 9a17334..f9b356f 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -32,6 +32,7 @@ class ProviderAndDumperAggregator protected $aggregator; protected $limit; protected $results; + protected $isCaching = true; public function __construct() { @@ -59,6 +60,13 @@ public function toJson() : string ->first(); } + public function doNotCache() : self + { + $this->isCaching = false; + + return $this; + } + public function dump(string $dumper) : Collection { $dumperClasses = collect([ @@ -181,6 +189,10 @@ public function using(string $name) : self protected function cacheRequest(string $cacheKey, array $queryElements, string $queryType) { + if (! $this->isCaching) { + return collect($this->aggregator->{$queryType}(...$queryElements)); + } + $hashedCacheKey = sha1($cacheKey); $duration = config("geocoder.cache.duration", 0); $store = config('geocoder.cache.store'); diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index 1f87f94..b67b7b4 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -313,4 +313,17 @@ public function testEmptyResultsAreNotCached() $this->assertFalse(app('cache')->has("geocoder-{$cacheKey}")); } + + public function testCachingCanBeDisabled() + { + $results = app("geocoder") + ->doNotCache() + ->geocode('Los Angeles, CA') + ->get(); + + $this->assertEquals( + "Los Angeles, CA, USA", + $results->first()->getFormattedAddress() + ); + } } From 2cd8813f39224e62dd0c1f73f47a9fe0439e5bcf Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 21 Jun 2020 09:01:41 -0700 Subject: [PATCH 52/70] Changed `getProvider()` method to no longer be deprecated, and instead return the currently set provider, or if none set, the first configured provider. --- CHANGELOG.md | 8 ++++++++ src/ProviderAndDumperAggregator.php | 12 ++++++++---- tests/Feature/Providers/GeocoderServiceTest.php | 9 +++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7a2f5a..44c450f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.3.4] - 2020-06-21 +### Fixed +- non-caching declaration to only apply to current query. + +### Changed +- `getProvider()` method to no longer be deprecated, and instead return the + currently set provider, or if none set, the first configured provider. + ## [4.3.3] - 2020-06-20 ### Added - functionality to not cache requests by using `doNotCache()`. diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index f9b356f..82c3c3c 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -130,12 +130,14 @@ public function limit(int $limit) : self return $this; } - /** - * @deprecated Use `getProviders()` instead. - */ public function getProvider() { - return $this->getProviders()->first(); + $reflectedClass = new ReflectionClass(ProviderAggregator::class); + $reflectedProperty = $reflectedClass->getProperty('provider'); + $reflectedProperty->setAccessible(true); + + return $reflectedProperty->getValue($this->aggregator) + ?? $this->getProviders()->first(); } public function getProviders() : Collection @@ -190,6 +192,8 @@ public function using(string $name) : self protected function cacheRequest(string $cacheKey, array $queryElements, string $queryType) { if (! $this->isCaching) { + $this->isCaching = true; + return collect($this->aggregator->{$queryType}(...$queryElements)); } diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index b67b7b4..aea92ba 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -326,4 +326,13 @@ public function testCachingCanBeDisabled() $results->first()->getFormattedAddress() ); } + + public function testGetProviderReturnsCurrentProvider() + { + $provider = app("geocoder") + ->using("google_maps") + ->getProvider(); + + $this->assertEquals("google_maps", $provider->getName()); + } } From 3e95ab16489099a68b0367652915a7a943f3bedd Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 21 Jun 2020 09:06:01 -0700 Subject: [PATCH 53/70] Fixed caching to be provider-dependent. --- CHANGELOG.md | 1 + src/ProviderAndDumperAggregator.php | 2 +- tests/Feature/Providers/GeocoderServiceTest.php | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44c450f..bf9a76b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [4.3.4] - 2020-06-21 ### Fixed - non-caching declaration to only apply to current query. +- caching to take provider into account. ### Changed - `getProvider()` method to no longer be deprecated, and instead return the diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 82c3c3c..a1909c0 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -197,7 +197,7 @@ protected function cacheRequest(string $cacheKey, array $queryElements, string $ return collect($this->aggregator->{$queryType}(...$queryElements)); } - $hashedCacheKey = sha1($cacheKey); + $hashedCacheKey = sha1($this->getProvider()->getName() . "-" . $cacheKey); $duration = config("geocoder.cache.duration", 0); $store = config('geocoder.cache.store'); diff --git a/tests/Feature/Providers/GeocoderServiceTest.php b/tests/Feature/Providers/GeocoderServiceTest.php index aea92ba..22c3206 100644 --- a/tests/Feature/Providers/GeocoderServiceTest.php +++ b/tests/Feature/Providers/GeocoderServiceTest.php @@ -160,7 +160,10 @@ public function testGeocoder() public function testCacheIsUsed() { - $cacheKey = sha1(Str::slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')))); + $cacheKey = sha1( + app('geocoder')->getProvider()->getName() + . "-" . Str::slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA'))) + ); $result = app('geocoder') ->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA') @@ -271,7 +274,9 @@ public function testGetProvider() public function testJapaneseCharacterGeocoding() { - $cacheKey = sha1(Str::slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')))); + $cacheKey = sha1(app('geocoder')->getProvider()->getName() + . "-" . Str::slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3'))) + ); app('geocoder') ->geocode('108-0075 東京都港区港南2丁目16-3') From a4e2ab3aea59fd83e1890e07cdb2b4f1a8b0904e Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 9 Sep 2020 13:51:41 +0000 Subject: [PATCH 54/70] Upgrade to Laravel 8. --- composer.json | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index d882849..f1f8ff0 100644 --- a/composer.json +++ b/composer.json @@ -28,10 +28,10 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "^5.0|^6.0|^7.0", - "illuminate/support": "^5.0|^6.0|^7.0", + "illuminate/cache": "^5.0|^6.0|^7.0|^8.0", + "illuminate/support": "^5.0|^6.0|^7.0|^8.0", "php-http/curl-client": "*", - "php": ">=7.2.5", + "php": ">=7.3", "willdurand/geocoder": "^4.0" }, "require-dev": { @@ -39,9 +39,10 @@ "geocoder-php/bing-maps-provider": "^4.0", "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", - "orchestra/testbench-browser-kit": "^5.0", - "orchestra/testbench-dusk": "^5.0", - "orchestra/testbench": "^5.0", + "laravel/legacy-factories": "^1.0", + "orchestra/testbench": "^6.0", + "orchestra/testbench-browser-kit": "^6.0", + "orchestra/testbench-dusk": "^6.0", "php-coveralls/php-coveralls": "*", "phpunit/phpunit": "8.5", "sebastian/phpcpd": "^5.0" From 6810bcc92b289274e08a6cb17b01a674f9ee2c65 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 9 Sep 2020 07:01:00 -0700 Subject: [PATCH 55/70] Update .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f6805bd..a586f6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.2.5 - 7.3 - 7.4 From cdfa5d6cd1dcb69ae0df0d9096053d3087a3a2b0 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 2 Dec 2020 09:41:48 -0800 Subject: [PATCH 56/70] Update composer.json --- composer.json | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f1f8ff0..7010230 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,19 @@ "role": "Original Creator" } ], + "repositories": [ + { + "type": "git", + "url": "git@github.com:mikebronner/chain-provider.git" + }, + { + "type": "git", + "url": "git@github.com:mikebronner/geocoder.git" + } + + ], "require": { - "geocoder-php/chain-provider": "^4.0", + "geocoder-php/chain-provider": "dev-patch-1@dev", "geocoder-php/geo-plugin-provider": "^4.0", "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", @@ -32,7 +43,7 @@ "illuminate/support": "^5.0|^6.0|^7.0|^8.0", "php-http/curl-client": "*", "php": ">=7.3", - "willdurand/geocoder": "^4.0" + "willdurand/geocoder": "dev-patch-1@dev" }, "require-dev": { "doctrine/dbal": "*", From 0703c4774465a6090deed6a364881c339de7bb81 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 2 Dec 2020 09:47:53 -0800 Subject: [PATCH 57/70] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7010230..f4ed3f5 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ ], "require": { - "geocoder-php/chain-provider": "dev-patch-1@dev", + "geocoder-php/chain-provider": "php8_support@dev", "geocoder-php/geo-plugin-provider": "^4.0", "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", From cb9e89de9d5b9ed743bef4f7b745b3c107ca2eed Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 2 Dec 2020 10:00:16 -0800 Subject: [PATCH 58/70] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f4ed3f5..219ef6b 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "illuminate/cache": "^5.0|^6.0|^7.0|^8.0", "illuminate/support": "^5.0|^6.0|^7.0|^8.0", "php-http/curl-client": "*", - "php": ">=7.3", + "php": "^7.3|^8.0", "willdurand/geocoder": "dev-patch-1@dev" }, "require-dev": { From 55ab04e389a3174f03a9b3eae5168f6413e0ab97 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 2 Dec 2020 10:00:51 -0800 Subject: [PATCH 59/70] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 219ef6b..8c1a424 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ ], "require": { - "geocoder-php/chain-provider": "php8_support@dev", + "geocoder-php/chain-provider": "^4.0", "geocoder-php/geo-plugin-provider": "^4.0", "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", @@ -43,7 +43,7 @@ "illuminate/support": "^5.0|^6.0|^7.0|^8.0", "php-http/curl-client": "*", "php": "^7.3|^8.0", - "willdurand/geocoder": "dev-patch-1@dev" + "willdurand/geocoder": "^4.0" }, "require-dev": { "doctrine/dbal": "*", From 9d06ba7a643db859ec1831fe2d21801d161a8a0a Mon Sep 17 00:00:00 2001 From: Jiong Ye Date: Fri, 16 Jul 2021 11:12:26 -0400 Subject: [PATCH 60/70] Fixed remove empty cache entry method It didn't actually remove the cache entry because cache store was not specified. --- src/ProviderAndDumperAggregator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index a1909c0..a5c07c9 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -320,7 +320,9 @@ protected function preventCacheKeyHashCollision( protected function removeEmptyCacheEntry(Collection $result, string $cacheKey) { if ($result && $result->isEmpty()) { - app('cache')->forget($cacheKey); + app('cache') + ->store(config('geocoder.cache.store')) + ->forget($cacheKey); } } From 1f65d69c00a616f307d37cacc26a0198396a7753 Mon Sep 17 00:00:00 2001 From: Andrew Minion Date: Mon, 6 Dec 2021 12:19:51 -0600 Subject: [PATCH 61/70] allow updated upstream repositories --- composer.json | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/composer.json b/composer.json index 8c1a424..e858832 100644 --- a/composer.json +++ b/composer.json @@ -22,17 +22,6 @@ "role": "Original Creator" } ], - "repositories": [ - { - "type": "git", - "url": "git@github.com:mikebronner/chain-provider.git" - }, - { - "type": "git", - "url": "git@github.com:mikebronner/geocoder.git" - } - - ], "require": { "geocoder-php/chain-provider": "^4.0", "geocoder-php/geo-plugin-provider": "^4.0", From e81506d22c3b452346140d7979e609d5936e8ebd Mon Sep 17 00:00:00 2001 From: Andrew Minion Date: Mon, 6 Dec 2021 12:37:29 -0600 Subject: [PATCH 62/70] update dev dependencies to allow PHP 8 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e858832..028f0c5 100644 --- a/composer.json +++ b/composer.json @@ -44,8 +44,8 @@ "orchestra/testbench-browser-kit": "^6.0", "orchestra/testbench-dusk": "^6.0", "php-coveralls/php-coveralls": "*", - "phpunit/phpunit": "8.5", - "sebastian/phpcpd": "^5.0" + "phpunit/phpunit": "8.5|^9.0", + "sebastian/phpcpd": "^5.0|^6.0" }, "autoload": { "psr-4": { From 92ca30ef3b347d5e32f9cf33a5692ab955b7fca3 Mon Sep 17 00:00:00 2001 From: Nabil EL Mahiri Date: Thu, 10 Feb 2022 04:55:31 +0100 Subject: [PATCH 63/70] Update composer.json --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 028f0c5..be27372 100644 --- a/composer.json +++ b/composer.json @@ -28,10 +28,10 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "^5.0|^6.0|^7.0|^8.0", - "illuminate/support": "^5.0|^6.0|^7.0|^8.0", + "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0", + "illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0", "php-http/curl-client": "*", - "php": "^7.3|^8.0", + "php": "^8.0", "willdurand/geocoder": "^4.0" }, "require-dev": { @@ -40,9 +40,9 @@ "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", "laravel/legacy-factories": "^1.0", - "orchestra/testbench": "^6.0", - "orchestra/testbench-browser-kit": "^6.0", - "orchestra/testbench-dusk": "^6.0", + "orchestra/testbench": "^7.0", + "orchestra/testbench-browser-kit": "^7.0", + "orchestra/testbench-dusk": "^7.0", "php-coveralls/php-coveralls": "*", "phpunit/phpunit": "8.5|^9.0", "sebastian/phpcpd": "^5.0|^6.0" From 55c61bd655b6a2f0b171589057fdb41a69acb31c Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Thu, 10 Feb 2022 12:31:29 +0000 Subject: [PATCH 64/70] Updated tests. --- phpunit.xml | 64 +++++++++---------- tests/BrowserTestCase.php | 18 ------ .../Feature/Providers/GeocoderServiceTest.php | 57 ++++++++--------- tests/UnitTestCase.php | 8 --- 4 files changed, 57 insertions(+), 90 deletions(-) delete mode 100644 tests/BrowserTestCase.php delete mode 100644 tests/UnitTestCase.php diff --git a/phpunit.xml b/phpunit.xml index fa0e22b..648dc54 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,41 +1,35 @@ - - - ./tests/Browser - - + + + ./src + + + - ./tests/Feature - - - - ./tests/Unit + ./tests/Feature - - - - ./src - - - - - - - - - - - - + + + + + + + + + + + diff --git a/tests/BrowserTestCase.php b/tests/BrowserTestCase.php deleted file mode 100644 index 8b191b6..0000000 --- a/tests/BrowserTestCase.php +++ /dev/null @@ -1,18 +0,0 @@ -reverse(38.897957, -77.036560) - ->get() - ->filter(function (GoogleAddress $address) { - return Str::contains($address->getStreetName() ?? '', 'Northwest'); - }) - ->first(); - - $this->assertNotNull($result); - $this->assertEquals('1600', $result->getStreetNumber()); - $this->assertEquals('Pennsylvania Avenue Northwest', $result->getStreetName()); - $this->assertEquals('Washington', $result->getLocality()); - $this->assertEquals('20500', $result->getPostalCode()); - } + // public function testItReverseGeocodesCoordinates() + // { + // $result = app('geocoder') + // ->reverse(38.897957, -77.036560) + // ->get() + // ->filter(function (GoogleAddress $address) { + // return Str::contains($address->getStreetName() ?? '', 'Northwest'); + // }) + // ->first(); + + // $this->assertNotNull($result); + // $this->assertEquals('1600', $result->getStreetNumber()); + // $this->assertEquals('Pennsylvania Avenue Northwest', $result->getStreetName()); + // $this->assertEquals('Washington', $result->getLocality()); + // $this->assertEquals('20500', $result->getPostalCode()); + // } public function testItResolvesAGivenAddress() { diff --git a/tests/UnitTestCase.php b/tests/UnitTestCase.php deleted file mode 100644 index 12c041f..0000000 --- a/tests/UnitTestCase.php +++ /dev/null @@ -1,8 +0,0 @@ - Date: Thu, 10 Feb 2022 05:48:16 -0700 Subject: [PATCH 65/70] Update phpunit.xml --- phpunit.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 648dc54..1524cdf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -30,6 +30,5 @@ - From cc2ef41076de605e84ca4fa05c0c9ce47621b5c3 Mon Sep 17 00:00:00 2001 From: Devin Norgarb Date: Sat, 17 Dec 2022 23:21:15 +0200 Subject: [PATCH 66/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb3af79..268684c 100644 --- a/README.md +++ b/README.md @@ -274,7 +274,7 @@ The one change to keep in mind here is that the results returned from instead of returning an instance of `AddressCollection`. This should provide greater versatility in manipulation of the results, and be inline with expectations for working with Laravel. The existing `AddressCollection` - methods should map strait over to Laravel's `Collection` methods. But be sure + methods should map straight over to Laravel's `Collection` methods. But be sure to double-check your results, if you have been using `count()`, `first()`, `isEmpty()`, `slice()`, `has()`, `get()`, or `all()` on your results. From 75fb5a450772c4c406331e5d2c3a0ab7f026eedf Mon Sep 17 00:00:00 2001 From: Shift Date: Thu, 2 Feb 2023 21:50:32 +0000 Subject: [PATCH 67/70] Bump dependencies for Laravel 10 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index be27372..f06aa36 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,8 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0", - "illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0", + "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0", "php-http/curl-client": "*", "php": "^8.0", "willdurand/geocoder": "^4.0" @@ -40,7 +40,7 @@ "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", "laravel/legacy-factories": "^1.0", - "orchestra/testbench": "^7.0", + "orchestra/testbench": "^7.0|^8.0", "orchestra/testbench-browser-kit": "^7.0", "orchestra/testbench-dusk": "^7.0", "php-coveralls/php-coveralls": "*", From c9d1ccd83e5d1050ec30cc999ff4edb458e4932c Mon Sep 17 00:00:00 2001 From: Shift Date: Tue, 27 Feb 2024 18:14:05 +0000 Subject: [PATCH 68/70] Bump dependencies for Laravel 11 --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f06aa36..42a92b2 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,8 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0", - "illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", "php-http/curl-client": "*", "php": "^8.0", "willdurand/geocoder": "^4.0" @@ -40,11 +40,11 @@ "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", "laravel/legacy-factories": "^1.0", - "orchestra/testbench": "^7.0|^8.0", - "orchestra/testbench-browser-kit": "^7.0", - "orchestra/testbench-dusk": "^7.0", + "orchestra/testbench": "^7.0|^8.0|^9.0", + "orchestra/testbench-browser-kit": "^7.0|^8.5", + "orchestra/testbench-dusk": "^7.0|^8.22", "php-coveralls/php-coveralls": "*", - "phpunit/phpunit": "8.5|^9.0", + "phpunit/phpunit": "8.5|^9.0|^10.5", "sebastian/phpcpd": "^5.0|^6.0" }, "autoload": { From 573b4ce17b8bd0678d93c779989f0daeb7623480 Mon Sep 17 00:00:00 2001 From: Shift Date: Tue, 18 Feb 2025 17:53:40 +0000 Subject: [PATCH 69/70] Bump dependencies for Laravel 12 --- composer.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 42a92b2..5b4677e 100644 --- a/composer.json +++ b/composer.json @@ -28,11 +28,11 @@ "geocoder-php/google-maps-provider": "^4.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", - "illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", "php-http/curl-client": "*", "php": "^8.0", - "willdurand/geocoder": "^4.0" + "willdurand/geocoder": "^4.0|^5.0" }, "require-dev": { "doctrine/dbal": "*", @@ -40,11 +40,11 @@ "geocoder-php/geoip2-provider": "^4.0", "geocoder-php/maxmind-binary-provider": "^4.0", "laravel/legacy-factories": "^1.0", - "orchestra/testbench": "^7.0|^8.0|^9.0", - "orchestra/testbench-browser-kit": "^7.0|^8.5", - "orchestra/testbench-dusk": "^7.0|^8.22", + "orchestra/testbench": "^7.0|^8.0|^9.0|^10.0", + "orchestra/testbench-browser-kit": "^7.0|^8.5|^10.0", + "orchestra/testbench-dusk": "^7.0|^8.22|^10.0", "php-coveralls/php-coveralls": "*", - "phpunit/phpunit": "8.5|^9.0|^10.5", + "phpunit/phpunit": "8.5|^9.0|^10.5|^11.5.3", "sebastian/phpcpd": "^5.0|^6.0" }, "autoload": { From 34d8ea717953718e836b192eeb0ba833cf97728a Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Wed, 5 Mar 2025 18:09:07 -0700 Subject: [PATCH 70/70] WIP --- composer.json | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 5b4677e..21cd476 100644 --- a/composer.json +++ b/composer.json @@ -23,9 +23,9 @@ } ], "require": { - "geocoder-php/chain-provider": "^4.0", - "geocoder-php/geo-plugin-provider": "^4.0", - "geocoder-php/google-maps-provider": "^4.0", + "geocoder-php/chain-provider": "^4.0|^5.0", + "geocoder-php/geo-plugin-provider": "^4.0|^5.0", + "geocoder-php/google-maps-provider": "^4.0|^5.0", "guzzlehttp/psr7": "*", "http-interop/http-factory-guzzle": "^1.0", "illuminate/cache": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", @@ -44,8 +44,7 @@ "orchestra/testbench-browser-kit": "^7.0|^8.5|^10.0", "orchestra/testbench-dusk": "^7.0|^8.22|^10.0", "php-coveralls/php-coveralls": "*", - "phpunit/phpunit": "8.5|^9.0|^10.5|^11.5.3", - "sebastian/phpcpd": "^5.0|^6.0" + "phpunit/phpunit": "8.5|^9.0|^10.5|^11.5.3" }, "autoload": { "psr-4": { @@ -69,6 +68,9 @@ "prefer-stable": true, "config": { "preferred-install": "dist", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": true + } } }