/** * {@inheritdoc} */ public function processNewResource(ResourceInterface $resource) { /** @var AuthorizationRepository $repository */ $repository = $this->entityManager->getRepository('MyCLabs\\ACL\\Model\\Authorization'); $parentResources = $this->resourceGraphTraverser->getAllParentResources($resource); // Find root authorizations on the parent resources $authorizationsToCascade = []; foreach ($parentResources as $parentResource) { $authorizationsToCascade = array_merge($authorizationsToCascade, $repository->findCascadableAuthorizationsForResource($parentResource)); } // Cascade them $authorizations = []; foreach ($authorizationsToCascade as $authorizationToCascade) { /** @var Authorization $authorizationToCascade */ $authorizations[] = $authorizationToCascade->createChildAuthorization($resource); } return $authorizations; }
public function testSetTraverserWithInterface() { $traverser = new ResourceGraphTraverserDispatcher(); $resource = $this->getMockForAbstractClass('MyCLabs\\ACL\\Model\\ResourceInterface'); $subTraverser = $this->getMockForAbstractClass('\\MyCLabs\\ACL\\ResourceGraph\\ResourceGraphTraverser'); // Set the traverser by passing the interface (and not the concrete class) $traverser->setResourceGraphTraverser('MyCLabs\\ACL\\Model\\ResourceInterface', $subTraverser); // Check that the $subTraverser is indeed called $subTraverser->expects($this->once())->method('getAllParentResources')->with($resource); $traverser->getAllParentResources($resource); }