directives = $directives; } /** * Returns true if the consumer has access to the given topic * * @param ConsumerInterface $consumer * @param Topic $topic * * @return Boolean */ public function hasAccess(ConsumerInterface $consumer, Topic $topic) { foreach ($this->getDirectives($topic) as $directive) { if (!$directive->isStatisfiedBy($consumer)) { return false; } } return true; } /** * @param Topic $topic * * @return Directive[] */ private function getDirectives(Topic $topic) { return array_filter($this->directives, function (Directive $directive) use ($topic) { return $directive->getTopic() === $topic->getId(); }); } }