Translates an activity token.

@param string|ComActivitiesActivityObjectInterface $token    The activity token.
@param ComActivitiesActivityInterface              $activity The activity object.
@return string The translated token.
19703
public function translateActivityToken($token, ComActivitiesActivityInterface $activity)
    {
        if (is_string($token))
        {
            $tokens = $this->getActivityTokens($activity);

            if (isset($tokens[$token])) {
                $token = $tokens[$token];
            }
        }

        if (!$token instanceof ComActivitiesActivityObjectInterface) {
            throw new RuntimeException('Invalid token');
        }

        $result = $token->getDisplayName();

        if ($token->isTranslatable())
        {
            if ($activity->getLocale() == $this->getLocaleFallback())
            {
                // Use decorator catalogue instead
                $this->_switchCatalogues();
                $result = $this->translate($result);
                $this->_switchCatalogues();
            } else $result = $this->translate($result);
        }

        return $result;
    }
234227
private function _processTODO($token) {
		if ($this->_isActive('showTODOs')) {
			$text = $token->text;
			$todoStr = stripos($text, 'TODO');
			if ($todoStr !== FALSE) {

				$todoMsg = substr($text, $todoStr + 4);

				// Take the first line only
				$lines = preg_split('/\r\n|\r|\n/', $todoMsg);
				$todoMsg = $lines[0];

				// Remove a ':' from the start
				$colonPos = stripos($todoMsg, ':');
				if ($todoStr !== FALSE) {
					$todoMsg = substr($todoMsg, $colonPos + 1);
				}

				// Trim
				$todoMsg = trim($todoMsg);

				$msg = $this->_getMessage('TODO', $todoMsg);
				$this->_writeError('showTODOs', $msg, $token->line);
			}
		}
	}
59572
private function assertCurrentFlowObjectIsExpectedActivity(ActivityInterface $activity)
    {
        if (!$activity->equals($this->getCurrentFlowObject())) {
            throw new UnexpectedActivityException(sprintf('The current flow object is not equal to the expected activity "%s".', $activity->getId()));
        }
    }
847340
def handle_activity_legacy(_: str, __: int, tokens: ParseResults) -> ParseResults:
    """"""
    legacy_cls = language.activity_labels[tokens[MODIFIER]]
    tokens[MODIFIER] = ACTIVITY
    tokens[EFFECT] = {
        NAME: legacy_cls,
        NAMESPACE: BEL_DEFAULT_NAMESPACE
    }
    log.log(5, 'upgraded legacy activity to %s', legacy_cls)
    return tokens
259455
protected function voteForReadAction($media, TokenInterface $token)
    {
        return $this->isSubjectInPerimeter($media->getMediaFolder()->getPath(), $token->getUser(), MediaFolderInterface::ENTITY_TYPE);
    }
5840
protected Object getBean(Token token) {
        Object value;
        if (token.getAlternativeValue() != null) {
            if (token.getDirectiveType() == TokenDirectiveType.FIELD) {
                Field field = (Field)token.getAlternativeValue();
                if (Modifier.isStatic(field.getModifiers())) {
                    value = ReflectionUtils.getField(field, null);
                } else {
                    Class<?> cls = field.getDeclaringClass();
                    Object target = activity.getBean(cls);
                    value = ReflectionUtils.getField(field, target);
                }
            } else if (token.getDirectiveType() == TokenDirectiveType.METHOD) {
                Method method = (Method)token.getAlternativeValue();
                if (Modifier.isStatic(method.getModifiers())) {
                    value = ReflectionUtils.invokeMethod(method, null);
                } else {
                    Class<?> cls = method.getDeclaringClass();
                    Object target = activity.getBean(cls);
                    value = ReflectionUtils.invokeMethod(method, target);
                }
            } else {
                Class<?> cls = (Class<?>)token.getAlternativeValue();
                try {
                    value = activity.getBean(cls);
                } catch (RequiredTypeBeanNotFoundException | NoUniqueBeanException e) {
                    if (token.getGetterName() != null) {
                        try {
                            value = BeanUtils.getProperty(cls, token.getGetterName());
                            if (value == null) {
                                value = token.getDefaultValue();
                            }
                            return value;
                        } catch (InvocationTargetException e2) {
                            // ignore
                        }
                    }
                    throw e;
                }
                if (value != null && token.getGetterName() != null) {
                    value = getBeanProperty(value, token.getGetterName());
                }
            }
        } else {
            value = activity.getBean(token.getName());
            if (value != null && token.getGetterName() != null) {
                value = getBeanProperty(value, token.getGetterName());
            }
        }
        if (value == null) {
            value = token.getDefaultValue();
        }
        return value;
    }
622950
protected function translateTokenFromIdentifier($identifier, $value)
    {
        $result = null;

        if (array_key_exists($identifier, self::$tokenValueMap)) {
            $result = $this->translateTokenUsingMap($identifier);
        } elseif (array_key_exists($identifier, self::$tokenCallbackMap)) {
            $result = $this->translateTokenUsingCallback($identifier, $value);
        }

        return $result;
    }
1252484
public function addToken($token)
    {
        if (count($this->tokens) + 1 > self::MULTICAST_MAX_TOKENS) {
            throw new \RuntimeException(sprintf('Max token number reached. %s tokens max.', self::MULTICAST_MAX_TOKENS));
        }

        return parent::addToken($token);
    }
