Skip to content
Permalink
Browse files

first pass at guessing policy from class

  • Loading branch information...
taylorotwell committed Feb 18, 2019
1 parent 83a7b92 commit 82816f053517587c100d951f3f1853428cfcf579
Showing with 15 additions and 0 deletions.
  1. +15 −0 src/Illuminate/Auth/Access/Gate.php
@@ -531,13 +531,28 @@ public function getPolicyFor($class)
return $this->resolvePolicy($this->policies[$class]);
}
if (class_exists($guessedPolicy = $this->guessPolicyName($class))) {
return $this->resolvePolicy($guessedPolicy);
}
foreach ($this->policies as $expected => $policy) {
if (is_subclass_of($class, $expected)) {
return $this->resolvePolicy($policy);
}
}
}
/**
* Guess the policy name for the given class.
*
* @param string $class
* @return string
*/
protected function guessPolicyName($class)
{
return dirname(str_replace('\\', '/', $class)).'\\Policies\\'.class_basename($class).'Policy';
}
/**
* Build a policy class instance of the given type.
*

0 comments on commit 82816f0

Please sign in to comment.
You can’t perform that action at this time.