Helpers.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 2021-04-14
  6. * Time: 17:34
  7. */
  8. /**
  9. * 密码验证
  10. */
  11. if (!function_exists('validPass')) {
  12. function validPass($candidate)
  13. {
  14. $r1 = '/[A-Z]/'; // 大写字母
  15. $r2 = '/[a-z]/'; // 小写字母
  16. $r3 = '/[!@#$%^&*()\-_=+{};:,<.>]/'; // 特殊字符
  17. $r4 = '/[0-9]/'; // 数字
  18. if (preg_match_all($r1, $candidate, $o) < 1) return '至少有一个大写字母';
  19. if (preg_match_all($r2, $candidate, $o) < 1) return '至少有一个小写字母';
  20. if (preg_match_all($r3, $candidate, $o) < 1) return '至少有一个特殊字符';
  21. if (preg_match_all($r4, $candidate, $o) < 1) return '至少有一个数字';
  22. if (strlen($candidate) < 8) return '至少8个字符';
  23. return true;
  24. }
  25. }
  26. /**
  27. * 判断按钮权限
  28. */
  29. if (!function_exists('checkBtn')) {
  30. function checkBtn($path = '', $permissionsList = [])
  31. {
  32. return true; //permission todo
  33. $path = explode('?', $path)[0];
  34. if (in_array($path, $permissionsList, true) || in_array('/' . $path, $permissionsList, true)) {
  35. return true;
  36. }
  37. return false;
  38. }
  39. }
  40. if (! function_exists('pinyin')) {
  41. /**
  42. * Get the Pinyin of given string.
  43. *
  44. * @param string $string
  45. * @param string $option
  46. *
  47. * @return string
  48. */
  49. function pinyin($string, $option = \Overtrue\Pinyin\Pinyin::NONE)
  50. {
  51. return app(\Overtrue\Pinyin\Pinyin::class)->convert($string, $option);
  52. }
  53. } else {
  54. Log::warning('There exist multiple function "pinyin".');
  55. }