@param TokenInterface $token

@return FamilyPermission[]|Collection

@throws \UnexpectedValueException
326254
protected function extractPermissions(TokenInterface $token)
    {
        $user = $token->getUser();
        if (!$user instanceof User) {
            return [];
        }

        return $user->getCombinedFamilyPermissions();
    }
1129557
public function vote(TokenInterface $token, $object, array $attributes)
    {
        if ($object instanceof DataInterface) {
            return $this->familyVoter->vote($token, $object->getFamily(), $attributes);
        }

        return VoterInterface::ACCESS_ABSTAIN;
    }
581743
public function canEditPwsPerm(TokenInterface $token)
    {
        if ($this->container->get('security.context')->isGranted('ROLE_ADMIN')) return true;

        $roles = $this->roleManager->getStringRolesFromToken($token);
        $accesses = $this->om
            ->getRepository('ClarolineCoreBundle:Resource\PwsRightsManagementAccess')
            ->findByRoles($roles);

        foreach ($accesses as $access) {
            if ($access->isAccessible()) return true;
        }

        return false;
    }
854772
protected function setUpTokenValues(TokenInterface $token): int
    {
        list($tokenValue, $tokenType, $tokenExpiresIn, $refreshValue) =
            $this->getIntegration()->generateTokenValues($token);
        $token->setValue($tokenValue)->setType($tokenType)->setRefreshValue($refreshValue);

        return $tokenExpiresIn;
    }
748689
public function readByValue(string $tokenValue, int $expirationInSeconds): ?TokenInterface
    {
        $schema = $this->getDatabaseSchema();
        return $this->readEnabledTokenByColumnWithExpirationCheck(
            $tokenValue,
            $schema->getTokensValueColumn(),
            $expirationInSeconds,
            $schema->getTokensValueCreatedAtColumn()
        );
    }
328971
protected function buildId(TokenInterface $token)
    {
        $id = spl_object_hash($token);
        $listeners = $this->getCacheIdentityListeners();

        foreach ($listeners as $listener) {
            $id .= '_'.$listener->getCacheId();
        }

        return $id;
    }
516544
public function getAllDrafts(TokenInterface $token)
    {
        $owner = UserSecurityIdentity::fromToken($token);
        $states = [Revision::STATE_ADDED, Revision::STATE_MODIFIED];

        $result = [];

        try {
            $result = $this->findBy([
                '_owner' => $owner,
                '_state' => $states,
            ]);
        } catch (ConversionException $e) {
            $result = [];
            foreach ($this->getAllDraftsUids($owner, $states) as $data) {
                try {
                    $result[] = $this->find($data['_uid']);
                } catch (ConversionException $e) {
                    $this->_em->getConnection()->executeUpdate(
                        'DELETE FROM revision WHERE uid = :uid',
                        ['uid' => $data['_uid']]
                    );
                }
            }
        } catch (MappingException $e) {
            $result = [];
            foreach ($this->getAllDraftsUids($owner, $states) as $data) {
                $draft = $this->find($data['_uid']);
                if (null !== $draft->getContent()) {
                    $result[] = $draft;
                } else {
                    $this->_em->getConnection()->executeUpdate(
                        'DELETE FROM revision WHERE uid = :uid',
                        ['uid' => $data['_uid']]
                    );
                }
            }
        }

        return $result;
    }
1069295
protected function userIsAllowed(TokenInterface $token)
    {
        /** @var \Symfony\Component\Security\Core\Role\RoleInterface $role */
        foreach ($this->hierarchy->getReachableRoles($token->getRoles()) as $role) {
            if ($role->getRole() === self::ROLE_ADMIN_MENU_ITEM) {
                return true;
            }
        }
        return false;
    }
905054
public function vote(TokenInterface $token, $object, array $attributes)
    {
        //attributes[0] contains the permission (ie create, edit, open, ...)
        $attributes[0] = strtoupper($attributes[0]);

        if (!$this->supports($object) || !$this->supportsAction($attributes[0])) {
            return VoterInterface::ACCESS_ABSTAIN;
        }

        $collection = $this->getCollection($object);

        foreach ($collection as $object) {
            $access = $this->checkPermission($token, $object, $attributes, $collection->getOptions());
            if (VoterInterface::ACCESS_DENIED === $access) {
                return $access;
            }
        }

        //maybe abstain sometimes
        return VoterInterface::ACCESS_GRANTED;
    }
31326
protected function addSpecialRoles(TokenInterface $token, array $sids)
    {
        $sids = $this->injectSpecialRoles($sids);

        if ($this->authenticationTrustResolver->isFullFledged($token)) {
            $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_FULLY);
            $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
            $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
        } elseif ($this->authenticationTrustResolver->isRememberMe($token)) {
            $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
            $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
        } elseif ($this->authenticationTrustResolver->isAnonymous($token)) {
            $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
        }

        return $sids;
    }
1080186
public function endToken(TokenInterface $token)
    {
        $token->getSourceLocation()->setOffsetLength(
            $this->reader->getOffset() - $token->getSourceLocation()->getOffset()
        );

        return $token;
    }
976937
public function setFamily(FamilyInterface $family = null): FamilyPermission
    {
        $this->familyCode = $family ? $family->getCode() : null;

        return $this;
    }
798276
private function doFilter(TokenFilterInterface $filter, array $tokens): array
    {
        $result = [];
        foreach ($tokens as $token) {
            $result = array_merge($result, $filter->filter($token));
        }

        return $result;
    }
1236657
protected function setBaseApiUri(TokenInterface $token)
    {
        // Make request uri.
        $endpoint = 'https://login.mailchimp.com/oauth2/metadata?oauth_token=' . $token->getAccessToken();

        // Grab meta data about the token.
        $response = $this->httpRequest($endpoint, [], [], 'GET');

        // Parse JSON.
        $meta = json_decode($response, true);

        // Set base api uri.
        $this->baseApiUri = new Url('https://' . $meta[ 'dc' ] . '.api.mailchimp.com/{apiVersion}/');

        // Allow chaining.
        return $this;
    }
1132889
public function moveToToken(Token $token) {

      if (!$token->isValid()) {
        $this->setValid(false);
        return new Token();
      }

      $tokenIndex = $token->getIndex();


      foreach ($this->collection as $index => $collectionToken) {
        if ($collectionToken->getIndex() === $tokenIndex) {
          $this->setPosition($index);
          return $collectionToken;
        }
      }

      $this->setValid(false);
      return new Token();
    }
891583
public function vote(TokenInterface $token, $object, array $attributes)
    {
        if (!$object instanceof Group && !$object instanceof GroupCollection) return VoterInterface::ACCESS_ABSTAIN;
        $groups = $object instanceof GroupCollection ? $object->getGroups(): array($object);
        $action = strtolower($attributes[0]);

        switch ($action) {
            case self::CREATE: return $this->checkCreation($token);
            case self::EDIT:   return $this->checkEdit($token, $groups);
            case self::DELETE: return $this->checkDelete($token, $groups);
            case self::VIEW:   return $this->checkView($token, $groups);
        }

        return VoterInterface::ACCESS_ABSTAIN;
    }
944205
public function parse(Token $token): FixturePropertyValue
    {
        parent::parse($token);

        $explodedValue = explode('->', $token->getValue());
        if (count($explodedValue) !== 2) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }

        $reference = $this->parser->parse($explodedValue[0]);
        if (false === $reference instanceof ValueInterface) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }

        return new FixturePropertyValue(
            $reference,
            $explodedValue[1]
        );
    }