<?php

declare(strict_types=1);

namespace ProudNerds\Helpers;
use Twig\TwigFunction;

class TwigExtension
{
    public function __construct() {
        $this->add_filters();
    }

    private function add_filters(){
        add_filter( 'timber/twig', [$this, 'add_to_twig'] );

    }

    public function add_to_twig($twig){
        $twig->addFunction(new TwigFunction('dump', [$this, 'varDump']) );
        return $twig;
    }

    public function varDump()
    {
        $dumpFunc = function_exists('dump') ? 'dump' : 'var_dump';
        $dumpFunc(...func_get_args());
    }

}
