public function can($action, $resource, $resourceValue = null)
{
$self = $this;
if (!is_string($resource)) {
$resourceValue = $resource;
$resource = get_class($resourceValue);
}
$rules = $this->getRulesFor($action, $resource);
if (!$rules->isEmpty()) {
$allowed = array_reduce($rules->all(), function ($result, $rule) use($self, $resourceValue) {
return $result && $rule->isAllowed($self, $resourceValue);
}, true);
$myRules = $rules->all();
$last = end($myRules);
$allowed = $allowed || $last->isAllowed($self, $resourceValue);
} else {
$allowed = false;
}
return $allowed;
}