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