/**
  * Gets id for the given domain object.
  * Returns null when the given domain object is null
  *
  * @param  object|null $domainObject
  * @return int|string|null
  * @throws InvalidDomainObjectException
  */
 protected function getObjectIdIgnoreNull($domainObject)
 {
     if ($domainObject === null) {
         return null;
     }
     return $this->objectIdAccessor->getId($domainObject);
 }
 /**
  * Gets the id of logged in user
  *
  * @return int|string|null
  */
 public function getUserId()
 {
     $user = $this->getUser();
     if ($user) {
         return $this->objectIdAccessor->getId($user);
     }
     return null;
 }
示例#3
0
 /**
  * Constructs an ObjectIdentity for the given domain object
  *
  * @param object $domainObject
  *
  * @return ObjectIdentity
  * @throws InvalidDomainObjectException
  */
 protected function fromDomainObject($domainObject)
 {
     if (!is_object($domainObject)) {
         throw new InvalidDomainObjectException('$domainObject must be an object.');
     }
     try {
         return new ObjectIdentity($this->objectIdAccessor->getId($domainObject), ClassUtils::getRealClass($domainObject));
     } catch (\InvalidArgumentException $invalid) {
         throw new InvalidDomainObjectException($invalid->getMessage(), 0, $invalid);
     }
 }
 /**
  * Gets ACL extension responsible for work with the given domain object
  *
  * @param mixed $val A domain object, ObjectIdentity, object identity descriptor (id:type) or ACL annotation
  * @throws InvalidDomainObjectException
  * @return AclExtensionInterface
  */
 public function select($val)
 {
     if ($val === null) {
         return new NullAclExtension();
     }
     $type = $id = null;
     if (is_string($val)) {
         $delim = strpos($val, ':');
         if ($delim) {
             $type = ltrim(substr($val, $delim + 1), ' ');
             $id = strtolower(substr($val, 0, $delim));
         }
     } elseif (is_object($val)) {
         if ($val instanceof ObjectIdentityInterface) {
             $type = $val->getType();
             $id = $val->getIdentifier();
         } elseif ($val instanceof AclAnnotation) {
             $type = $val->getClass();
             if (empty($type)) {
                 $type = $val->getId();
             }
             $id = $val->getType();
         } else {
             $type = get_class($val);
             $id = $this->objectIdAccessor->getId($val);
         }
     }
     if ($type !== null && $id !== null) {
         $cacheKey = $id . '!' . $type;
         if (isset($this->localCache[$cacheKey])) {
             return $this->localCache[$cacheKey];
         }
         foreach ($this->extensions as $extension) {
             if ($extension->supports($type, $id)) {
                 $this->localCache[$cacheKey] = $extension;
                 return $extension;
             }
         }
     }
     throw $this->createAclExtensionNotFoundException($val, $type, $id);
 }
 /**
  * Gets the id of logged in user
  *
  * @return int|string
  */
 public function getUserId()
 {
     $token = $this->getSecurityContext()->getToken();
     if (!$token) {
         return null;
     }
     $user = $token->getUser();
     if (!is_object($user) || !is_a($user, $this->metadataProvider->getBasicLevelClass())) {
         return null;
     }
     return $this->objectIdAccessor->getId($user);
 }
示例#6
0
 /**
  * Checks if the given owner owns at least one entity
  *
  * @param object $owner
  * @return bool
  */
 public function hasAssignments($owner)
 {
     $result = false;
     $ownerType = $this->getOwnerType($owner);
     if ($ownerType !== OwnershipType::OWNER_TYPE_NONE) {
         foreach ($this->ownershipProvider->getConfigs(null, true) as $config) {
             if ($config->get('owner_type') === $ownerType) {
                 $entityClassName = $config->getId()->getClassName();
                 $result = $this->getAssignmentChecker($entityClassName)->hasAssignments($this->objectIdAccessor->getId($owner), $entityClassName, $this->ownershipMetadata->getMetadata($entityClassName)->getOwnerFieldName(), $this->em);
                 if ($result) {
                     break;
                 }
             }
         }
     }
     return $result;
 }
示例#7
0
 /**
  * @expectedException \Symfony\Component\Security\Acl\Exception\InvalidDomainObjectException
  */
 public function testGetIdNull()
 {
     $accessor = new ObjectIdAccessor();
     $accessor->getId(null);
 }