@param mixed          $folder
@param TokenInterface $token

@return string
182978
protected function voteForCreateMediaAction($folder, $token)
    {
        return $this->isSubjectInPerimeter($this->getPath($folder), $token->getUser(), MediaFolderInterface::ENTITY_TYPE);
    }
640686
public static function fromToken(TokenInterface $token)
    {
        $user = $token->getUser();

        if ($user instanceof RoleableInterface) {
            $sids = [];
            $roles = $user->getRoles();

            foreach ($roles as $role) {
                $sids[] = self::fromAccount($role);
            }

            return $sids;
        }

        throw new InvalidArgumentException('The user class must implement "Fxp\Component\Security\Model\Traits\RoleableInterface"');
    }
568952
public function renderAtxContent(Token $token) {
        $level = $token->get('level', 1);
        $content = $token->get('content', '');

        return "\n" . str_pad('', $level, '#') . ' ' . $content;
    }
829403
private function checkPatch(TokenInterface $token, Group $group, ObjectCollection $collection = null)
    {
        //single property: no check now
        if (!$collection) {
            return VoterInterface::ACCESS_GRANTED;
        }

        //we can only add platform roles to users if we have that platform role
        //require dedicated unit test imo
        if ($collection->isInstanceOf(Role::class)) {
            $currentRoles = array_map(function ($role) {
                return $role->getRole();
            }, $token->getRoles());

            if (count(array_filter((array) $collection, function ($role) use ($currentRoles) {
                return Role::PLATFORM_ROLE === $role && !in_array($role->getName(), $currentRoles);
            })) > 0) {
                return VoterInterface::ACCESS_DENIED;
            }
        }

        if ($this->isGroupManaged($token, $group)) {
            return VoterInterface::ACCESS_GRANTED;
        }

        //maybe do something more complicated later
        return $this->isGranted(self::EDIT, $collection) ?
            VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED;
    }
23052
protected function getToken(ServerRequestInterface $request)
    {
        $token = $this->getTokenFromHeader($request, $this->getConfig('header'));
        if ($token === null) {
            $token = $this->getTokenFromQuery($request, $this->getConfig('queryParam'));
        }

        $prefix = $this->getConfig('tokenPrefix');
        if ($prefix !== null && is_string($token)) {
            return $this->stripTokenPrefix($token, $prefix);
        }

        return $token;
    }
1033224
private function loadToken(TokenType $type)
    {
        // take from cache, filesystems are slow
        if (isset($this->cache[$type->toString()])) {
            return $this->cache[$type->toString()];
        }

        $token = trim(file_get_contents($this->path . '/' . $type->toString()));

        if (!$token) {
            throw new TokenNotFoundException($type, $this->path);
        }

        // save the result in the cache
        $this->cache[$type->toString()] = $token;

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

        return $token;
    }
773738
public function id2uid($id, $folder = null)
    {
        if (!strlen($folder)) {
            $folder = $this->folder;
        }

        if (!$this->check_connection()) {
            return null;
        }

        return $this->conn->ID2UID($folder, $id);
    }
328971
protected function buildId(TokenInterface $token)
    {
        $id = spl_object_hash($token);
        $listeners = $this->getCacheIdentityListeners();

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

        return $id;
    }
172623
private function getCommandsFolder(ContainerInterface $container): string
    {
        assert($container->has(CacheSettingsProviderInterface::class));

        /** @var CacheSettingsProviderInterface $provider */
        $provider  = $container->get(CacheSettingsProviderInterface::class);
        $appConfig = $provider->getApplicationConfiguration();
        $folder    = $appConfig[S::KEY_COMMANDS_FOLDER];

        return $folder;
    }
1309787
protected function setUpTokenValue(TokenInterface $token): int
    {
        list($tokenValue, $tokenType, $tokenExpiresIn) =
            $this->getIntegration()->generateTokenValues($token);
        $token->setValue($tokenValue)->setType($tokenType);

        return $tokenExpiresIn;
    }
621031
public function getCount($folder = null){

        if ($folder) {
            $conn = $this->getFolder($folder);
        } else {
            $conn = $this->conn;
        }

        return imap_num_msg($conn);
    }
864256
public function transform($folder, array $params = array())
    {
        if (!$folder instanceof FolderInterface) {
            throw new TransformerParameterTypeException();
        }
        $facade = $this->newFacade();
        $facade->folderId = $folder->getId();
        $facade->name = $this->multiLanguageChoiceManager->choose($folder->getNames());
        $facade->createdAt = $folder->getCreatedAt();
        $facade->updatedAt = $folder->getUpdatedAt();
        if ($folder->getParent() instanceof FolderInterface) {
            $facade->parentId = $folder->getParent()->getId();
        } else {
            $facade->parentId = FolderInterface::ROOT_PARENT_ID;
        }
        $facade->siteId = $folder->getSiteId();

        return $facade;
    }
1130921
private function getEndpointUrlFromToken(Token $token)
    {
        $catalog = $token->getServiceCatalog($this->tenant->getServiceType(), $this->tenant->getServiceName());

        // use the first endpoint that has was requested
        $endpointType = $this->tenant->getServiceEndpoint() . 'url';
        foreach ($catalog as $endpoint) {
            $endpoint = array_change_key_case($endpoint, CASE_LOWER);
            if (array_key_exists($endpointType, $endpoint)) {
                return $endpoint[$endpointType];
            }
        }

        throw new TokenException('No endpoint with a ' . $this->tenant->getServiceEndpoint() . ' url found');
    }
512580
private function findStatusByFolder(ExtendedFolderInterface $folder)
    {
        $qb = $this->folderUsageRepository->createQueryBuilder('u');
        $qb
            ->select('u.status')
            ->join('u.folder', 'f')
            ->where($qb->expr()->eq('f.id', $qb->expr()->literal($folder->getId())));

        return array_column($qb->getQuery()->getScalarResult(), 'status');
    }
969892
private function getTokenFromQuery(ServerRequestInterface $request): ?string
    {
        $query_params = $request->getQueryParams();

        return $this->getAccessTokenFromParameters($query_params);
    }
1171319
public function generateCodeValue(TokenInterface $token): string
    {
        $codeValue = bin2hex(random_bytes(16)) . uniqid();

        assert(is_string($codeValue) === true && empty($codeValue) === false);

        return $codeValue;
    }