### Install BazingaGeocoderBundle Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Install the bundle using Composer. This command adds the bundle as a dependency to your project. ```bash composer require willdurand/geocoder-bundle:^5.0 ``` -------------------------------- ### Install and Test BazingaGeocoderBundle Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Instructions for setting up the test suite for BazingaGeocoderBundle using Composer. ```bash composer update composer test ``` -------------------------------- ### Install CacheProvider Package Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md Install the CacheProvider package using Composer to utilize the Decorator pattern for caching geocoder responses. ```bash composer require geocoder-php/cache-provider ``` -------------------------------- ### Install Guzzle HTTP Client Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Install Guzzle and the HTTP factory for Guzzle to use it as a custom HTTP client with the geocoder. ```bash composer require guzzlehttp/guzzle http-interop/http-factory-guzzle ``` -------------------------------- ### Configure a Google Maps Provider Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure a specific provider using its factory. This example shows how to set up the Google Maps provider. ```yaml bazinga_geocoder: providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory ``` -------------------------------- ### Configure Provider with Options Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure a provider with specific options, such as an HTTP client, region, and API key. This example demonstrates options for the Google Maps provider. ```yaml bazinga_geocoder: providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory options: http_client: '@any.psr18.client' region: 'Sweden' api_key: 'xxyy' ``` -------------------------------- ### Configure Provider with Cache and Aliases Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure a provider with caching enabled and an alias for easier referencing. This example sets a cache lifetime of one hour. ```yaml bazinga_geocoder: providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory cache: 'any.psr16.service' cache_lifetime: 3600 aliases: - my_geocoder ``` -------------------------------- ### Install PSR-6 to PSR-16 Cache Bridge Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md Install the cache bridge package using Composer to enable compatibility between PSR-6 and PSR-16 cache implementations. ```bash composer require cache/simple-cache-bridge ``` -------------------------------- ### Geocoder Configuration: After Version 5.0.0 Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/CHANGELOG.md Demonstrates the updated provider configuration format for BazingaGeocoderBundle starting from version 5.0.0, utilizing provider factories. ```yaml bazinga_geocoder: providers: acme: factory: "Bazinga\GeocoderBundle\ProviderFactory\BingMapsFactory" locale: 'sv' options: api_key: "foo" ``` -------------------------------- ### GeoJson Dumper Usage with Autowiring Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Use the GeoJson dumper to output geocoded data in GeoJSON format. This example demonstrates autowiring for the geocoder provider and the dumper service. ```php acmeGeocoder = $acmeGeocoder; $this->geoJsonDumper = $dumper; } public function geocodeAction(Request $request) { $result = $this->acmeGeocoder->geocodeQuery(GeocodeQuery::create($request->server->get('REMOTE_ADDR'))); $body = $this->geoJsonDumper->dump($result); return new JsonResponse($body); } } ``` -------------------------------- ### Annotating User Entity for Geocoding Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/doctrine.md Annotate your entity properties with Geocoder attributes to specify which fields represent the address, latitude, and longitude. This example uses property annotations. ```php use Bazinga\GeocoderBundle\Mapping\Attributes as Geocoder; #[Geocoder\Geocodeable(provider: 'acme')] class User { #[Geocoder\Address()] private $address; #[Geocoder\Latitude()] private $latitude; #[Geocoder\Longitude()] private $longitude; } ``` -------------------------------- ### Custom Provider Factory (PHP) Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/custom-provider.md Create a custom factory to integrate your provider with the web profiler. This factory extends AbstractFactory and defines how to instantiate your custom provider. ```php namespace Acme\Demo\Geocoder\Factory; use Bazinga\GeocoderBundle\ProviderFactory\AbstractFactory; use Acme\Demo\Geocoder\Provider\MyProvider; use Acme\Demo\Service\Foo; final class MyFactory extends AbstractFactory { private $fooService; public function __construct(Foo $service) { $this->someService = $service; } protected function getProvider(array $config) { return new MyProvider($this->fooService); } } ``` -------------------------------- ### Configure Built-in Plugins Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/plugins.md Configure built-in plugins like FakeIpPlugin, CachePlugin, LimitPlugin, LocalePlugin, and LoggerPlugin directly within the BazingaGeocoderBundle configuration. ```yaml bazinga_geocoder: fake_ip: ip: '123.123.123.123' # Uses the FakeIpPlugin providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory cache: 'app.cache' # Uses the CachePlugin limit: 5 # Uses the LimitPlugin locale: 'sv' # Uses the LocalePlugin logger: 'logger' # Uses the LoggerPlugin ``` -------------------------------- ### Configure CacheProvider with Decorator Pattern Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md This configuration sets up the 'acme' provider using GoogleMapsFactory, preparing it to be wrapped by the CacheProvider. ```yaml bazinga_geocoder: providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory ``` -------------------------------- ### Reference Configuration for BazingaGeocoderBundle Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md A comprehensive reference for configuring all aspects of the BazingaGeocoderBundle, including profiling, fake IP, and individual provider settings. ```yaml # config/packages/bazinga_geocoder.yaml bazinga_geocoder: profiling: enabled: ~ # Default is same as kernel.debug fake_ip: enabled: true ip: null providers: # ... acme: factory: ~ # Required cache: 'app.cache' cache_lifetime: 3600 cache_precision: 4 # Precision of the coordinates to cache. limit: 5 locale: 'sv' logger: 'logger' plugins: - my_custom_plugin aliases: - acme - acme_geocoder options: foo: bar biz: baz # ... free_chain: aliases: - free_geo_chain factory: Bazinga\GeocoderBundle\ProviderFactory\ChainFactory options: services: ['@acme', '@acme_ii'] ``` -------------------------------- ### Configure Custom Provider Factory (YAML) Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/custom-provider.md Configure your custom provider factory in the bundle's configuration. This links the factory to your provider and its aliases. ```yaml bazinga_geocoder: providers: acme: factory: Acme\Demo\Geocoder\Factory\MyFactory aliases: ['acme_demo.geocoder.my_provider'] ``` -------------------------------- ### Register Custom Provider Service (XML) Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/custom-provider.md Register a custom provider as a service and tag it for automatic discovery by the bundle. ```xml ``` -------------------------------- ### Fake Local IP with Custom Local IP Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure a fake IP address and specify a custom local IP address for development environments. This is useful when 'localhost' is not '127.0.0.1'. ```yaml when@dev: bazinga_geocoder: fake_ip: local_ip: 192.168.99.1 # default 127.0.0.1 ip: 123.123.123.123 ``` -------------------------------- ### Configure BazingaGeocoderBundle with Symfony Cache Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md Configure the 'my_google_maps' provider to use the 'app.simple_cache' service for caching with a lifetime of 3600 seconds and a precision of 4 decimal places. ```yaml bazinga_geocoder: providers: my_google_maps: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory cache: 'app.simple_cache' cache_lifetime: 3600 cache_precision: 4 ``` -------------------------------- ### Fake Local IP Configuration Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure a fake IP address for development environments to simulate location data. This replaces '127.0.0.1' in queries. ```yaml when@dev: bazinga_geocoder: fake_ip: 123.123.123.123 ``` -------------------------------- ### Geocoder Configuration: Before Version 5.0.0 Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/CHANGELOG.md Illustrates the provider configuration format used in BazingaGeocoderBundle prior to version 5.0.0. ```yaml bazinga_geocoder: providers: bing_maps: api_key: "Foo" locale: 'sv' ``` -------------------------------- ### Configure Symfony Cache Adapter Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md Configure a Redis adapter for the application cache pool named 'app.cache.acme' with a default lifetime of 600 seconds. ```yaml framework: cache: app: cache.adapter.redis pools: app.cache.acme: adapter: cache.app default_lifetime: 600 ``` -------------------------------- ### Configure Chain Providers Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure multiple providers to be used in a chain. This allows requests to be passed through different provider factories. ```yaml bazinga_geocoder: providers: acme: aliases: - my_geocoder cache: 'any.psr16.service' cache_lifetime: 3600 factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory options: api_key: 'xxxx' acme_ii: aliases: - my_geocoder_ii factory: Bazinga\GeocoderBundle\ProviderFactory\TomTomFactory options: api_key: 'xxyy' http_client: '@any.psr18.client' region: 'Sweden' chain: factory: Bazinga\GeocoderBundle\ProviderFactory\ChainFactory options: services: ['@bazinga_geocoder.provider.acme', '@bazinga_geocoder.provider.acme_ii'] ``` -------------------------------- ### Enable Custom Plugin in BazingaGeocoderBundle Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/plugins.md Enable a custom plugin, such as the registered QueryDataPlugin, for a specific provider within the BazingaGeocoderBundle configuration. ```yaml bazinga_geocoder: providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory plugins: - 'app.query_data_plugin' ``` -------------------------------- ### Fake Local IP using Faker Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Enable the use of the Faker library to generate fake IP addresses for development environments. This provides dynamic fake IP generation. ```yaml when@dev: bazinga_geocoder: fake_ip: use_faker: true # default false ``` -------------------------------- ### Using Doctrine ORM Integration Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/doctrine.md After configuration, you can persist user entities with addresses, and the bundle will automatically geocode them. The latitude and longitude will be populated upon flushing the entity manager. ```php $user = new User(); $user->setAddress('Brandenburger Tor, Pariser Platz, Berlin'); $em->persist($user); $em->flush(); echo $user->getLatitude(); // will output 52.516325 echo $user->getLongitude(); // will output 13.377264 ``` -------------------------------- ### Configure CachePlugin in BazingaGeocoderBundle Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md This configuration enables the CachePlugin for the 'acme' provider, specifying a PSR16 cache service, a lifetime of 3600 seconds, and no specific cache precision. ```yaml bazinga_geocoder: providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory cache: 'any.psr16.service' cache_lifetime: 3600 cache_precision: ~ ``` -------------------------------- ### Annotating User Entity with Getter for Address Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/doctrine.md Alternatively, you can annotate a getter method for the address field. This provides flexibility in how your address data is accessed. ```php use Bazinga\GeocoderBundle\Mapping\Attributes as Geocoder; #[Geocoder\Geocodeable(provider: 'acme')] class User { #[Geocoder\Latitude()] private $latitude; #[Geocoder\Longitude()] private $longitude; #[Geocoder\Address()] public function getAddress(): \Stringable|string { // Your code... } } ``` -------------------------------- ### Autowiring Providers in Symfony Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure a provider for autowiring. This allows you to inject the provider directly into your services. ```yaml bazinga_geocoder: providers: googleMaps: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory ``` -------------------------------- ### Register Custom QueryDataPlugin Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/plugins.md Register a custom QueryDataPlugin as a service in services.yaml to add specific data to each geocoding query. ```yaml services: app.query_data_plugin: class: Geocoder\Plugin\Plugin\QueryDataPlugin arguments: - ['foo': 'bar'] - true ``` -------------------------------- ### Assign Custom HTTP Client to Provider Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure a specific geocoder provider to use the custom HTTP client defined in services. ```yaml bazinga_geocoder: providers: acme: factory: ... options: http_client: '@guzzle.client' ``` -------------------------------- ### Enable BazingaGeocoderBundle in Symfony Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Manually enable the bundle in your Symfony application's configuration. This is required if you are not using Symfony Flex. ```php // config/bundles.php // in older Symfony apps, enable the bundle in app/AppKernel.php return [ // ... Bazinga\GeocoderBundle\BazingaGeocoderBundle::class => ['all' => true], ]; ``` -------------------------------- ### Enabling Doctrine ORM Listener Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/doctrine.md Enable the Doctrine ORM listener in your application's configuration to activate the automatic geocoding functionality. This is a required step for integration. ```yaml bazinga_geocoder: orm: enabled: true ``` -------------------------------- ### Configure Guzzle HTTP Client in Symfony Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure Symfony services to use Guzzle as the HTTP client for the geocoder. ```yaml services: guzzle.client: class: GuzzleHttp\Client ``` -------------------------------- ### Provider Cache Configuration Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Configure caching for geocoder provider results using a PSR-16 compatible cache service. Specify the cache service name and lifetime. ```yaml bazinga_geocoder: providers: acme: factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory cache: 'any.psr16.service' cache_lifetime: 3600 ``` -------------------------------- ### Define Cached Geocoder Service Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md Define a service for a cached geocoder using the ProviderCache, linking it to the 'bazinga_geocoder.provider.acme' service, a PSR16 cache service, and a lifetime of 3600 seconds. ```yaml services: my_cached_geocoder: class: Geocoder\Provider\Cache\ProviderCache arguments: ['@bazinga_geocoder.provider.acme', '@any.psr16.service', 3600] ``` -------------------------------- ### Register Symfony Cache Service Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/cache.md Register a Symfony cache service using the Psr6Cache adapter, which bridges to a PSR-6 cache service. ```yaml app.simple_cache: class: Symfony\Component\Cache\Simple\Psr6Cache arguments: ['@app.cache.acme'] ``` -------------------------------- ### Injecting Autowired Provider in a Service Source: https://github.com/geocoder-php/bazingageocoderbundle/blob/master/doc/index.md Inject an autowired provider into a Symfony service. The provider is injected based on its configured name and the 'Geocoder' suffix. ```php googleMapsGeocoder = $googleMapsGeocoder; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.