1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\common\adapter;
  3. use com\HonrayAuth;
  4. class AuthAdapter
  5. {
  6. private static $_instance;
  7. /**
  8. * 验证码
  9. * @var string
  10. */
  11. private $auth_key;
  12. public function __construct($auth_key)
  13. {
  14. $this->auth_key = $auth_key;
  15. }
  16. //实例化权限类
  17. public static function getInstance($auth_key)
  18. {
  19. if (!(self::$_instance instanceof HonrayAuth)) {
  20. self::$_instance = new HonrayAuth($auth_key);
  21. }
  22. return self::$_instance;
  23. }
  24. //登录认证
  25. public function checkLogin($names, $uid, $relation='or')
  26. {
  27. self::getInstance($this->auth_key)->_config['AUTH_TYPE'] = 2;
  28. if ($uid == 1){
  29. return true;
  30. }
  31. if (!self::getInstance($this->auth_key)->check($names, $uid, $relation)) {
  32. return false;
  33. } else {
  34. return true;
  35. }
  36. }
  37. //实时认证
  38. public function checkIntime($names, $uid, $relation='or')
  39. {
  40. self::getInstance($this->auth_key)->_config['AUTH_TYPE'] = 1;
  41. if ($uid == 1) {
  42. return true;
  43. }
  44. if (!self::getInstance($this->auth_key)->check($names, $uid, $relation)) {
  45. return false;
  46. } else {
  47. return true;
  48. }
  49. }
  50. //更新缓存auth_list
  51. public function updateCacheAuth()
  52. {
  53. $res = self::getInstance($this->auth_key)->updateCacheAuth();
  54. return $res;
  55. }
  56. }