<?php
namespace TwigExtension;

use Psr\Container\ContainerInterface;
use Skeleton\Router;

class SpecifiqueExtension extends \Twig\Extension\AbstractExtension
{

    private $router;
    private $contenaire;
    private $pdo;
    
    
    public function __construct(Router $router, ContainerInterface $contenaire, \PDO $pdo)
    {
        $this->router = $router;
        $this->contenaire = $contenaire;
        $this->pdo = $pdo;
    }

    /**
     *
     */





    public function getFilters()
    {
        return array(

            'specifiqueScript' => new \Twig\TwigFilter('specifiqueScript', array($this, 'specifiqueScript')),
        );
    }

   
    public function getFunctions()
    {
        return [
            new \Twig\TwigFunction(
                'specifique',
                [
                $this,
                'specifique'
                ],
                [
                'is_safe' => [
                    'html'
                ]
                ]
            ),
        ];
    }
    
   
    public function specifiqueScript($array)
    {
        $specifique = new \Helpers\Additional\Specifique\Specifique();
        return $specifique->getSpecifiqueScript($this->router->getNameRoute());
    }


    public function specifique($class, $function, $array = [])
    {
        $namespace = "Modules\\Additional\\Specifique\\Client".(int)$_SESSION['Session_NumClient']."\\Html\\".$class;

        if (class_exists($namespace)) {
            $class = new $namespace($this->router, $this->contenaire, $this->pdo);
            if (method_exists($class, $function)) {
                return $class->$function($array);
            }
        }
    }
}
