/**
  * @param AttributeDefinition $attribute
  */
 public function addAttributeDefinition(AttributeDefinition $attribute)
 {
     if (isset($this->attributes[$attribute->getName()])) {
         throw new LogicException(sprintf('Cannot add attribute "%s" as it has already been added'));
     }
     $this->attributes[$attribute->getName()] = $attribute;
 }
 public function containsAttributeDefinedBy(AttributeDefinition $attributeDefinition)
 {
     foreach ($this->attributes as $attribute) {
         if ($attributeDefinition->equals($attribute->getAttributeDefinition())) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param AuthenticatedUser $user
  * @return ConsentList|null
  */
 public function findAllFor(AuthenticatedUser $user)
 {
     if (!$user->getAttributes()->containsAttributeDefinedBy($this->identifyingAttribute)) {
         $message = sprintf('Cannot get consent list for user: user does not have identifying attribute "%s"', $this->identifyingAttribute->getName());
         $this->logger->error($message);
         return null;
     }
     $userIdentifier = $user->getAttributes()->getAttributeByDefinition($this->identifyingAttribute);
     $identifyingValues = $userIdentifier->getValue();
     $identifyingValue = array_shift($identifyingValues);
     if (!is_string($identifyingValue)) {
         $message = sprintf('In order to get the consent list for a user, the identifying attribute must have a string value. "%s"' . 'given for identifying attribute "%s"', gettype($identifyingValue), $this->identifyingAttribute->getName());
         $this->logger->error($message);
         return null;
     }
     return $this->consentRepository->findAllFor($identifyingValue);
 }
 /**
  * @param AttributeDefinition $attributeDefinition
  *
  * We store the definitions indexed both by name and by urn to ensure speedy lookups due to the amount of
  * definitions and the amount of usages of the lookups
  */
 public function addAttributeDefinition(AttributeDefinition $attributeDefinition)
 {
     if (isset($this->attributeDefinitionsByName[$attributeDefinition->getName()])) {
         throw new LogicException(sprintf('Cannot add attribute "%s" as it has already been added', $attributeDefinition->getName()));
     }
     $this->attributeDefinitionsByName[$attributeDefinition->getName()] = $attributeDefinition;
     if ($attributeDefinition->hasUrnMace()) {
         $this->attributeDefinitionsByUrn[$attributeDefinition->getUrnMace()] = $attributeDefinition;
     }
     if ($attributeDefinition->hasUrnOid()) {
         $this->attributeDefinitionsByUrn[$attributeDefinition->getUrnOid()] = $attributeDefinition;
     }
 }