<?php
namespace TwigExtension;

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

class SpecifiqueExtension extends \Twig\Extension\AbstractExtension
{

    private Router $router;
    private ContainerInterface $contenaire;
    private \PDO $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'
                ]
                ]
            ),
        ];
    }
    
    /**
     * @param array<mixed> $array
     * @return array<mixed>
     */
    public function specifiqueScript($array)
    {
        $specifique = new \Helpers\Additional\Specifique\Specifique();
        return $specifique->getSpecifiqueScript($this->router->getNameRoute());
    }

    /**
     * @param string $class
     * @param string $function
     * @param array<mixed> $array
     * @return mixed
     */
    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);
            }
        }
    }
}
