<?php

namespace Dough\Twig;

use Dough\Bank\BankInterface;
use Dough\Money\MoneyInterface;

class DoughExtension extends \Twig_Extension
{
    private $bank;

    public function __construct(BankInterface $bank = null)
    {
        $this->bank = $bank;
    }

    public function getFunctions()
    {
        return array(
            'dough_currency' => new \Twig_Function_Method($this, 'renderCurrency'),
        );
    }



    public function renderCurrency(MoneyInterface $money)
    {
        $reduced = $money->reduce($this->bank);

        return number_format($reduced->getAmount(), 2);
    }

    public function getName()
    {
        return 'merk_dough';
    }
}

<?php

namespace Dough\Twig;

use Dough\Bank\BankInterface;
use Dough\Money\MoneyInterface;

class DoughExtension extends \Twig_Extension
{
    private $bank;

    public function __construct(BankInterface $bank = null)
    {
        $this->bank = $bank;
    }

    public function getFilters()
    {
        return array(
            'dough_currency' => new \Twig_Filter_Method($this, 'getAmount', array('is_safe' => array('html'))),
        );
    }

    public function getAmount(MoneyInterface $money, $currency = null)
    {
        $reduced = $this->bank->reduce($money, $currency);

        return $reduced->getAmount();
    }

    public function getName()
    {
        return 'merk_dough';
    }
}

Make dough_currency as twig filter instead of the function.
Make dough_currency as twig filter instead of the function.

And the filter returns a raw value of the Money instead of
formatted string. This allows use chain filters.
