- How do I install and configure the 1tomany/php-geocoder-bundle in Symfony?
- Install it with composer require 1tomany/php-geocoder-bundle. Then create config/packages/onetomany_geocoder.yaml if you need to override defaults. The transport normally uses Symfony's http_client service, and the bundle wires in serializer automatically.
- What should go in onetomany_geocoder.yaml?
- The file can define a transport block, a google block with api_key and api_version, and a mock flag. The transport block is usually omitted because the bundle defaults to Symfony's http_client service. The google block is optional; if omitted, the Google provider is not registered. The mock provider is disabled by default.
- How do I enable the mock provider for Symfony tests?
- Add a when@test section in config/packages/onetomany_geocoder.yaml with onetomany_geocoder: mock: true. This keeps the mock disabled outside the test environment. It is intended for testing, not production geocoding.
- How do I inject GeocoderClientInterface and geocode an address?
- Type-hint OneToMany\Geocoder\Contract\GeocoderClientInterface in your service constructor and let Symfony autowire it. Call geocode with Vendor::Google and a Geocode resource containing street, unit, city, zip, state, and country fields. For reverse geocoding, call reverse with Vendor::Google and a Reverse resource containing latitude and longitude.
- Does 1tomany/php-geocoder-bundle work with Laravel?
- No, this is a Symfony bundle rather than a Laravel package. It depends on Symfony service autowiring, http_client, serializer, and YAML configuration under config/packages. For Laravel, use the underlying 1tomany/php-geocoder library directly or find a Laravel-specific integration.
- Which Symfony versions are supported by this bundle?
- The provided README does not list Symfony version constraints. Check the package's composer.json for its symfony/framework-bundle and related requirements before installing. Confirm compatibility with your Symfony version in a test environment first.
- How does the bundle use Symfony http_client and serializer services?
- The transport defaults to Symfony's http_client service, so you normally do not need to configure a transport block. The bundle injects Symfony's serializer service into the transport automatically. You can still set transport.http_client in YAML if you need a custom client.
- What Google API key and API version configuration is required?
- The example configuration uses google.api_key set to %env(GOOGLE_API_KEY)% and google.api_version set to v4. The google block is optional, but omitting it means the Google provider is not registered. Keep the API key in environment variables rather than committing it to YAML.
- Can I run this bundle in production without the Google provider?
- Yes, if you omit the google block the Google provider is not registered with the GeocoderClient. The mock provider is disabled by default and is meant for test environments, not production. For real geocoding in production, configure the google block with valid credentials.
- Is this bundle actively maintained, and what are the alternatives?
- The README does not state a maintenance status or release cadence, so check the GitHub repository for recent commits and releases. As an alternative, you can use the underlying 1tomany/php-geocoder library directly or evaluate other Symfony geocoder integrations. This bundle is not a Laravel package, so Laravel projects should look elsewhere.