phil / measurement-bundle
Units of measure in Symfony: form types, validation constraints, a Doctrine column and Twig formatting, on top of phil/measurement.
Package info
github.com/parler-haut-interagir-librement/measurement-bundle
Type:symfony-bundle
pkg:composer/phil/measurement-bundle
Requires
- php: >=8.5
- ext-intl: *
- ext-mbstring: *
- phil/measurement: ^0.1@dev
- symfony/config: ^8.2
- symfony/dependency-injection: ^8.2
- symfony/form: ^8.2
- symfony/options-resolver: ^8.2
- symfony/validator: ^8.2
Requires (Dev)
- doctrine/dbal: ^4.6
- doctrine/doctrine-bundle: ^3.4
- doctrine/orm: ^3.8
- doctrine/persistence: ^4.2
- phpunit/phpunit: ^13.4
- psr/log: ^3.0
- symfony/event-dispatcher: ^8.2
- symfony/framework-bundle: ^8.2
- symfony/http-kernel: ^8.2
- symfony/translation: ^8.2
- symfony/twig-bridge: ^8.2
- symfony/twig-bundle: ^8.2
- twig/twig: ^3.31.1
Suggests
- doctrine/dbal: For the phil_measurement column type
- twig/twig: For the format_measurement, measurement_in_channel and preferred_units filters
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-28 03:39:23 UTC
README
Weights and sizes in Symfony forms, validation, Twig and Doctrine, as exact decimals with their units, per sales channel, written in each locale.
phil/measurement-bundle integrates phil/measurement with Symfony: the registry of units with the application's own,
the unit of each sales channel, a form type that reads a value and a unit in the request's locale, constraints that
bound a measurement in any unit of its family, Twig filters that write it in the locale or in the unit a region
prefers, and a Doctrine column type that stores it without a float. The library alone suits an application without
Symfony.
#[ORM\Column(type: 'phil_measurement')] #[MeasurementRange(min: '0 kg', max: '30 kg')] #[MeasurementUnit(family: 'mass')] public ?Measurement $weight = null; $builder->add('weight', MeasurementType::class, ['family' => 'mass', 'channel' => 'storefront']);
{{ product.weight|format_measurement('long') }} {# 12,5 kilogrammes #}
{{ person.height|preferred_units('person-height')|format_measurement }}
Status
| Part | State |
|---|---|
PhilMeasurementBundle and its configuration phil_measurement: units added, unit of each channel |
Implemented and tested |
MeasurementType, the form type of a value and a unit |
Implemented and tested |
MeasurementRange and MeasurementUnit, the constraints |
Implemented and tested |
format_measurement, measurement_in_channel and preferred_units, the Twig filters |
Implemented and tested |
phil_measurement, the Doctrine column type |
Implemented and tested on SQLite; tests for MySQL and PostgreSQL run when their servers are given |
Documentation
| Document | What it covers |
|---|---|
| Installation | Requirements and installing. |
| Configuration | Every option, with an example. |
| Forms | MeasurementType, its options and how it reads a value. |
| Validation | MeasurementRange and MeasurementUnit. |
| Twig | The filters that write and convert a measurement. |
| Doctrine | The phil_measurement column type, and two columns to sort or sum in SQL. |
| Extension points | The services to replace, the tags to add to, and when they are stable. |
| Testing | The bundle's tests, and the servers its integration tests read. |
| Reference | Every class and service of the bundle. |
Quick start
// config/bundles.php Phil\MeasurementBundle\PhilMeasurementBundle::class => ['all' => true],
# config/packages/phil_measurement.yaml phil_measurement: channels: storefront: { mass: kg, length: cm } marketplace: { mass: '[lb_av]', length: '[in_i]' }
Requirements
PHP 8.5 or later with the intl extension, and Symfony 8.2 or later. Doctrine DBAL 4 for the column type, Twig 3 for
the filters.
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.