NativeSlugify.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\CoreBundle\Component;
  11. @trigger_error(
  12. 'The '.__NAMESPACE__.'\NativeSlugify class is deprecated since version 2.3 and will be removed in 4.0.',
  13. E_USER_DEPRECATED
  14. );
  15. /**
  16. * Do not use this class, it is only here to be BC.
  17. *
  18. * NEXT_MAJOR: remove this class.
  19. *
  20. * @deprecated since 2.3, to be removed in 4.0.
  21. *
  22. * @author Thomas Rabaix <thomas.rabaix@gmail.com>
  23. */
  24. class NativeSlugify
  25. {
  26. /**
  27. * @param $text
  28. *
  29. * @return mixed|string
  30. *
  31. * @deprecated since 2.3, to be removed in 4.0.
  32. */
  33. public function slugify($text)
  34. {
  35. $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
  36. // trim
  37. $text = trim($text, '-');
  38. // transliterate
  39. if (function_exists('iconv')) {
  40. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  41. }
  42. // lowercase
  43. $text = strtolower($text);
  44. // remove unwanted characters
  45. $text = preg_replace('~[^-\w]+~', '', $text);
  46. return $text;
  47. }
  48. }