Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created February 12, 2014 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/8966134 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/8966134 to your computer and use it in GitHub Desktop.
The solution that should have been arrived at in this blog post: http://danielribeiro.org/solid-principles-violations-on-symfonys-cookbook-custom-twig-extension/
<?php
interface MoneyFormatter
{
public function format($value, $decimals=0, $decimalPoint='.', $thousandsSep=',');
}
class FormatterExtension extends \Twig_Extension
{
private $formatter;
private $filterName;
public function __construct(MoneyFormatter $formater, $filterName)
{
$this->formatter = $formatter;
$this->filterName = $filterName;
}
public function getFilters()
{
return array(
new \Twig_SimpleFilter($this->filterName, array($this->formatter, 'format')),
);
}
public function getName()
{
return "{$this->filterName}_formatter_extension";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment