<?php

/*
 * This file is part of the VitiCore 2.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Util;

class Slugifier
{
    private $symbolMap = [
        ' ' => '-',
        '_' => '-',
    ];

    /**
     * @var \Transliterator
     */
    private $transliterator;

    public function __construct()
    {
        $this->transliterator = \Transliterator::createFromRules("::Latin-ASCII; ::Lower; [^[:L:]]+ > '-';");
    }

    public function __invoke($source): string
    {
        return mb_trim(strtr($this->transliterator->transliterate($source), $this->symbolMap), '-');
    }
}
