Handle an incoming request.

@param  JsonRpcRequest $request

@return mixed
@throws JsonRpcException
@throws \ReflectionException
960372
public function handle($request)
    {
        $api_params = !empty($request->call->params) ? (array)$request->call->params : [];

        // подготавливаем аргументы для вызова метода
        $reflectionMethod = new \ReflectionMethod($request->controller, $request->method);
        $errors = [];
        $args = [];

        foreach ($reflectionMethod->getParameters() as $i => $parameter) {

            $value = $api_params[$parameter->getName()] ?? null;

            // если аргумент не передан
            if (null === $value) {
                // если он обязателен
                if (!$parameter->isOptional()) {
                    $errors[] = [
                        'code'        => 'required_field',
                        'message'     => 'Не передан либо пустой обязательный параметр',
                        'object_name' => $parameter->getName(),
                    ];
                } else {
                    // получим значение аргумента по умолчанию
                    $value = $parameter->getDefaultValue();
                }
            } else {
                // Проверяем тип
                $parameterType = strtolower(class_basename((string)$parameter->getType()));
                switch ($parameterType) {
                    case 'int':
                    case 'integer':
                        $parameterType = 'integer';
                        break;
                    case 'float':
                    case 'double':
                        $parameterType = 'double';
                        break;
                    case 'boolean':
                    case 'bool':
                        $parameterType = 'boolean';
                        break;
                    case 'stdclass':
                        $parameterType = 'object';
                        break;
                }

                if (null !== $parameter->getType() && \gettype($value) !== $parameterType) {
                    $errors[] = [
                        'code'        => 'invalid_parameter',
                        'message'     => 'Передан аргумент неверного типа',
                        'object_name' => $parameter->getName(),
                    ];
                }
            }

            // установим переданное значение
            $args[$i] = $value;
        }

        if (\count($errors) > 0) {
            throw new JsonRpcException(JsonRpcException::CODE_INVALID_PARAMETERS, null, $errors);
        }

        $request->params = $args;

        return true;
    }
669857
protected function processJson( \stdClass $request )
	{
		$response = array(
			'jsonrpc' => '2.0',
		);

		try
		{
			if( !isset( $request->method ) )
			{
				$msg = sprintf( 'Required attribute "%1$s" missing in request', 'method' );
				throw new \Aimeos\Controller\ExtJS\Exception( $msg, -32600 );
			}

			if( !isset( $request->params ) ) {
				throw new \Aimeos\Controller\ExtJS\Exception( 'Required parameters are missing in request', -32600 );
			}

			$response['result'] = $this->callMethod( $request->method, $request->params );
		}
		catch( \Exception $e )
		{
			$response['error'] = array(
				'code' => ( $e->getCode() != 0 ? $e->getCode() : -1 ),
				'message' => $e->getMessage(),
			);
		}

		if( !isset( $request->id ) ) {
			return null;
		}

		$response['id'] = $request->id;
		return $response;
	}
1341360
public function handle($request)
	{
		$entity = $this->repository()->findById($request->getId());

        $this->authorize($request, $entity);

        if ($relatedEntity = $this->getProperty($entity, $this->field())) {
            return $this->response()->resource($request,
                new Item($relatedEntity, $this->transformer())
            );
        }

        return $this->response()->resource($request, new NullResource());
	}
327096
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (empty($this->handler)) {
            throw new HttpException("Unable to run HttpCore, no handler is set.");
        }

        return $this->pipeline->withHandler($this->handler)->handle($request);
    }
654434
public function toResponse($request)
    {
        return tap(response()->json(
            $this->wrap(
                $this->resource->resolve($request),
                array_merge_recursive(
                    $this->paginationInformation($request),
                    $this->resource->with($request),
                    $this->resource->additional
                )
            ),
            $this->calculateStatus()
        ), function ($response) use ($request) {
            $response->original = $this->resource->resource->pluck('resource');

            $this->resource->withResponse($request, $response);
        });
    }
134841
public function execute( Request $request )
    {
        $controllerClass = $request->attributes->get('_controller');
        if( !($this->isJwtRequired($controllerClass))) {
            return null;
        }

        if( !$this->authoriser->isAuthorised( $request ) ) {
            return new JsonResponse( ['error' => 'Invalid token'], 403 );
        }
        return null;
    }
