Giter VIP home page Giter VIP logo

php-units-of-measure-bundle's Introduction

PHP Units Of Measure Bundle

Build Status Coverage Status

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.