for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yokai\EnumBundle\Twig\Extension;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
use Yokai\EnumBundle\Registry\EnumRegistryInterface;
/**
* @author Yann Eugoné <[email protected]>
*/
class EnumExtension extends Twig_Extension
{
* @var EnumRegistryInterface
private $registry;
* @param EnumRegistryInterface $registry
public function __construct(EnumRegistryInterface $registry)
$this->registry = $registry;
}
* @inheritdoc
public function getFunctions()
return [
new Twig_SimpleFunction('enum_label', [ $this, 'getLabel' ]),
new Twig_SimpleFunction('enum_choices', [ $this, 'getChoices' ]),
];
public function getFilters()
new Twig_SimpleFilter('enum_label', [ $this, 'getLabel' ]),
* @param string $value
* @param string $enum
*
* @return string
public function getLabel($value, $enum)
$choices = $this->getChoices($enum);
if (isset($choices[$value])) {
return $choices[$value];
return $value;
* @return array
public function getChoices($enum)
return $this->registry->get($enum)->getChoices();
public function getName()
return 'enum';