<?php


namespace AutoAdmin\Bundle\Core\Twig;


use Cocur\Slugify\SlugifyInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class SluggerExtension extends AbstractExtension
{
    private SlugifyInterface $slugger;

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

    /**
     * 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";
    }
}