435271
public function setRequest(JsonRequest $request)
    {
        $this->id = $request->getId();
        $this->jsonrpc = $request->getJsonrpc();
        $this->method = $request->getMethod();
        $this->request = $request;

        if (!$request->getResponse()) {
            $request->setResponse($this);
        }

        return $this;
    }
1298909
protected function doRequestInProcess($request)
    {
        $response = parent::doRequestInProcess($request);

        $this->profiler = false;

        return $response;
    }
616745
protected function getJsonRpcCall(string $request) : JsonRpcCall
    {
        $jsonRpcCall = $this->jsonRpcCallSerializer->deserialize($request);

        $event = new AcknowledgeEvent\OnRequestReceivedEvent($request, $jsonRpcCall);
        $this->dispatchJsonRpcEvent($event::EVENT_NAME, $event);

        return $jsonRpcCall;
    }
709230
public function handle($request)
    {
        try {
            $this->app['events']->fire('kernel.handling', [$request]);

            $request->enableHttpMethodParameterOverride();

            $response = $this->sendRequestThroughRouter($request);
        } catch (Exception $e) {
            $this->reportException($e);

            $response = $this->renderException($request, $e);
        } catch (Throwable $e) {
            $this->reportException($e = new FatalThrowableError($e));

            $response = $this->renderException($request, $e);
        }

        $this->app['events']->fire('kernel.handled', [$request, $response]);

        return $response;
    }
875365
public function handle(Request $request)
    {
        try {
            $restRequest = new RestRequest($this->config, $request->getMethod(), $request->getUri(), $request->getContent());
            $restResponse = $this->adapter->processRequest($restRequest);
        } catch (\Exception $e) {
            if (true === $this->debugEnabled()) {
                throw $e;
            }
            $restResponse = $this->adapter->handleException($e);
        }
        return new Response($restResponse->getContent(), $restResponse->getStatus(), $restResponse->getHeaders());
    }
594438
protected function handleRequest(ehough_shortstop_api_HttpRequest $request)
    {
        $method  = self::_getMethod($request);
        $url     = $request->getUrl()->toString();
        $body    = $request->getEntity() === null ? null : $request->getEntity()->getContent();
        $options = self::_buildOptionsArray($request);

        $rawResponse = @http_request($method, $url, $body, $options, $this->_info);

        if ($rawResponse === false || ! empty($this->_info[self::$_info_error])) {

            throw new Exception($this->_info[self::$_info_responsecode] . ': ' . $this->_info[self::$_info_error]);
        }

        return $rawResponse;
    }
468821
public function handleRPCMethod(PhpXmlRpc\Request $request) {
        $username=$request->getParam(1)->scalarval();
        $password=$request->getParam(2)->scalarval();
        
        if($this->authenticate($username, $password)) {
            $encoder=new PhpXmlRpc\Encoder();
            $method=str_replace(array('blogger.', 'metaWeblog.', 'kapost.'), '', $request->methodname);
            
            if(!in_array($request->methodname, $this->exposed_methods) || !method_exists($this, $method)) {
                return $this->httpError(403, _t('KapostService.METHOD_NOT_ALLOWED', '_Action "{method}" is not allowed on class Kapost Service.', array('method'=>$request->methodname)));
            }
            
            
            //Pack params into call to method if they are not the authentication parameters
            $params=array();
            for($i=0;$i<$request->getNumParams();$i++) {
                if($i!=1 && $i!=2) {
                    $params[]=$encoder->decode($request->getParam($i));
                }
            }
            
            
            //Convert the custom fields to an associtive array
            if(array_key_exists(1, $params) && is_array($params[1]) && array_key_exists('custom_fields', $params[1])) {
                $params[1]['custom_fields']=$this->struct_to_assoc($params[1]['custom_fields']);
            }
            
            
            //If transactions are supported start one for newPost and editPost
            if(($method=='newPost' || $method=='editPost') && DB::getConn()->supportsTransactions()) {
                DB::getConn()->transactionStart();
            }
            
            
            //Call the method
            try {
                $response=call_user_func_array(array($this, $method), $params);
                if($response instanceof PhpXmlRpc\Response) {
                    //If transactions are supported check the response and rollback in the case of a fault
                    if(($method=='newPost' || $method=='editPost' || $method=='newMediaObject') && DB::getConn()->supportsTransactions()) {
                        if($response->faultCode()!=0) {
                            DB::getConn()->transactionRollback();
                        }else {
                            DB::getConn()->transactionEnd();
                        }
                    }
                    
                    return $response; //Response is already encoded so return
                }
            }catch(ValidationException $e) {
                if(DB::getConn()->supportsTransactions()) {
                    DB::getConn()->transactionRollback();
                }
                
                return new PhpXmlRpc\Response(0, 400, $e->getMessage());
            }
            
            //Encode the response
            $response=$encoder->encode($response);
            if(is_object($response) && $response instanceof PhpXmlRpc\Value) {
                $response=new PhpXmlRpc\Response($response);
                
                if(($method=='newPost' || $method=='editPost' || $method=='newMediaObject') && DB::getConn()->supportsTransactions()) {
                    if($response->faultCode()!=0) {
                        DB::getConn()->transactionRollback();
                    }else {
                        DB::getConn()->transactionEnd();
                    }
                }
                
                return $response;
            }
            
            return $this->httpError(500, _t('KapostService.INVALID_RESPONSE', '_Invalid response returned from {method}, response was: {response}', array(
                                                                                                                                                        'method'=>$method,
                                                                                                                                                        'response'=>print_r($response, true)
                                                                                                                                                    )));
        }
        
        
        return $this->httpError(401, _t('KapostService.AUTH_FAIL', '_Authentication Failed, please check the App Center credentials for the SilverStripe end point.'));
    }
