@param Request          $request
@param \ReflectionClass $reflectionClass
@param UrlAnnotation    $urlAnnotation

@return Response
426471
private function fetchData(Request $request, \ReflectionClass $reflectionClass, UrlAnnotation $urlAnnotation)
	{
		if($this->cache && $this->cacheModel instanceof Cache){
			$this->cacheModel->setRequest($request);
			$this->cacheModel->setReflectionClass($reflectionClass);
		}else{
			$this->cache = false;
		}
		try {
			$cacheRequest = false;
			if ($this->cache && $this->cacheModel->exist()) {
				$cacheRequest = true;
				$response     = new Response(200, [], $this->cacheModel->get());
			}
			if (!$cacheRequest) {
				/** @var IProtocol $class */
				$class = (new \ReflectionClass('\Scraper\\Scraper\\Protocol\\' . ucfirst(strtolower($urlAnnotation->protocol))))
					->newInstanceArgs([$reflectionClass, $request, $urlAnnotation]);
				/** @var Response $response */
				$response = $class->execute();
			}
		} catch (\Exception $e) {
			echo 'Exception: ', $e->getMessage(), "\n";
		}

		try {
			if (in_array(strtolower($urlAnnotation->contentType), ['html', 'json', 'text', 'xml'])) {
				/** @var IContentType $class */
				$class = (new \ReflectionClass('\Scraper\\Scraper\\ContentType\\' . ucfirst(strtolower($urlAnnotation->contentType))))
					->newInstanceArgs([$reflectionClass, $request, $response, $urlAnnotation, $this->cacheModel]);
			} else {
				/** @var IContentType $class */
				$class = (new \ReflectionClass($urlAnnotation->contentType))
					->newInstanceArgs([$reflectionClass, $request, $response, $urlAnnotation]);
			}

			/** @var Response $response */
			$response = $class->execute();
		} catch (\Exception $e) {
			echo 'Exception: ', $e->getMessage(), "\n";
		}

		return $response;
	}
841691
protected function createInstance(\ReflectionClass $reflectedClass)
    {
        $constructor = $reflectedClass->getConstructor();

        if ($constructor && $constructor->getNumberOfRequiredParameters() > 0) {
            throw new \RuntimeException('Unable to hydrate an object requiring constructor param');
        }

        return $reflectedClass->newInstance();
    }
209338
private function readClassAnnotation(\ReflectionClass $reflectionClass, $annotationName)
    {
        $annotationClass = "FOS\\RestBundle\\Controller\\Annotations\\$annotationName";

        if ($annotation = $this->annotationReader->getClassAnnotation($reflectionClass, $annotationClass)) {
            return $annotation;
        }
    }
730970
public function run(HttpRequest $request = null)
    {
        if (!$this->container->getSetting('debug')) {
            error_reporting(0);
        } else {
            error_reporting(E_ALL);
        }
        
        if (!$request) {
            $request = $this->container->getRequest();
        }
        
        try {
            $parsed = $this->container->getRouter()->parse($request, $this->container->getRoutes());

            if ($parsed['found'] || $this->container->hasRoute('notFound')) {
                if (is_string($parsed['action'])) {
                    # Extract class controller and method
                    list($controller, $method) = explode('::', $parsed['action']);

                    # initialize arguments
                    $arguments = array();
                    # Create a reflection method
                    $reflectionMethod = new \ReflectionMethod($controller, $method);
                    $reflectionParams = $reflectionMethod->getParameters();
                    # Create arguments
                    foreach ($reflectionParams as $param) {
                        if ($paramClass = $param->getClass()) {
                            $className = $paramClass->name;
                            if ($className === 'MVC\\MVC' || $className === '\\MVC\\MVC') {
                                $arguments[] = $this;
                            } elseif ($className === 'MVC\\Server\\HttpRequest' || $className === '\\MVC\\Server\\HttpRequest') {
                                $arguments[] = $request;
                            }
                        } else {
                            foreach ($parsed['params'] as $keyRouteParam => $valueRouteParam) {
                                if ($param->name === $keyRouteParam) {
                                    $arguments[] = $valueRouteParam;
                                    break;
                                }
                            }
                        }
                    }

                    $response = call_user_func_array($reflectionMethod->getClosure(new $controller()), $arguments);

                    if (is_array($response) && !isset($response['body'])) {
                        throw new \LogicException("Invalid response array. Array response haven't body. Expected array('body' => 'string')");
                    } elseif (is_string($response)) {
                        $response = array('body' => $response);
                    }
                } elseif(is_callable($parsed['action'])) {
                    $this->container->getRequest()->params = $parsed['params'];

                    $response = call_user_func_array($parsed['action'], array_values($parsed['params']));
                } else {
                    throw new \LogicException('Route haven\'t action.');
                }
                if ($this->container->hasProvider('monolog')) {
                    $this->container->providers['monolog']->addInfo($response, $parsed);
                }
                $this->container->getResponse()->render($response);
            } else {
                if ($this->container->getSetting('debug')) {
                    throw new \LogicException(sprintf('Route or Resource "%s" not found.', $request->url));
                }
                $this->defaultNotFound();
            }
        } catch (\Exception $e) {
            Error::run($e);
        }
    }
