midnightluke / php-units-of-measure-bundle
Symfony bundle wrapper for the PHP Units of Measure library with useful doctrine and form types.
Installs: 1 157
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 3
Open Issues: 4
Type:symfony-bundle
Requires
- php: ^5.5.9 || ^7.0
- doctrine/dbal: ^2.5
- php-units-of-measure/php-units-of-measure: ^2.1
- symfony/form: ^2.7 || ^3.0 || ^4.0
- symfony/framework-bundle: ^2.7 || ^3.0 || ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ^5.7
- satooshi/php-coveralls: ^1.0
This package is auto-updated.
Last update: 2024-11-29 05:20:39 UTC
README
Provides useful Doctrine and Form types for working with the PHP Units of Measure Library.
Installation
Install this bundle using composer:
composer require midnightluke/php-units-of-measure-bundle:dev-master
Add it to your application kernel (AppKernel.php):
class AppKernel extends Kernel { // [...] public function registerBundles() { $bundles = [ // [...] new MidnightLuke\PhpUnitsOfMeasureBundle\MidnightLukePhpUnitsOfMeasureBundle(), ]; } // [...] }
Add the form types you need to doctrine in config.yml:
doctrine: dbal: types: acceleration: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\AccelerationType angle: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\AngleType area: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\AreaType electric_current: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\ElectricCurrentType energy: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\EnergyType length: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\LengthType luminous_intensity: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\LuminousIntensityType mass: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\MassType pressure: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\PressureType quantity: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\QuantityType solid_angle: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\SolidAngleType temperature: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\TemperatureType uom_time: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\TimeType velocity: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\VelocityType volume: MidnightLuke\PhpUnitsOfMeasureBundle\Doctrine\Types\VolumeType
Configuration
This bundle comes with configuration that allows you to specify the "default" unit for each unit of measure form type. This can be configured in your app's config.yml file like so:
units_of_measure: base_units: acceleration: m/s^2 angle: rad area: m^2 electric_current: A energy: J length: m luminous_intensity: cd mass: kg pressure: Pa quantity: mol solid_angle: sr temperature: K uom_time: s velocity: m/s volume: m^3
Note that this is optional and the defaults above will be used otherwise.
Use
This module allows you to use native PhysicalQuantity types in Doctrine and on forms.
Doctrine Use
class Person { // [...] /** * @ORM\Column(type="length") * @var Length */ private $height; // [...] }
Form Use
$form = $this->createFormBuilder() ->add('length', LengthType::class) ->add('mass', MassType::class) ->add('save', SubmitType::class, array('label' => 'Create Post')) ->getForm();
About
Submitting bugs and feature requests
Bugs and feature request are tracked on GitHub.
Author
Luke Bainbridge - http://twitter.com/midnightLuke
License
PHP Units Of Measure Bundle is licensed under the MIT License - see the LICENSE file for details.