kucharovic/money-bundle
Composer 安装命令:
composer require kucharovic/money-bundle
包简介
This bundle provides integration for Money library in your Symfony project.
README 文档
README
JKMoneyBundle
This bundle provides integration for Money library in your Symfony project. Features include:
- Automatically add Doctrine mappings (use Doctrine embeddable objects)
- Customized FormType
- Twig extension
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require kucharovic/money-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new JK\MoneyBundle\JKMoneyBundle(), ]; // ... } // ... }
Step 3: Configuration
By default, bundle load your application locale and define it's currency code as default. You can override it:
# app/config/config.yml jk_money: currency: USD
Usage
Entity
// src/AppBundle/Entity/Proudct.php use Doctrine\ORM\Mapping as ORM; use Money\Money; // ... class Product { // ... /** * @var Money * * @ORM\Embedded(class="Money\Money") */ private $price; // ... public function __construct() { $this->price = Money::CZK(0); } public function setPrice(Money $price): void { $this->price = $price; } public function getPrice(): Money { return $this->price; }
This entity mapping produces following table structure:
+---------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| price_amount | varchar(255) | NO | | NULL | |
| price_currency_code | char(3) | NO | | NULL | |
+---------------------+--------------+------+-----+---------+----------------+
So it's easy to query database using aggregate functions like SUM, AVG, etc:
SELECT MAX(`price_amount`), `price_currency_code` FROM `product` GROUP BY `price_currency_code`;
Form
| Option | Type | Default |
|---|---|---|
| currency | string |
your application locale currency |
| grouping | boolean |
false |
| scale | integer |
2 |
// src/AppBundle/Entity/Proudct.php // ... use JK\MoneyBundle\Form\Type\MoneyType; class ProductType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->add('price', MoneyType::class) ; }
Twig templates
<!-- 1 599,90 Kč --> Formated with czech locale {{ product.price|money }}<br> <!-- 1599,9 --> You can also specify scale, grouping and hide currency symbol {{ product.price|money(1, false, false) }
kucharovic/money-bundle 适用场景与选型建议
kucharovic/money-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53.73k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2017 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「twig」 「bundle」 「money」 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kucharovic/money-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kucharovic/money-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kucharovic/money-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
The bundle for easy using json-rpc api on your project
Twig extensions for Tracy Debugger
统计信息
- 总下载量: 53.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-23