@@ -53,14 +53,10 @@ public function register()
5353 $ this ->app ->singleton ('geocoder.chain ' , function ($ app ) {
5454 $ providers = collect (config ('geocoder.providers ' ))
5555 ->map (function ($ arguments , $ provider ) {
56+ $ arguments = $ this ->prepArguments ($ arguments , $ provider );
5657 $ reflection = new ReflectionClass ($ provider );
5758
58- if (is_array ($ arguments )) {
59- array_unshift ($ arguments , $ this ->app ['geocoder.adapter ' ]);
60- return $ reflection ->newInstanceArgs ($ arguments );
61- }
62-
63- return $ reflection ->newInstance ($ this ->app ['geocoder.adapter ' ]);
59+ return $ reflection ->newInstanceArgs ($ arguments );
6460 });
6561
6662 return new Chain ($ providers ->toArray ());
@@ -74,6 +70,60 @@ public function register()
7470 });
7571 }
7672
73+ private function prepArguments (array $ arguments , $ provider )
74+ {
75+ $ specificAdapter = $ this ->providerRequiresSpecificAdapter ($ provider );
76+
77+ if ($ specificAdapter ) {
78+ array_unshift ($ arguments , $ specificAdapter );
79+
80+ return $ arguments ;
81+ }
82+
83+ if ($ this ->providerRequiresAdapter ($ provider )) {
84+ array_unshift ($ arguments , $ this ->app ['geocoder.adapter ' ]);
85+
86+ return $ arguments ;
87+ }
88+
89+ return $ arguments ;
90+ }
91+
92+ private function providerRequiresSpecificAdapter ($ provider )
93+ {
94+ $ specificAdapters = collect ([
95+ 'Geocoder\Provider\GeoIP2 ' => 'Geocoder\Adapter\GeoIP2Adapter ' ,
96+ ]);
97+
98+ return $ specificAdapters ->get ($ provider );
99+ }
100+
101+ private function providerRequiresAdapter ($ provider )
102+ {
103+ $ providersRequiringAdapter = collect ([
104+ 'Geocoder\Provider\ArcGISOnline ' ,
105+ 'Geocoder\Provider\BingMaps ' ,
106+ 'Geocoder\Provider\FreeGeoIp ' ,
107+ 'Geocoder\Provider\GeoIPs ' ,
108+ 'Geocoder\Provider\Geonames ' ,
109+ 'Geocoder\Provider\GeoPlugin ' ,
110+ 'Geocoder\Provider\GoogleMaps ' ,
111+ 'Geocoder\Provider\GoogleMapsBusiness ' ,
112+ 'Geocoder\Provider\HostIp ' ,
113+ 'Geocoder\Provider\IpInfoDb ' ,
114+ 'Geocoder\Provider\MapQuest ' ,
115+ 'Geocoder\Provider\MaxMind ' ,
116+ 'Geocoder\Provider\Nominatim ' ,
117+ 'Geocoder\Provider\OpenCage ' ,
118+ 'Geocoder\Provider\OpenStreetMap ' ,
119+ 'Geocoder\Provider\Provider ' ,
120+ 'Geocoder\Provider\TomTom ' ,
121+ 'Geocoder\Provider\Yandex ' ,
122+ ]);
123+
124+ return $ providersRequiringAdapter ->contains ($ provider );
125+ }
126+
77127 /**
78128 * Get the services provided by the provider.
79129 *
0 commit comments