@param Interpretations\IRequestInterpretation $requestInterpretation
@param IScopeInterpreter                      $scopeInterpreter
@param O\IEvaluationContext                   $evaluationContext

@return IRequestQueryInterpreter
554023
protected function buildRequestQueryInterpreter(
            Interpretations\IRequestInterpretation $requestInterpretation,
            IScopeInterpreter $scopeInterpreter,
            O\IEvaluationContext $evaluationContext = null
    ) {
        return new RequestQueryInterpreter($requestInterpretation, $scopeInterpreter, $evaluationContext);
    }
833605
public function evaluateQuestion(array $questionRaw, PhpStringParser $parser, GeneratorDataObject $generator)
    {
        $iterator       = $this->iteratorValidator->retrieveValidIteration($questionRaw, $generator, $parser);
        $iteratorParser = clone $parser;

        foreach ($iterator as $iteration) {
            $iteratorParser->addVariable('iteration', $iteration);

            $origine = $iteratorParser->parse($questionRaw['iteration']['retrieveBy']);

            $question = new SimpleQuestion(
                $iteratorParser->parse($questionRaw['iteration']['text']),
                $questionRaw['setter'] . $origine
            );
            $question->setDefaultResponse((isset($questionRaw['iteration']['response']['default']) === true)
                    ? $iteratorParser->parse($questionRaw['iteration']['response']['default']) : null);
            $question->setRequired($questionRaw['required']);
            $question->setHelpMessage($questionRaw['helpMessage']);
            $question->setResponseType(new QuestionResponseTypeEnum($questionRaw['iteration']['response']['type']));

            $response = $this->context->ask($question);

            $questionName = $questionRaw['setter'];
            if ($response !== null) {
                $generator->getDto()->$questionName($origine, $response);
            }
        }

        return $generator;
    }
327979
public function getEvaluationByUserAndActivityParams(
        User $user,
        ActivityParameters $activityParams,
        $executeQuery = true
    )
    {
        return $this->evaluationRepo->findEvaluationByUserAndActivityParams(
            $user,
            $activityParams,
            $executeQuery
        );
    }
999543
private function evaluate(
        ClassArgumentObject $inputSource,
        ClassArgumentObject $matcher,
        ServerRequestInterface $httpRequest
    ) {
        return $matcher->getInstance()->match(
            $inputSource->getInstance()->getValue($httpRequest, $inputSource->getArgument()),
            $matcher->getArgument()
        );
    }
1139400
public function handle($request, Closure $next, ...$requestedScopes)
    {
        if (! $this->token->exists()) {
            return $next($request);
        }

        $providedScopes = $this->token->scopes;

        // If any of the requested scopes were not provided, throw an exception.
        $missingScopes = array_diff($requestedScopes, $providedScopes);
        if (count($missingScopes)) {
            $message = 'Requires a token with the following scopes: '.implode(', ', $missingScopes);
            throw new AccessDeniedHttpException($message);
        }

        return $next($request);
    }
659852
@Override
    public String evaluate(String request) throws EvaluationException {
        logger.debug("evaluating request: {}", request);

        RequestCtx req = null;
        ByteArrayInputStream is = new ByteArrayInputStream(request.getBytes());

        try {
            req = BasicRequestCtx.getInstance(is);
        } catch (ParsingException pe) {
            logger.error("Error parsing request:\n" + request, pe);
            throw new EvaluationException("Error parsing request:\n" + request);
        }

        ResponseCtx res = evaluate(req);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        res.encode(os, new Indenter());

        if (logger.isDebugEnabled()) {
            logger.debug("response is: {}", os.toString());
        }
        return os.toString();
    }
78573
protected function _getScope(EntityInterface $entity)
    {
        $scope = [];
        $config = $this->getConfig();

        // If scope are specified and data for all scope fields is not
        // provided we cannot calculate new order
        if ($config['scope']) {
            $scope = $entity->extract($config['scope']);
            if (count($scope) !== count($config['scope'])) {
                return false;
            }

            // Modify where clauses when NULL values are used
            foreach ($scope as $field => $value) {
                if (is_null($value)) {
                    $scope[$field . ' IS'] = $value;
                    unset($scope[$field]);
                }
            }
        }

        return $scope;
    }
1370786
public static function evaluateEelExpression($expression, EelEvaluatorInterface $eelEvaluator, array $contextVariables, array $defaultContextConfiguration = [])
    {
        $matches = null;
        if (!preg_match(Package::EelExpressionRecognizer, $expression, $matches)) {
            throw new Exception('The EEL expression "' . $expression . '" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?', 1410441849);
        }

        $defaultContextVariables = self::getDefaultContextVariables($defaultContextConfiguration);
        $contextVariables = array_merge($defaultContextVariables, $contextVariables);

        if (isset($contextVariables['q'])) {
            throw new Exception('Context variable "q" not allowed, as it is already reserved for FlowQuery use.', 1410441819);
        }

        $contextVariables['q'] = function ($element) {
            return new FlowQuery\FlowQuery(is_array($element) || $element instanceof \Traversable ? $element : [$element]);
        };

        $context = new ProtectedContext($contextVariables);
        $context->whitelist('q');

        return $eelEvaluator->evaluate($matches['exp'], $context);
    }