613079
public function authenticate(TokenInterface $token)
    {
        if (!$this->supports($token)) {
            throw new \InvalidArgumentException('GuardAuthenticationProvider only supports GuardTokenInterface.');
        }

        if (!$token instanceof PreAuthenticationGuardToken) {
            /*
             * The listener *only* passes PreAuthenticationGuardToken instances.
             * This means that an authenticated token (e.g. PostAuthenticationGuardToken)
             * is being passed here, which happens if that token becomes
             * "not authenticated" (e.g. happens if the user changes between
             * requests). In this case, the user should be logged out, so
             * we will return an AnonymousToken to accomplish that.
             */

            // this should never happen - but technically, the token is
            // authenticated... so it could just be returned
            if ($token->isAuthenticated()) {
                return $token;
            }

            // cause the logout - the token is not authenticated
            return new AnonymousToken($this->providerKey, 'anon.');
        }

        // find the *one* GuardAuthenticator that this token originated from
        foreach ($this->guardAuthenticators as $key => $guardAuthenticator) {
            // get a key that's unique to *this* guard authenticator
            // this MUST be the same as GuardAuthenticationListener
            $uniqueGuardKey = $this->providerKey.'_'.$key;

            if ($uniqueGuardKey == $token->getGuardProviderKey()) {
                return $this->authenticateViaGuard($guardAuthenticator, $token);
            }
        }

        // no matching authenticator found - but there will be multiple GuardAuthenticationProvider
        // instances that will be checked if you have multiple firewalls.
    }
450321
public function decorate(Token $token): string
    {
        $style = $token->style();
        $value = $token->value();

        foreach ($this->decorators as $decorator) {
            $value = $decorator->decorate($style, $value);
        }

        return $value;
    }
864045
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));
    }
56015
public static function getFormattedDescription(Activity $activity, $withDecoration = true)
    {
        if (!$withDecoration) {
            return $activity->getDescription(false);
        }
        $value = $activity->getDescription(true);

        // Replace description HTML elements with Symfony Console decoration
        // tags.
        $value = preg_replace('@<[^/][^>]+>@', '<options=underscore>', $value);
        $value = preg_replace('@</[^>]+>@', '</>', $value);

        // Replace literal tags like "&lt;info&;gt;" with escaped tags like
        // "\<info>".
        $value = preg_replace('@&lt;(/?[a-z][a-z0-9,_=;-]*+)&gt;@i', '\\\<$1>', $value);

        // Decode other HTML entities.
        $value = html_entity_decode($value, ENT_QUOTES, 'utf-8');

        return $value;
    }
347269
public function getByToken($token)
    {
        if (null === $this->profiler) {
            throw new \RuntimeException('Invalid profiler instance.');
        }

        $profile = $this->profiler->loadProfile($token);

        // In case no results were found
        if (!$profile instanceof Profile) {
            return array(array(), 0);
        }

        try {
            /** @var TranslationDataCollector $collector */
            $collector = $profile->getCollector('translation');
            $messages = $collector->getMessages();

            $transUnits = array();
            foreach ($messages as $message) {
                $transUnit = $this->storage->getTransUnitByKeyAndDomain($message['id'], $message['domain']);

                if ($transUnit instanceof TransUnit) {
                    $transUnits[] = $transUnit;
                } elseif (true === $this->createMissing) {
                    $transUnits[] = $transUnit = $this->transUnitManager->create($message['id'], $message['domain'], true);
                }

                // Also store the translation if profiler state was defined
                if (!$transUnit->hasTranslation($message['locale']) && $message['state'] === DataCollectorTranslator::MESSAGE_DEFINED) {
                    $file = $this->fileManager->getFor(sprintf('%s.%s.%s', $message['domain'], $message['locale'], $this->defaultFileFormat));

                    $this->transUnitManager->addTranslation($transUnit, $message['locale'], $message['translation'], $file, true);
                }
            }

            return array($transUnits, count($transUnits));

        } catch (\InvalidArgumentException $e) {

            // Translation collector is a 2.7 feature
            return array(array(), 0);
        }
    }
714642
public function addActivity($activity)
    {
        if (array_key_exists('to', $activity)) {
            $activity['to'] = $this->signToField($activity['to']);
        }

        return $this->makeHttpRequest("{$this->base_feed_url}/", 'POST', $activity, null, 'feed', 'write');
    }
1077341
private function activeDeclaration(int $tokenID): string
    {
        foreach ($this->declarations as $declarations) {
            foreach ($declarations as $name => $position) {
                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
                    return $name;
                }
            }
        }

        //Can not be detected
        return '';
    }
995022
public function parse(Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();

        $count = null;
        $vars = new ArrayExpression([], $lineno);
        $domain = null;
        $locale = null;
        if (!$stream->test(Token::BLOCK_END_TYPE)) {
            if ($stream->test('count')) {
                // {% trans count 5 %}
                $stream->next();
                $count = $this->parser->getExpressionParser()->parseExpression();
            }

            if ($stream->test('with')) {
                // {% trans with vars %}
                $stream->next();
                $vars = $this->parser->getExpressionParser()->parseExpression();
            }

            if ($stream->test('from')) {
                // {% trans from "messages" %}
                $stream->next();
                $domain = $this->parser->getExpressionParser()->parseExpression();
            }

            if ($stream->test('into')) {
                // {% trans into "fr" %}
                $stream->next();
                $locale = $this->parser->getExpressionParser()->parseExpression();
            } elseif (!$stream->test(Token::BLOCK_END_TYPE)) {
                throw new SyntaxError('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
            }
        }

        // {% trans %}message{% endtrans %}
        $stream->expect(Token::BLOCK_END_TYPE);
        $body = $this->parser->subparse([$this, 'decideTransFork'], true);

        if (!$body instanceof TextNode && !$body instanceof AbstractExpression) {
            throw new SyntaxError('A message inside a trans tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext());
        }

        $stream->expect(Token::BLOCK_END_TYPE);

        return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
    }
28022
public function getToken($token, $ip = null, $userAgent = null)
    {
        $query = $this->getTokenQuery($token, $ip, $userAgent);

        return $this->findOneWith($query);
    }