Search by

phil / measurement-bundle

phil

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

Homepage

Type:symfony-bundle

pkg:composer/phil/measurement-bundle

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0-alpha 2026-11-27 22:00 UTC

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.