phil / geo-bundle
phil/geo in Symfony: coordinates as a Doctrine embeddable, a form type, distances in Twig, and a Stimulus controller that sorts places by distance in the browser, the visitor's position never sent
Package info
github.com/parler-haut-interagir-librement/geo-bundle
Type:symfony-bundle
pkg:composer/phil/geo-bundle
Requires
- php: >=8.5
- ext-intl: *
- ext-zlib: *
- phil/geo: ^0.1@dev
- symfony/config: ^8.2
- symfony/dependency-injection: ^8.2
- symfony/form: ^8.2
- symfony/options-resolver: ^8.2
Requires (Dev)
- doctrine/dbal: ^4.5
- doctrine/doctrine-bundle: ^3.3
- doctrine/orm: ^3.7
- doctrine/persistence: ^4.1
- phpunit/phpunit: ^13.4
- psr/log: ^3.0
- symfony/console: ^8.2
- symfony/event-dispatcher: ^8.2
- symfony/framework-bundle: ^8.2
- symfony/http-client: ^8.2
- symfony/http-client-contracts: ^3.6
- symfony/http-kernel: ^8.2
- symfony/twig-bridge: ^8.2
- symfony/twig-bundle: ^8.2
- twig/twig: ^3.21
Suggests
- doctrine/orm: To embed Coordinates in an entity
- symfony/console: For phil:geo:maxmind:update
- symfony/http-client: For the geocoders, the IP locator and phil:geo:maxmind:update
- twig/twig: For geo_distance, format_distance and geo_attributes
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-11 13:30:36 UTC
README
Stored coordinates, distances in Twig, configured geocoders and nearest-first lists for Symfony applications.
phil/geo-bundle brings phil/geo into a Symfony application. It maps Coordinates as a Doctrine embeddable of two
float columns, adds CoordinatesType to enter a position as two fields, and gives Twig geo_distance(),
format_distance, geo_attributes() and geo_schema(). It registers the geocoders the configuration lists, asked in
that order and optionally cached, and an IP locator on MaxMind or ipstack. The command phil:geo:maxmind:update
downloads the latest MaxMind database, checks it and puts it in place.
It is for Symfony applications where editors enter positions and visitors look for the nearest place. The Stimulus
controller distance-sort sorts places by their distance to the visitor in the browser. The browser asks the
visitor for the position, and that position never reaches the server. The server publishes the places, blurred when
their exact position is private, and knows nothing of who is near which.
Use the bundle when the application runs on Symfony; in other PHP code, or inside a domain model, use phil/geo
directly. The Doctrine mapping needs the ORM and can be turned off with doctrine_mapping. The bundle adds no
geography of its own: each piece wraps a library type, and the browser computes the same great-circle distance as
Coordinates::distanceTo().
Status
| Part | State |
|---|---|
Coordinates as a Doctrine embeddable, optional |
Implemented and tested |
CoordinatesType: a position as two fields |
Implemented and tested |
Twig: geo_distance(), format_distance, geo_attributes(), geo_schema() |
Implemented and tested |
The Stimulus controller distance-sort |
Implemented and tested |
| Geocoders from the configuration — chained, cached — and the IP locator, MaxMind or ipstack | Implemented and tested |
phil:geo:maxmind:update: the latest MaxMind database, checked and put in place |
Implemented and tested |
Documentation
| Document | What it covers |
|---|---|
| Installation | Requirements, installing, registering, configuring, the Stimulus controller. |
| Doctrine | Embedding a position, searching near a point. |
| Forms | CoordinatesType. |
| Twig | geo_distance(), format_distance, geo_attributes(), geo_schema(). |
| Sorting by distance | The Stimulus controller, and why the position stays in the browser. |
| Geocoding | The providers of the configuration, the chain, the cache, the IP locator. |
| Extension points | What an application implements, configures, replaces or relies on. |
| Testing | How the bundle is tested, and how to run its tests. |
| Reference | Every type of the bundle. |
Quick start
composer require phil/geo-bundle
// config/bundles.php return [ // ... Phil\GeoBundle\PhilGeoBundle::class => ['all' => true], ];
<div data-controller="phil--geo-bundle--distance-sort" data-phil--geo-bundle--distance-sort-locate-value="true"> {% for store in stores %} <article {{ geo_attributes(store.position, 3) }}>{{ store.name }} <span data-distance></span></article> {% endfor %} </div>
Requirements
PHP 8.5 or later with ext-intl, and ext-zlib for phil:geo:maxmind:update; phil/geo 0.1; symfony/config, symfony/dependency-injection, symfony/form
and symfony/options-resolver 8.2 or later. Doctrine ORM and Twig are optional; the controller needs
@hotwired/stimulus 3, which the application provides.
Contributing
Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.
License
MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.