Gate.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace Illuminate\Contracts\Auth\Access;
  3. interface Gate
  4. {
  5. /**
  6. * Determine if a given ability has been defined.
  7. *
  8. * @param string $ability
  9. * @return bool
  10. */
  11. public function has($ability);
  12. /**
  13. * Define a new ability.
  14. *
  15. * @param string $ability
  16. * @param callable|string $callback
  17. * @return $this
  18. */
  19. public function define($ability, $callback);
  20. /**
  21. * Define a policy class for a given class type.
  22. *
  23. * @param string $class
  24. * @param string $policy
  25. * @return $this
  26. */
  27. public function policy($class, $policy);
  28. /**
  29. * Register a callback to run before all Gate checks.
  30. *
  31. * @param callable $callback
  32. * @return $this
  33. */
  34. public function before(callable $callback);
  35. /**
  36. * Register a callback to run after all Gate checks.
  37. *
  38. * @param callable $callback
  39. * @return $this
  40. */
  41. public function after(callable $callback);
  42. /**
  43. * Determine if the given ability should be granted for the current user.
  44. *
  45. * @param string $ability
  46. * @param array|mixed $arguments
  47. * @return bool
  48. */
  49. public function allows($ability, $arguments = []);
  50. /**
  51. * Determine if the given ability should be denied for the current user.
  52. *
  53. * @param string $ability
  54. * @param array|mixed $arguments
  55. * @return bool
  56. */
  57. public function denies($ability, $arguments = []);
  58. /**
  59. * Determine if all of the given abilities should be granted for the current user.
  60. *
  61. * @param iterable|string $abilities
  62. * @param array|mixed $arguments
  63. * @return bool
  64. */
  65. public function check($abilities, $arguments = []);
  66. /**
  67. * Determine if any one of the given abilities should be granted for the current user.
  68. *
  69. * @param iterable|string $abilities
  70. * @param array|mixed $arguments
  71. * @return bool
  72. */
  73. public function any($abilities, $arguments = []);
  74. /**
  75. * Determine if the given ability should be granted for the current user.
  76. *
  77. * @param string $ability
  78. * @param array|mixed $arguments
  79. * @return \Illuminate\Auth\Access\Response
  80. *
  81. * @throws \Illuminate\Auth\Access\AuthorizationException
  82. */
  83. public function authorize($ability, $arguments = []);
  84. /**
  85. * Get the raw result from the authorization callback.
  86. *
  87. * @param string $ability
  88. * @param array|mixed $arguments
  89. * @return mixed
  90. */
  91. public function raw($ability, $arguments = []);
  92. /**
  93. * Get a policy instance for a given class.
  94. *
  95. * @param object|string $class
  96. * @return mixed
  97. *
  98. * @throws \InvalidArgumentException
  99. */
  100. public function getPolicyFor($class);
  101. /**
  102. * Get a guard instance for the given user.
  103. *
  104. * @param \Illuminate\Contracts\Auth\Authenticatable|mixed $user
  105. * @return static
  106. */
  107. public function forUser($user);
  108. /**
  109. * Get all of the defined abilities.
  110. *
  111. * @return array
  112. */
  113. public function abilities();
  114. }