762140
public static void putServiceTicketInRequestScope(final RequestContext context, final ServiceTicket ticketValue) {
        context.getRequestScope().put(PARAMETER_SERVICE_TICKET_ID, ticketValue.getId());
    }
923792
public function invoke(MethodInvocation $methodInvocation, MethodCall $methodCall, Message $requestMessage)
    {
        $methodInvocationType = TypeDescriptor::create(MethodInvocation::class);

        $hasMethodInvocation = false;
        $argumentsToCallInterceptor = [];
        $interceptedInstanceType = TypeDescriptor::createFromVariable($methodInvocation->getInterceptedInstance());
        $referenceSearchServiceTypeDescriptor = TypeDescriptor::create(ReferenceSearchService::class);
        $messageType = TypeDescriptor::create(Message::class);

        foreach ($this->interceptorInterfaceToCall->getInterfaceParameters() as $parameter) {
            $resolvedArgument = null;

            foreach ($methodCall->getMethodArguments() as $methodArgument) {
                if ($methodArgument->hasSameTypeAs($parameter)) {
                    $resolvedArgument = $methodArgument->value();
                }
            }

            if (!$resolvedArgument && $parameter->hasType($methodInvocationType)) {
                $hasMethodInvocation = true;
                $resolvedArgument = $methodInvocation;
            }

            if (!$resolvedArgument && $parameter->hasType($interceptedInstanceType)) {
                $resolvedArgument = $methodInvocation->getInterceptedInstance();
            }

            if (!$resolvedArgument && $parameter->hasType($messageType)) {
                $resolvedArgument = $requestMessage;
            }

            if (!$resolvedArgument) {
                if ($methodInvocation->getInterceptedInterface()->hasMethodAnnotation($parameter->getTypeDescriptor())) {
                    $resolvedArgument = $methodInvocation->getInterceptedInterface()->getMethodAnnotation($parameter->getTypeDescriptor());
                }
                if ($methodInvocation->getInterceptedInterface()->hasClassAnnotation($parameter->getTypeDescriptor())) {
                    $resolvedArgument = $methodInvocation->getInterceptedInterface()->getClassAnnotation($parameter->getTypeDescriptor());
                }
            }

            if (!$resolvedArgument) {
                foreach ($methodInvocation->getEndpointAnnotations() as $endpointAnnotation) {
                    if (TypeDescriptor::createFromVariable($endpointAnnotation)->equals($parameter->getTypeDescriptor())) {
                        $resolvedArgument = $endpointAnnotation;
                        break;
                    }
                }
            }

            if (!$resolvedArgument) {
                if ($parameter->hasType($referenceSearchServiceTypeDescriptor)) {
                    $resolvedArgument = $this->referenceSearchService;
                }
            }

            if (!$resolvedArgument && !$parameter->doesAllowNulls()) {
                throw MethodInvocationException::create("{$this->interceptorInterfaceToCall} can't resolve argument for parameter with name `{$parameter->getName()}`. Maybe your docblock type hint is not correct?");
            }

            $argumentsToCallInterceptor[] = $resolvedArgument;
        }

        $returnValue = call_user_func_array(
            [$this->referenceToCall, $this->interceptorInterfaceToCall->getMethodName()],
            $argumentsToCallInterceptor
        );

        if (!$hasMethodInvocation) {
            return $methodInvocation->proceed();
        }

        return $returnValue;
    }
402731
public static void internalSetAndInitRequestScope (@Nonnull final IRequestScope aRequestScope)
  {
    ValueEnforcer.notNull (aRequestScope, "RequestScope");
    ValueEnforcer.isTrue (ScopeManager::isGlobalScopePresent,
                          "No global context present! May be the global context listener is not installed?");

    // Happens if an internal redirect happens in a web-application (e.g. for
    // 404 page)
    final IRequestScope aExistingRequestScope = s_aRequestScopeTL.get ();
    if (aExistingRequestScope != null)
    {
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("A request scope is already present - will overwrite it: " + aExistingRequestScope.toString ());
      if (aExistingRequestScope.isValid ())
      {
        // The scope shall be destroyed here, as this is most probably a
        // programming error!
        LOGGER.warn ("Destroying the old request scope before the new one gets initialized!");
        _destroyRequestScope (aExistingRequestScope);
      }
    }

    // set request context
    s_aRequestScopeTL.set (aRequestScope);

    // Now init the scope
    aRequestScope.initScope ();

    // call SPIs
    ScopeSPIManager.getInstance ().onRequestScopeBegin (aRequestScope);
  }