202874
protected function process(RequestInterface $request, string $responseClassName = null): ?ResponseInterface
    {
        $context = SerializationContext::create();

        $request = $this->serializer->serialize($request, $this->serializerFormat, $context);

        $response = $this->httpClient->post('', ['body' => $request]);

        if (!$responseClassName) {
            return null;
        }

        return $this->serializer->deserialize($response->getBody(), $responseClassName, $this->deserializerFormat);
    }
133314
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        // Let's recreate a new context object (because request can be modified by the filters)
        $context = new SplashRequestContext($request);
        $context->setUrlParameters($this->splashRoute->getFilledParameters());
        // Let's pass everything to the controller:
        $args = $this->parameterFetcherRegistry->toArguments($context, $this->splashRoute->getParameters());
        $action = $this->splashRoute->getMethodName();
        $controller = $this->controller;

        try {
            $response = SplashUtils::buildControllerResponse(
                function () use ($controller, $action, $args) {
                    return $controller->$action(...$args);
                },
                $this->mode,
                $this->debug
            );
        } catch (SplashException $e) {
            throw new SplashException($e->getMessage(). ' (in '.$this->splashRoute->getControllerInstanceName().'->'.$this->splashRoute->getMethodName().')', $e->getCode(), $e);
        }
        return $response;
    }
136158
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        /**
         * If request is modified by a middleware, and as ServerRequestInterface is immutable, given $request must
         * replace current ServerRequestInterface in RequestHandler PSR-11 container.
         */
        $this->container->set("request", $request);

        $middlewareEntry = current($this->middlewareSequence);
        next($this->middlewareSequence);

        // If middleware sequence is exhausted, controller is instantiated and run.
        if ($middlewareEntry === false) {

            /**
             * @var Route $route
             */
            $route = $this->container->get("route");

            $controllerData = explode("::", $route->controller);
            if (count($controllerData) !== 2) {

                throw new RuntimeException("Invalid controller declaration for route {$route->name} (expecting '\\Namespace\\Class::method' format)");

            }

            $controllerClass = $controllerData[0];
            if (class_exists($controllerClass) === false) {

                throw new RuntimeException("Invalid controller declaration for route {$route->name} (unknown class {$controllerClass})");

            }

            /**
             * @var $controller AbstractController
             */
            $controller = new $controllerClass($this->container);

            $controllerMethod = $controllerData[1];
            if (method_exists($controller, $controllerMethod) === false) {

                throw new BadMethodCallException("{$controllerClass}::{$controllerMethod} declared in routes doesn't exists in {$controllerClass}");

            }

            /**
             * @var $response ResponseInterface
             */
            $response = $controller->{$controllerMethod}();
            if (($response instanceof ResponseInterface) === false) {

                throw new LogicException("Method {$controllerMethod} must return an instance of PSR-7 ResponseInterface");

            }

            return $response;

        } else {

            $middlewareFQCN = is_array($middlewareEntry) ? $middlewareEntry[0] : $middlewareEntry;
            $middlewareParams = is_array($middlewareEntry) && count($middlewareEntry) > 1 ? $middlewareEntry[1] : null;

            /**
             * @var $middleware MiddlewareInterface
             */
            $middleware = new $middlewareFQCN($middlewareParams);
            if (($middleware instanceof MiddlewareInterface) === false) {

                throw new LogicException("Middleware {$middlewareFQCN} must implements PSR-11 MiddlewareInterface");

            }

            return $middleware->process($request, $this);

        }
    }
157286
public function api(Request $request)
	{
		$reflectClassRequest = new \ReflectionClass($request);
		$className           = $reflectClassRequest->getShortName();
		$className           = str_replace('Request', 'Api', $className);
		$namespace           = str_replace('\Request', '\Api\\', $reflectClassRequest->getNamespaceName());
		/** @var UrlAnnotation $urlAnnotation */
		$urlAnnotation = Reader::read($request);
		$data          = $this->fetchData($request, $reflectClassRequest, $urlAnnotation);

		$reflectClassName = new \ReflectionClass($namespace . $className);
		$instance         = $reflectClassName->newInstanceArgs([$request, $data, $urlAnnotation]);
		return call_user_func([$instance, 'execute']);
	}
