Gate.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 a policy instance for a given class.
  86. *
  87. * @param object|string $class
  88. * @return mixed
  89. *
  90. * @throws \InvalidArgumentException
  91. */
  92. public function getPolicyFor($class);
  93. /**
  94. * Get a guard instance for the given user.
  95. *
  96. * @param \Illuminate\Contracts\Auth\Authenticatable|mixed $user
  97. * @return static
  98. */
  99. public function forUser($user);
  100. /**
  101. * Get all of the defined abilities.
  102. *
  103. * @return array
  104. */
  105. public function abilities();
  106. }