Просмотр файла vendor/league/commonmark/src/Extension/HeadingPermalink/Slug/DefaultSlugGenerator.php

Размер файла: 1.14Kb
  1. <?php
  2.  
  3. /*
  4. * This file is part of the league/commonmark package.
  5. *
  6. * (c) Colin O'Dell <colinodell@gmail.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11.  
  12. namespace League\CommonMark\Extension\HeadingPermalink\Slug;
  13.  
  14. use League\CommonMark\Normalizer\SlugNormalizer;
  15.  
  16. @trigger_error(sprintf('%s is deprecated; use %s instead', DefaultSlugGenerator::class, SlugNormalizer::class), E_USER_DEPRECATED);
  17.  
  18. /**
  19. * Creates URL-friendly strings
  20. *
  21. * @deprecated Use League\CommonMark\Normalizer\SlugNormalizer instead
  22. */
  23. final class DefaultSlugGenerator implements SlugGeneratorInterface
  24. {
  25. public function createSlug(string $input): string
  26. {
  27. // Trim whitespace
  28. $slug = \trim($input);
  29. // Convert to lowercase
  30. $slug = \mb_strtolower($slug);
  31. // Try replacing whitespace with a dash
  32. $slug = \preg_replace('/\s+/u', '-', $slug) ?? $slug;
  33. // Try removing characters other than letters, numbers, and marks.
  34. $slug = \preg_replace('/[^\p{L}\p{Nd}\p{Nl}\p{M}-]+/u', '', $slug) ?? $slug;
  35.  
  36. return $slug;
  37. }
  38. }