754437
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $container = ContainerScope::getContainer();
        if (empty($container)) {
            throw new ScopeException("Unable to run SpiralCommand outside of IoC scope.");
        }

        $reflection = new \ReflectionMethod($this, 'perform');
        $reflection->setAccessible(true);

        /** @var ResolverInterface $resolver */
        $resolver = $container->get(ResolverInterface::class);

        try {
            list($this->input, $this->output) = [$input, $output];

            //Executing perform method with method injection
            return $reflection->invokeArgs($this, $resolver->resolveArguments(
                $reflection,
                compact('input', 'output')
            ));
        } finally {
            list($this->input, $this->output) = [null, null];
        }
    }
842747
public static void putServiceOriginalUrlIntoRequestScope(final RequestContext requestContext, final WebApplicationService service) {
        requestContext.getRequestScope().put("originalUrl", service.getOriginalUrl());
    }
621978
public function scopeRequestWith($query, Request $request)
    {
        if ($request->has('with')) {
            $query->with($request->input('with'));
        }

        return $query;
    }
468434
public function asEvaluator(IEvaluationContext $context = null)
    {
        return CompiledEvaluator::fromExpressions([Expression::returnExpression($this)], $context);
    }
977926
private function normalizeRequest(RequestInterface $request): RequestInterface
    {
        $uri = $request->getUri();
        $updated = false;

        $normalizedPath = preg_replace('~/{2,}~', '/', $uri->getPath());

        $normalizedPath = preg_replace('~/\.(/|$)~', '/', $normalizedPath);
        do {
            $normalizedPath = preg_replace('~/[^/]+(?<!\.\.)/+\.\.(/|$)~', '/', $normalizedPath, 1, $count);
        } while ($count);

        $normalizedPath = $this->decodePercentEncoding($normalizedPath);

        if ($uri->getPath() !== $normalizedPath) {
            $uri = $uri->withPath($normalizedPath);
            $updated = true;
        }

        $normalizedQuery = $this->decodePercentEncoding($uri->getQuery());

        if ($uri->getQuery() !== $normalizedQuery) {
            $uri = $uri->withQuery($normalizedQuery);
            $updated = true;
        }

        if ($updated) {
            return $request->withUri($uri);
        }

        return $request;
    }
1196666
public function validateRequest(RequestInterface $request, ResponseInterface $response)
    {
        $providerName        = $request->request('provider');
        $providerUserId      = $request->request('provider_user_id');
        $providerAccessToken = $request->request('provider_access_token');

        if (! $providerName || ! $providerUserId || ! $providerAccessToken) {
            $response->setError(
                400,
                'invalid_request',
                'One or more missing parameter: "provider", "provider_user_id" and "provider_access_token" are required'
            );

            return false;
        }

        $provider = isset($this->providers[$providerName]) ? $this->providers[$providerName] : null;

        if (! $provider instanceof ProviderInterface) {
            $response->setError(400, 'invalid_request', 'Unknown provider selected');

            return false;
        }

        try {
            $errorMessage = '';
            if (! $provider->validate($providerUserId, $providerAccessToken, $errorMessage)) {
                $response->setError(401, 'invalid_grant', 'Invalid third party credentials: ' . $errorMessage);

                return false;
            }
        } catch (ClientException $e) {
            $response->setError($e->getCode(), 'provider_client_error', $e->getMessage());

            return false;
        } catch (Exception $e) {
            $response->setError(500, 'provider_error', $e->getMessage());

            return false;
        }

        $token       = $request->request('access_token');
        $accessToken = $token ? $this->accessTokenMapper->findByToken($token) : null;

        if ($accessToken instanceof Entity\AccessToken && $accessToken->isExpired()) {
            $response->setError(401, 'invalid_grant', 'Access token is expired');

            return false;
        }

        $thirdPartyUser = $this->thirdPartyMapper->findByProvider($provider);

        switch (true) {
            // a known user tries to connect with third party credentials owned by another user? issue an error
            case ($accessToken instanceof Entity\AccessToken
                    && $thirdPartyUser instanceof Entity\ThirdParty
                    && $thirdPartyUser->getUser() !== $accessToken->getUser()):
                $response->setError(400, 'invalid_request', 'Another user is already registered with same credentials');

                return false;

            // known third party credentials? update the data and grab the user form it
            case ($thirdPartyUser instanceof Entity\ThirdParty):
                $thirdPartyUser->setData($provider->getUserData());
                $user = $thirdPartyUser->getUser();
                break;

            // valid access token? grab the user form it
            case ($accessToken instanceof Entity\AccessToken):
                $user = $accessToken->getUser();
                break;

            // no third party credentials or access token? it's a new user
            default:
                $userClass = $this->moduleOptions->getUserEntityClassName();
                $user      = new $userClass();
        }

        // in case 3 and 4 we need to connect the user with new third party credentials
        if (! $thirdPartyUser instanceof Entity\ThirdParty) {
            $this->connectUserToThirdParty($user, $provider);
        }

        $this->userMapper->save($user);
        $this->user = $user;

        return true;
    }