From cd5cd92be69a8b08c5f689a8cac830789fb76c28 Mon Sep 17 00:00:00 2001 From: Michelle Lewis Date: Wed, 16 Oct 2019 10:47:44 -0500 Subject: [PATCH 1/2] 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 2/2] 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