2017 © Pedro Peláez
 

symfony-bundle money-bundle

This bundle provides integration for Money library in your Symfony project.

image

kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  • Tuesday, March 13, 2018
  • by kucharovic
  • Repository
  • 4 Watchers
  • 6 Stars
  • 2,955 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 3 Open issues
  • 17 Versions
  • 14 % Grown

The README.md

GitHub Release Travis Total Downloads SensioLabs Insight Software License, (*1)

JKMoneyBundle

This bundle provides integration for Money library in your Symfony project. Features include:, (*2)

  • 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:, (*3)

$ composer require kucharovic/money-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*4)

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:, (*5)

<?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:, (*6)

# 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:, (*7)

+---------------------+--------------+------+-----+---------+----------------+
| 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:, (*8)

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) }

The Versions

13/03 2018

dev-master

9999999-dev https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

13/03 2018

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

13/03 2018

v1.0.9

1.0.9.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

12/03 2018

1.1.x-dev

1.1.9999999.9999999-dev https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

12/03 2018

v1.1.3

1.1.3.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

19/01 2018

v1.1.2

1.1.2.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

18/01 2018

v1.1.1

1.1.1.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

17/01 2018

v1.1.0

1.1.0.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

25/12 2017

v1.0.8

1.0.8.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

23/12 2017

v1.0.7

1.0.7.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

15/12 2017

v1.0.6

1.0.6.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

07/12 2017

v1.0.5

1.0.5.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

04/12 2017

v1.0.4

1.0.4.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

23/10 2017

v1.0.3

1.0.3.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

10/10 2017

v1.0.2

1.0.2.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

25/06 2017

v1.0.1

1.0.1.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp

25/06 2017

v1.0.0

1.0.0.0 https://github.com/kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony2 project.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakub Kucharovic

twig php bundle doctrine symfony money moneyphp