| 1 | <?php |
||
| 11 | class EnumExtension extends Twig_Extension |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var EnumRegistryInterface |
||
| 15 | */ |
||
| 16 | private $registry; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param EnumRegistryInterface $registry |
||
| 20 | */ |
||
| 21 | 2 | public function __construct(EnumRegistryInterface $registry) |
|
| 25 | |||
| 26 | /** |
||
| 27 | * {@inheritdoc} |
||
| 28 | */ |
||
| 29 | 2 | public function getFunctions() |
|
| 30 | { |
||
| 31 | return [ |
||
| 32 | 2 | new \Twig_SimpleFunction('enum_label', [ $this, 'getLabel' ]), |
|
| 33 | 2 | new \Twig_SimpleFunction('enum_choices', [ $this, 'getChoices' ]), |
|
| 34 | ]; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | 2 | public function getFilters() |
|
| 41 | { |
||
| 42 | return [ |
||
| 43 | 2 | new \Twig_SimpleFilter('enum_label', [ $this, 'getLabel' ]), |
|
| 44 | ]; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param string $value |
||
| 49 | * @param string $enum |
||
| 50 | * |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 1 | public function getLabel($value, $enum) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @param string $enum |
||
| 66 | * |
||
| 67 | * @return array |
||
| 68 | */ |
||
| 69 | 2 | public function getChoices($enum) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * {@inheritdoc} |
||
| 76 | */ |
||
| 77 | 2 | public function getName() |
|
| 81 | } |
||
| 82 |