Created
February 12, 2014 22:48
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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