Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

62 rindas
1.4 KiB

  1. <?php
  2. /**
  3. * @package Grav\Plugin\Admin
  4. *
  5. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Plugin\Admin;
  9. use Grav\Common\Grav;
  10. use Grav\Common\User\Interfaces\UserCollectionInterface;
  11. use Grav\Common\User\Interfaces\UserInterface;
  12. /**
  13. * Admin utils class
  14. *
  15. * @license MIT
  16. */
  17. class Utils
  18. {
  19. /**
  20. * Matches an email to a user
  21. *
  22. * @param string $email
  23. *
  24. * @return UserInterface
  25. */
  26. public static function findUserByEmail(string $email)
  27. {
  28. $grav = Grav::instance();
  29. /** @var UserCollectionInterface $users */
  30. $users = $grav['accounts'];
  31. return $users->find($email, ['email']);
  32. }
  33. /**
  34. * Generates a slug of the given string
  35. *
  36. * @param string $str
  37. * @return string
  38. */
  39. public static function slug(string $str)
  40. {
  41. if (function_exists('transliterator_transliterate')) {
  42. $str = transliterator_transliterate('Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove;', $str);
  43. } else {
  44. $str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
  45. }
  46. $str = strtolower($str);
  47. $str = preg_replace('/[-\s]+/', '-', $str);
  48. $str = preg_replace('/[^a-z0-9-]/i', '', $str);
  49. $str = trim($str, '-');
  50. return $str;
  51. }
  52. }