<?php


namespace AutoAdmin\Bundle\Core\Twig;


use AutoAdmin\Bundle\Core\Slugger\Slugger;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class SluggerExtension extends AbstractExtension
{
    private Slugger $slugger;

    public function __construct(Slugger $slugger)
    {
        $this->slugger = $slugger;
    }

    /**
     * Returns the Twig functions of this extension.
     *
     * @return TwigFilter[]
     */
    public function getFilters(): array
    {
        return [
            new TwigFilter('slugify', [$this, 'slugifyFilter']),
        ];
    }

    public function slugifyFilter(string $string, string $separator = null): string
    {
        return $this->slugger->slugify($string, $separator);
    }

    public function getName(): string
    {
        return "SlugifyExtension";
    }
}