Gate.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 abilities for a resource.
  22. *
  23. * @param string $name
  24. * @param string $class
  25. * @param array|null $abilities
  26. * @return $this
  27. */
  28. public function resource($name, $class, ?array $abilities = null);
  29. /**
  30. * Define a policy class for a given class type.
  31. *
  32. * @param string $class
  33. * @param string $policy
  34. * @return $this
  35. */
  36. public function policy($class, $policy);
  37. /**
  38. * Register a callback to run before all Gate checks.
  39. *
  40. * @param callable $callback
  41. * @return $this
  42. */
  43. public function before(callable $callback);
  44. /**
  45. * Register a callback to run after all Gate checks.
  46. *
  47. * @param callable $callback
  48. * @return $this
  49. */
  50. public function after(callable $callback);
  51. /**
  52. * Determine if all of the given abilities should be granted for the current user.
  53. *
  54. * @param iterable|string $ability
  55. * @param array|mixed $arguments
  56. * @return bool
  57. */
  58. public function allows($ability, $arguments = []);
  59. /**
  60. * Determine if any of the given abilities should be denied for the current user.
  61. *
  62. * @param iterable|string $ability
  63. * @param array|mixed $arguments
  64. * @return bool
  65. */
  66. public function denies($ability, $arguments = []);
  67. /**
  68. * Determine if all of the given abilities should be granted for the current user.
  69. *
  70. * @param iterable|string $abilities
  71. * @param array|mixed $arguments
  72. * @return bool
  73. */
  74. public function check($abilities, $arguments = []);
  75. /**
  76. * Determine if any one of the given abilities should be granted for the current user.
  77. *
  78. * @param iterable|string $abilities
  79. * @param array|mixed $arguments
  80. * @return bool
  81. */
  82. public function any($abilities, $arguments = []);
  83. /**
  84. * Determine if the given ability should be granted for the current user.
  85. *
  86. * @param string $ability
  87. * @param array|mixed $arguments
  88. * @return \Illuminate\Auth\Access\Response
  89. *
  90. * @throws \Illuminate\Auth\Access\AuthorizationException
  91. */
  92. public function authorize($ability, $arguments = []);
  93. /**
  94. * Inspect the user for the given ability.
  95. *
  96. * @param string $ability
  97. * @param array|mixed $arguments
  98. * @return \Illuminate\Auth\Access\Response
  99. */
  100. public function inspect($ability, $arguments = []);
  101. /**
  102. * Get the raw result from the authorization callback.
  103. *
  104. * @param string $ability
  105. * @param array|mixed $arguments
  106. * @return mixed
  107. *
  108. * @throws \Illuminate\Auth\Access\AuthorizationException
  109. */
  110. public function raw($ability, $arguments = []);
  111. /**
  112. * Get a policy instance for a given class.
  113. *
  114. * @param object|string $class
  115. * @return mixed
  116. *
  117. * @throws \InvalidArgumentException
  118. */
  119. public function getPolicyFor($class);
  120. /**
  121. * Get a guard instance for the given user.
  122. *
  123. * @param \Illuminate\Contracts\Auth\Authenticatable|mixed $user
  124. * @return static
  125. */
  126. public function forUser($user);
  127. /**
  128. * Get all of the defined abilities.
  129. *
  130. * @return array
  131. */
  132. public function abilities();
  133. }