1177161
public function validateReflectionClassForAccessorNotPrivate(\ReflectionClass $reflectionClass)
    {
        $methods = array_merge(
            $reflectionClass->getMethods(\ReflectionMethod::IS_PROTECTED),
            $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC)
        );

        if (empty($methods)) {
            return new CoverFishMessageError(
                CoverFishMessageError::PHPUNIT_REFLECTION_NO_NOT_PRIVATE_METHODS_FOUND, null
            );
        }

        return true;
    }
125519
public function analyzeRequest(
        Request $request,
        Reader $reader,
        ReflectionMethod $method
    ) {
        /**
         * Annotations load.
         */
        $methodAnnotations = $reader->getMethodAnnotations($method);

        /**
         * Every annotation found is parsed.
         */
        foreach ($methodAnnotations as $annotation) {
            if ($annotation instanceof Annotation) {
                $this->analyzeAnnotation(
                    $request,
                    $method,
                    $annotation,
                    $this->resolverStack
                );
            }
        }
    }
1158008
private function invalidArrayParameterException(\ReflectionFunctionAbstract $controller, RequestParam $annotation) : HttpBadRequestException
    {
        return new HttpBadRequestException(sprintf(
            '%s() expects an array for %s parameter "%s" (bound to $%s), string given.',
            $this->reflectionTools->getFunctionName($controller),
            $annotation->getParameterType(),
            $annotation->getName(),
            $annotation->getBindTo()
        ));
    }
242504
public function loadMetadataForClass(\ReflectionClass $reflectionClass)
    {
        $className = $reflectionClass->getName();
        $classMetadata = new ClassMetadata($className);
        $classMetadata->fileResources[] = $reflectionClass->getFileName();

        $encryptionAnnotation = $this->reader->getClassAnnotation(
            $reflectionClass,
            'Jagilpe\\EncryptionBundle\\Annotation\\EncryptedEntity'
        );
        /** @var EncryptedEntity $encryptionAnnotation */
        if ($encryptionAnnotation) {
            $classMetadata->encryptionEnabled = $encryptionAnnotation->enabled;
            $classMetadata->encryptionMode = $encryptionAnnotation->mode;

            $encryptedFileAnnotation = $this->reader->getClassAnnotation(
                $reflectionClass,
                'Jagilpe\\EncryptionBundle\\Annotation\\EncryptedFile'
            );

            /** @var EncryptedFile $encryptedFileAnnotation */
            if ($encryptedFileAnnotation) {
                $classMetadata->encryptedFile = $encryptedFileAnnotation->enabled;
                $classMetadata->encryptedFileMode = $encryptedFileAnnotation->mode;
            }

            foreach ($reflectionClass->getProperties() as $reflectionProperty) {
                $propertyAnnotation = $this->reader->getPropertyAnnotation(
                    $reflectionProperty,
                    'Jagilpe\\EncryptionBundle\\Annotation\\EncryptedField'
                );

                /** @var EncryptedField $propertyAnnotation */
                if ($propertyAnnotation) {
                    $propertyMetadata = new PropertyMetadata($reflectionClass->getName(), $reflectionProperty->getName());
                    $propertyMetadata->encrypted = $propertyAnnotation->enabled;

                    $classMetadata->addPropertyMetadata($propertyMetadata);
                }
            }
        }
        else {
            $classMetadata->encryptionEnabled = false;
        }

        return $classMetadata;
    }