452481
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);
        $details = ArrayObject::ensureArrayObject($request->getModel());

        $httpRequest = new GetHttpRequest();
        $this->gateway->execute($httpRequest);

        if ($this->api->verifyHash($httpRequest->request) === false) {
            throw new HttpResponse('0|CheckMacValue verify fail.', 400, ['Content-Type' => 'text/plain']);
        }

        $details->replace($httpRequest->request);

        throw new HttpResponse('1|OK', 200, ['Content-Type' => 'text/plain']);
    }
600130
private function post($request)
    {
        try {
            $responseGuzzle = $this->client->request('post', $this->url, $request->build());
        } catch (ClientException $e) {
            $responseGuzzle = $e->getResponse();
        }

        return $responseGuzzle;
    }
1341979
protected function handle($request)
    {
        $this->authorize($request, $this->repository()->getClassName());

        $qb = $this->repository()->sourceQueryBuilder($request);
        $this->applyPagination($request, $qb);
        $this->applyFilter($request, $qb);

        return $this->response()->resource($request, $this->prepareCollection($request, $qb));
    }
1049502
public function handle($request)
    {
        // смотрим метод, к которому пытаются обратиться
        $namespace = $request->server->namespace;
        $method = $request->call->method;

        if (!empty($request->call->endpoint) && !empty($request->call->action)) {
            $namespace = $request->server->namespace . studly_case($request->call->endpoint) . '\\';
            $controllerName = $request->call->action;
        } elseif (!empty($request->call->endpoint)) {
            $controllerName = $request->call->endpoint;
        } else {
            $methodCall = $request->call->method;

            // парсим имя метода
            $methodArray = explode('_', $methodCall);

            // если имя вызываемого метода без разделителя - значит ищем его в базовом классе
            if (\count($methodArray) === 1) {
                $controllerName = $request->server->controller;
                $method = $methodCall;
            } else {
                $controllerName = $methodArray[0];
                unset($methodArray[0]);
                $method = camel_case(implode('_', $methodArray));
            }

        }

        $controllerName = $namespace . studly_case($controllerName . $request->server->postfix);

        // если нет такого контроллера или метода
        if (!class_exists($controllerName)) {
            throw new JsonRpcException(JsonRpcException::CODE_METHOD_NOT_FOUND);
        }

        $controller = app($controllerName);

        if (!\is_callable([$controller, $method])) {
            throw new JsonRpcException(JsonRpcException::CODE_METHOD_NOT_FOUND);
        }

        $request->controller = $controller;
        $request->method = $method;
        $request->params = !empty($request->call->params) ? array_values((array)$request->call->params) : [];

        return true;
    }