geocoder-php/plugin
Lightweight plugin system for Geocoder PHP. Add features like caching, logging, rate limiting, and more by wrapping Geocoder providers with reusable plugins. Designed to be framework-agnostic, easy to compose, and simple to integrate in any PHP app.
geocoder-php/plugin package extends the core geocoder-php library by enabling plugin-based provider support (e.g., custom geocoding services like OpenStreetMap, Google Maps, or proprietary APIs). This aligns well with Laravel’s modular architecture, where packages can be dynamically loaded and configured via service providers.GeocodeFailed, ReverseGeocodeSuccess), Laravel’s event system can be leveraged for observability, retries, or logging without tight coupling.geocoder-php, which is already PHP 8.1+ compatible and Laravel-friendly (via illuminate/support polyfills if needed). No major PHP version conflicts expected.register()/boot() methods in a custom service provider, enabling:
.env (e.g., GEOCODER_PROVIDER=plugin://custom_provider).Model::geocode()), Laravel’s Eloquent can integrate seamlessly via accessors/mutators or global scopes.geocoder-php v2.x+.cache()->remember()) to avoid rate limits.composer why-not geocoder-php/plugin).throttle middleware?Log::channel('geocoder')) or must it be wrapped?composer require geocoder-php/plugin. No runtime conflicts expected if using PHP 8.1+.// app/Providers/GeocoderPluginProvider.php
public function register()
{
$this->app->singleton(GeocoderPlugin::class, function ($app) {
return new GeocoderPlugin(config('geocoder.plugin'));
});
}
config/geocoder.php) to define plugin-specific settings:
'plugin' => [
'provider' => 'openstreetmap',
'api_key' => env('OPENSTREETMAP_API_KEY'),
'timeout' => 10,
],
Geocoder::plugin('openstreetmap')->geocode($address)) for cleaner syntax.Phase 1: Proof of Concept
geocoder-php and geocoder-php/plugin.GeocodedModel::withCoordinates()).Phase 2: Service Provider Integration
php artisan vendor:publish..env):
GEOCODER_PLUGIN_PROVIDER=google
GOOGLE_MAPS_API_KEY=your_key
Phase 3: Eloquent Integration
// app/Models/Geocodable.php
trait Geocodable
{
public function getCoordinatesAttribute()
{
return app(GeocoderPlugin::class)->geocode($this->address)->first();
}
}
Phase 4: Fallback & Caching
cache()->remember() to reduce API calls.geocoder-php v2.x+ (check composer.json constraints).| Step | Task | Dependencies |
|---|---|---|
| 1 | Install package | composer require geocoder-php/plugin |
| 2 | Configure .env |
Provider API keys |
| 3 | Publish config | php artisan vendor:publish |
| 4 | Register service provider | config/app.php |
| 5 | Test basic geocoding | Tinker/Postman |
| 6 | Integrate with Eloquent | Global scopes/accessors |
| 7 | Add caching | Laravel Cache |
| 8 | Implement fallbacks | Multi-provider logic |
| 9 | Add monitoring | Laravel Logs/Prometheus |
geocoder-php and plugin updates for breaking changes. Use composer why-not to track dependencies.config/ to avoid hardcoding. Use env() for secrets.Log::channel('geocoder')->info('Geocoded', ['address' => $address, 'provider' => $provider]);
try-catch and map exceptions to Laravel’s HttpException or custom errors:
try {
$result = $plugin->geocode($address);
} catch (GeocoderPluginException $e) {
throw new HttpResponseException(response()->json(['error' => 'Geocoding failed'], 424));
}
Geocoder::plugin('google')->geocode($address)->later(); // Dispatch to queue
redis (TTL: 1 hour).coordinates column in users table).| Failure Scenario | Mitigation |
|---|---|
| Provider API Down | Implement fallback providers (e.g., OpenStreetMap). |
| Rate Limit Exceeded | Use Laravel Queues + exponential backoff. |
| Malformed API Response | Validate responses with Laravel’s Validator. |
| Plugin Bug | Feature flags to disable problematic providers. |
How can I help you explore Laravel packages today?