Authority\RuleRepository::getRelevantRules PHP Method

getRelevantRules() public method

Get all rules only relevant to the given action and resource
public getRelevantRules ( string $action, string $resource ) : RuleRepository
$action string Action to check against
$resource string Resource to check against
return RuleRepository
    public function getRelevantRules($action, $resource)
    {
        $rules = array_reduce($this->rules, function ($rules, $currentRule) use($action, $resource) {
            if ($currentRule->isRelevant($action, $resource)) {
                $rules[] = $currentRule;
            }
            return $rules;
        }, array());
        return new static($rules);
    }

Usage Example

 public function testCanFetchRelevantRules()
 {
     $repo = new RuleRepository($this->rules);
     $this->assertCount(1, $repo->getRelevantRules('read', 'Obj'));
     $repo->add(new Rule(true, 'read', 'Obj'));
     $this->assertCount(2, $repo->getRelevantRules('read', 'Obj'));
 }