1184284
public function evaluateAnnotation(
        Request $request,
        Annotation $annotation,
        ReflectionMethod $method
    ) : ? string {
        /**
         * Annotation is only loaded if is type-of AnnotationEntity.
         */
        if ($annotation instanceof CreatePaginator) {

            /**
             * Creating new instance of desired entity.
             */
            $entity = $this
                ->entityProvider
                ->evaluateEntityNamespace($annotation->getEntityNamespace());

            /**
             * We create a basic query builder.
             */
            $queryBuilder = $this->createQueryBuilder($entity);

            /**
             * Every paginator evaluator is evaluated in this code.
             *
             * Every evaluated is defined using a Dependency Injection tag,
             * and accumulated in a Collector.
             * This collector evaluator, evaluates each one injected previously
             * by the DI Component
             */
            $this
                ->paginatorEvaluatorCollector
                ->evaluate($queryBuilder, $annotation);

            $paginator = new DoctrinePaginator($queryBuilder, true);

            /**
             * Calculating limit of elements per page. Value can be evaluated
             * using as reference a Request attribute value.
             */
            $annotationLimit = $annotation->getLimit() ?? $this->defaultLimitPerPage;
            $limitPerPage = is_int($annotationLimit)
                ? $annotationLimit
                : (int) $this
                    ->providerCollector
                    ->provide($annotationLimit);

            /**
             * Calculating page to fetch. Value can be evaluated using as
             * reference a Request attribute value.
             */
            $annotationPage = $annotation->getPage() ?? $this->defaultPage;
            $page = is_int($annotationPage)
                ? $annotationPage
                : (int) $this
                    ->providerCollector
                    ->provide($annotationPage);

            /**
             * If attributes is not null, this bundle will place in the method
             * parameter named as defined a new PaginatorAttributes Value Object
             * with all needed data.
             */
            $this->evaluateAttributes(
                $request,
                $annotation,
                $paginator,
                $limitPerPage,
                $page
            );

            /**
             * Calculating offset, given number per pageand page.
             */
            $offset = $limitPerPage * ($page - 1);

            /**
             * Retrieving the Paginator iterator.
             */
            $paginator
                ->getQuery()
                ->setFirstResult($offset)
                ->setMaxResults($limitPerPage);

            /**
             * Get the parameter name. If not defined, is set as defined in
             * parameters.
             */
            $parameterName = $annotation->getName() ?: $this->defaultName;
            $parameterType = $this->getParameterType(
                $method,
                $parameterName
            );

            $dql = $paginator->getQuery()->getDQL();
            $paginator = $this
                ->decidePaginatorFormat(
                    $paginator,
                    $parameterType,
                    $limitPerPage,
                    $page
                );

            $request->attributes->set(
                $parameterName,
                $paginator
            );

            return $dql;
        }

        return null;
    }
413979
public static function createResourceForClass(\ReflectionClass $reflectionClass)
    {
        $metadata = array();

        if ($constructor = $reflectionClass->getConstructor()) {
            $metadata['__construct'] = self::getResourceMetadataForMethod($constructor);
        }

        foreach (self::getSetters($reflectionClass) as $reflectionMethod) {
            $metadata[$reflectionMethod->name] = self::getResourceMetadataForMethod($reflectionMethod);
        }

        return new AutowireServiceResource($reflectionClass->name, $reflectionClass->getFileName(), $metadata);
    }
1091764
public function handle(\ReflectionParameter $parameter)
    {
        $class = $parameter->getDeclaringClass();
        $className = $class->implementsInterface(WeavedInterface::class) ? $class->getParentClass()->getName() : $class->name;
        $method = $parameter->getDeclaringFunction()->name;
        $msg = sprintf('$%s in %s::%s()', $parameter->name, $className, $method);

        throw new ParameterException($msg, Code::BAD_REQUEST);
    }
1045225
public function process(HTTPRequest $request, callable $delegate)
    {
        try {
            $response = $delegate($request);
        } catch (HTTPResponse_Exception $ex) {
            $response = $ex->getResponse();
        }
        if (!$response) {
            return null;
        }

        // Update state based on current request and response objects
        $this->augmentState($request, $response);

        // Update state based on deprecated HTTP settings
        HTTP::augmentState($request, $response);

        // Add all headers to this response object
        $this->applyToResponse($response);

        if (isset($ex)) {
            throw $ex;
        }
        return $response;
    }
72327
public function parse(Request $request)
    {
        foreach($this->rules as $url => $items)
        {
            $result = $this->checkUrl($request, $url, $params);
            if($result['result'] || $result['resultIgnoreCase'])
            {
                foreach($items as $item)
                {
                    if(
                        ($result['result'] || ($this->ignoreCase || $item['annotation']->ignoreCase)) &&
                        $this->checkMethod($request, $item['annotation']->method) &&
                        $this->checkDomain($request, $item['annotation']->domain, $domainParams) &&
                        $this->checkParamsGet($request, $item['annotation']->paramsGet) &&
                        $this->checkParamsPost($request, $item['annotation']->paramsPost) &&
                        $this->checkHeader($request, $item['annotation']->header) &&
                        $this->checkRequestMime($request, $item['annotation']->requestMime)
                    )
                    {
                        $params = array_merge($params, $domainParams);
                        return [
                            'params'        => $params,
                            'callable'      => $this->parseCallable($params, $item['callable']),
                            'middlewares'   => $item['middlewares'] ?? [],
                            'wsConfig'      => $item['wsConfig'],
                        ];
                    }
                }
            }
        }
        return null;
    }