midnightluke / php-units-of-measure-bundle
Symfony 插件包装器,用于 PHP Units of Measure 库,提供有用的 doctrine 和表单类型。
v1.0.0-BETA1
2018-06-26 16:35 UTC
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-08-29 04:31:24 UTC
README
为与 PHP Units of Measure 库一起工作提供有用的 doctrine 和表单类型。
安装
使用 composer 安装此插件
composer require midnightluke/php-units-of-measure-bundle:dev-master
将其添加到您的应用程序内核 (AppKernel.php)
class AppKernel extends Kernel { // [...] public function registerBundles() { $bundles = [ // [...] new MidnightLuke\PhpUnitsOfMeasureBundle\MidnightLukePhpUnitsOfMeasureBundle(), ]; } // [...] }
在 config.yml 中添加您需要的表单类型到 doctrine
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
配置
此插件附带配置,允许您为每个度量单位的表单类型指定“默认”单位。这可以在您的 app 的 config.yml 文件中配置,如下所示
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
注意,这是可选的,否则将使用上面的默认值。
使用
此模块允许您在 Doctrine 和表单中使用原生的物理量类型。
Doctrine 使用
class Person { // [...] /** * @ORM\Column(type="length") * @var Length */ private $height; // [...] }
表单使用
$form = $this->createFormBuilder() ->add('length', LengthType::class) ->add('mass', MassType::class) ->add('save', SubmitType::class, array('label' => 'Create Post')) ->getForm();
关于
提交错误和功能请求
错误和功能请求在 GitHub 上跟踪。
作者
Luke Bainbridge - http://twitter.com/midnightLuke
许可证
PHP Units Of Measure Bundle 在 MIT 许可证下发布 - 有关详细信息,请参阅 LICENSE 文件。