<?php

namespace DZunke\FeatureFlagsBundle\Twig;

use DZunke\FeatureFlagsBundle\Toggle;

class FeatureExtension extends \Twig_Extension
{

    /**
     * @var Toggle
     */
    protected $toggle;

    /**
     * @param Toggle $toggle
     */
    public function __construct(Toggle $toggle)
    {
        $this->toggle = $toggle;
    }

    public function getFunctions()
    {
        return [
            new \Twig_SimpleFunction('has_feature', [$this, 'checkFeature'], ['is_safe' => ['html']]),
        ];
    }

    /**
     * @param string $name
     * @param array  $arguments
     * @return bool
     */
    public function checkFeature($name, $arguments = null)
    {
        return $this->toggle->isActive($name, $arguments);
    }

    public function getName()
    {
        return 'd_zunke_feature_extension';
    }
}

<?php

namespace DZunke\FeatureFlagsBundle\Twig;

use DZunke\FeatureFlagsBundle\Toggle;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class FeatureExtension extends AbstractExtension
{

    /**
     * @var Toggle
     */
    protected $toggle;

    /**
     * @param Toggle $toggle
     */
    public function __construct(Toggle $toggle)
    {
        $this->toggle = $toggle;
    }

    public function getFunctions()
    {
        return [
            new TwigFunction('has_feature', [$this, 'checkFeature'], ['is_safe' => ['html']]),
        ];
    }

    /**
     * @param string $name
     * @param array  $arguments
     * @return bool
     */
    public function checkFeature($name, $arguments = null)
    {
        return $this->toggle->isActive($name, $arguments);
    }

    public function getName()
    {
        return 'd_zunke_feature_extension';
    }
}

Replace Twig global namespaces to support Twig 3
Replace Twig global namespaces to support Twig 3

Use of the globally namespaced Twig functions was deprecated in Twig 2.x and removed in Twig 3.x.

This commit simply replaces the globally namespaced functions with their namespaced equivalents.