Deprecated: Constant E_STRICT is deprecated in /var/www/PixelForce/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /var/www/PixelForce/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/cocur/slugify/src/Slugify.php line 82

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of cocur/slugify.
  4.  *
  5.  * (c) Florian Eckerstorfer <florian@eckerstorfer.co>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Cocur\Slugify;
  11. use Cocur\Slugify\RuleProvider\DefaultRuleProvider;
  12. use Cocur\Slugify\RuleProvider\RuleProviderInterface;
  13. /**
  14.  * Slugify
  15.  *
  16.  * @package   Cocur\Slugify
  17.  * @author    Florian Eckerstorfer <florian@eckerstorfer.co>
  18.  * @author    Ivo Bathke <ivo.bathke@gmail.com>
  19.  * @author    Marchenko Alexandr
  20.  * @copyright 2012-2015 Florian Eckerstorfer
  21.  * @license   http://www.opensource.org/licenses/MIT The MIT License
  22.  */
  23. class Slugify implements SlugifyInterface
  24. {
  25.     public const LOWERCASE_NUMBERS_DASHES '/[^A-Za-z0-9]+/';
  26.     /**
  27.      * @var array<string,string>
  28.      */
  29.     protected array $rules = [];
  30.     /**
  31.      * @var RuleProviderInterface
  32.      */
  33.     protected RuleProviderInterface $provider;
  34.     /**
  35.      * @var array<string,mixed>
  36.      */
  37.     protected array $options = [
  38.         'regexp'    => self::LOWERCASE_NUMBERS_DASHES,
  39.         'separator' => '-',
  40.         'lowercase' => true,
  41.         'lowercase_after_regexp' => false,
  42.         'trim' => true,
  43.         'strip_tags' => false,
  44.         'rulesets'  => [
  45.             'default',
  46.             // Languages are preferred if they appear later, list is ordered by number of
  47.             // websites in that language
  48.             // https://en.wikipedia.org/wiki/Languages_used_on_the_Internet#Content_languages_for_websites
  49.             'armenian',
  50.             'azerbaijani',
  51.             'burmese',
  52.             'hindi',
  53.             'georgian',
  54.             'norwegian',
  55.             'vietnamese',
  56.             'ukrainian',
  57.             'latvian',
  58.             'finnish',
  59.             'greek',
  60.             'czech',
  61.             'arabic',
  62.             'slovak',
  63.             'turkish',
  64.             'polish',
  65.             'german',
  66.             'russian',
  67.             'romanian'
  68.         ],
  69.     ];
  70.     /**
  71.      * @param array                 $options
  72.      * @param RuleProviderInterface $provider
  73.      */
  74.     public function __construct(array $options = [], RuleProviderInterface $provider null)
  75.     {
  76.         $this->options  array_merge($this->options$options);
  77.         $this->provider $provider $provider : new DefaultRuleProvider();
  78.         foreach ($this->options['rulesets'] as $ruleSet) {
  79.             $this->activateRuleSet($ruleSet);
  80.         }
  81.     }
  82.     /**
  83.      * Returns the slug-version of the string.
  84.      *
  85.      * @param string            $string  String to slugify
  86.      * @param string|array|null $options Options
  87.      *
  88.      * @return string Slugified version of the string
  89.      */
  90.     public function slugify(string $string, array|string|null $options null): string
  91.     {
  92.         // BC: the second argument used to be the separator
  93.         if (is_string($options)) {
  94.             $separator            $options;
  95.             $options              = [];
  96.             $options['separator'] = $separator;
  97.         }
  98.         $options array_merge($this->options, (array) $options);
  99.         // Add a custom ruleset without touching the default rules
  100.         if (isset($options['ruleset'])) {
  101.             $rules array_merge($this->rules$this->provider->getRules($options['ruleset']));
  102.         } else {
  103.             $rules $this->rules;
  104.         }
  105.         $string = ($options['strip_tags'])
  106.             ? strip_tags($string)
  107.             : $string;
  108.         $string strtr($string$rules);
  109.         unset($rules);
  110.         if ($options['lowercase'] && !$options['lowercase_after_regexp']) {
  111.             $string mb_strtolower($string);
  112.         }
  113.         $string preg_replace($options['regexp'], $options['separator'], $string);
  114.         if ($options['lowercase'] && $options['lowercase_after_regexp']) {
  115.             $string mb_strtolower($string);
  116.         }
  117.         return ($options['trim'])
  118.             ? trim($string$options['separator'])
  119.             : $string;
  120.     }
  121.     /**
  122.      * Adds a custom rule to Slugify.
  123.      *
  124.      * @param string $character   Character
  125.      * @param string $replacement Replacement character
  126.      *
  127.      * @return Slugify
  128.      */
  129.     public function addRule($character$replacement): self
  130.     {
  131.         $this->rules[$character] = $replacement;
  132.         return $this;
  133.     }
  134.     /**
  135.      * Adds multiple rules to Slugify.
  136.      *
  137.      * @param array <string,string> $rules
  138.      *
  139.      * @return Slugify
  140.      */
  141.     public function addRules(array $rules): self
  142.     {
  143.         foreach ($rules as $character => $replacement) {
  144.             $this->addRule($character$replacement);
  145.         }
  146.         return $this;
  147.     }
  148.     /**
  149.      * @param string $ruleSet
  150.      *
  151.      * @return Slugify
  152.      */
  153.     public function activateRuleSet($ruleSet): self
  154.     {
  155.         return $this->addRules($this->provider->getRules($ruleSet));
  156.     }
  157.     /**
  158.      * Static method to create new instance of {@see Slugify}.
  159.      *
  160.      * @param array <string,mixed> $options
  161.      *
  162.      * @return Slugify
  163.      */
  164.     public static function create(array $options = []): self
  165.     {
  166.         return new static($options);
  167.     }
  168. }