/** * Creates a user security identity from a TokenInterface. * * @param TokenInterface $token * * @return UserSecurityIdentity */ public static function fromToken(TokenInterface $token) { $user = $token->getUser(); if ($user instanceof UserInterface) { return self::fromAccount($user); } return new self((string) $user, is_object($user) ? ClassUtils::getRealClass($user) : ClassUtils::getRealClass($token)); }
/** * {@inheritdoc} */ public function save($unlockedBadge, array $options = []) { if (false === $unlockedBadge instanceof $this->savedClass) { throw new \InvalidArgumentException(sprintf('Expects a "%s", "%s" provided.', $this->savedClass, ClassUtils::getRealClass($unlockedBadge))); } $this->objectManager->persist($unlockedBadge); $this->objectManager->flush(); $event = new BadgeUnlockEvent($unlockedBadge); $this->eventDispatcher->dispatch(GameEvents::USER_UNLOCKS_BADGE, $event); }
/** * Gets the real class name of a class name that could be a proxy. * * @param string|object $object * * @return string */ public static function getRealClass($object) { if (class_exists('Symfony\\Component\\Security\\Acl\\Util\\ClassUtils')) { return AclClassUtils::getRealClass($object); } // fallback in case security-acl is not installed $class = is_object($object) ? get_class($object) : $object; if (false === ($pos = strrpos($class, '\\' . self::MARKER . '\\'))) { return $class; } return substr($class, $pos + self::MARKER_LENGTH + 2); }
/** * Constructs an ObjectIdentity for the given domain object. * * @param object $domainObject * * @throws InvalidDomainObjectException * * @return ObjectIdentity */ public static function fromDomainObject($domainObject) { if (!is_object($domainObject)) { throw new InvalidDomainObjectException('$domainObject must be an object.'); } try { if ($domainObject instanceof DomainObjectInterface) { return new self($domainObject->getObjectIdentifier(), ClassUtils::getRealClass($domainObject)); } elseif (method_exists($domainObject, 'getId')) { return new self((string) $domainObject->getId(), ClassUtils::getRealClass($domainObject)); } } catch (\InvalidArgumentException $e) { throw new InvalidDomainObjectException($e->getMessage(), 0, $e); } throw new InvalidDomainObjectException('$domainObject must either implement the DomainObjectInterface, or have a method named "getId".'); }
/** * {@inheritdoc} */ public function getObjectIdentity($type, $classOrObject) { if ($classOrObject instanceof ObjectIdentityInterface) { return $classOrObject; } switch ($type) { case self::OID_TYPE_CLASS: if (is_object($classOrObject)) { if (class_exists('Symfony\\Component\\Security\\Acl\\Util\\ClassUtils')) { $classOrObject = ClassUtils::getRealClass($classOrObject); } else { $classOrObject = DeprecatedClassUtils::getRealClass($classOrObject); } } return new ObjectIdentity($type, $classOrObject); case self::OID_TYPE_OBJECT: return ObjectIdentity::fromDomainObject($classOrObject); } throw new OidTypeException($type); }