@param JsonRpcRequest $request
@param array          $item

@return void

@throws JsonRpcInvalidRequestException
776094
protected function bindParamListIfProvided(JsonRpcRequest $request, array $item) : void
    {
        if (isset($item[self::KEY_PARAM_LIST])) {
            $this->validateArray($item[self::KEY_PARAM_LIST], 'Parameter list must be an array');
            $request->setParamList($item[self::KEY_PARAM_LIST]);
        }
    }
864923
public function handle(Request $request, JsonRpcServer $server)
    {
        // проверка типа метода
        if (!$request->isMethod('post')) {
            throw new JsonRpcException(JsonRpcException::CODE_INVALID_REQUEST);
        }

        // получаем тело запроса
        $json = $request->getContent();

        // если запрос пустой
        if (empty($json)) {
            throw new JsonRpcException(JsonRpcException::CODE_INVALID_REQUEST);
        }

        // декодируем json
        $data = json_decode($json);

        // если не валидный json
        if (null === $data) {
            throw new JsonRpcException(JsonRpcException::CODE_PARSE_ERROR);
        }

        $server->data = $data;

        return true;
    }
437739
public function add_item(cc_i_item &$item) {
        if (is_null($this->itemlist)) {
            $this->itemlist = array();
        }
        $this->itemlist[$item->identifier] = $item;
    }
165582
public function cast($request)
    {
        if (is_array($request) || is_object($request)) {
            foreach ($request as $key => $value) {
                if (is_array($value)) {
                    $this->cast($value);
                } else {
                    $this->$key = $value;
                }
            }
        }
    }
588430
protected JsonRpcResponse execute(JsonRpcRequest request) {
        if (request == null) {
            return new JsonRpcResponse(null, JsonRpcError.parseError(null));
        }

        String serviceName = null;
        String methodName = request.getMethod();
        int lastIndex = methodName.lastIndexOf('.');
        if (lastIndex >= 0) {
            serviceName = methodName.substring(0, lastIndex);
            methodName = methodName.substring(lastIndex + 1);
        }

        ServiceEntry<?> serviceEntry = serviceRegistry.getService(serviceName);
        if (serviceEntry == null) {
            return new JsonRpcResponse(null, JsonRpcError.methodNotFoundError(null));
        }
        Set<Method> methods = serviceEntry.getMethods(methodName);
        if (methods == null || methods.isEmpty()) {
            return new JsonRpcResponse(null, JsonRpcError.methodNotFoundError(null));
        }

        String id = request.getId();
        Node[] params = request.getParams();
        Method method = findExecutableMethod(methods, params);
        if (method == null) {
            return new JsonRpcResponse(null, JsonRpcError.invalidParamsError(null));
        }

        Object service = serviceEntry.getService();
        Object[] args = getParameters(method, params);
        try {
            Object invokeValue = method.invoke(service, args);

            if (id == null) {
                return null;
            }

            Node result = jsonImpl.convert(invokeValue);
            return new JsonRpcResponse(id, result);
        } catch (Throwable t) {
            if (t instanceof InvocationTargetException) {
                t = ((InvocationTargetException) t).getTargetException();
            }
            LOG.debug("executing error : " + method, t);
            return new JsonRpcResponse(id, JsonRpcError.serverError(2, "Server error", t));
        }
    }
115969
public function sendRequest(CPS_Request &$request, $json = false)
  {
    $firstSend = true;
    $previousRenderedStorage = '';
    if (isset($this->_connectionSwitcher)) {
      $this->_connectionSwitcher->newRequest($request);
    }

    do {
      $e = NULL;

      if (isset($this->_connectionSwitcher)) {
        $this->_connectionString = $this->_parseConnectionString($this->_connectionSwitcher->getConnectionString($this->_storageName));
      }
      try {
        if (strtolower($request->getCommand()) == 'begin-transaction')
          $this->setTransactionId(NULL);//reset transaction id to allow failover to another hub in case of failure
        if (!is_null($this->_transactionId)) {
          $request->setParam('transaction_id', $this->_transactionId);
        }
        if ($firstSend || ($previousRenderedStorage != $this->_storageName)) {
          $requestXml = $this->_renderRequest($request);
          $previousRenderedStorage = $this->_storageName;

          $this->_lastRequestQuery = $requestXml;
          if ($this->_debug) {
            echo $this->getLastRequestQuery();
          }
          $this->_lastRequestSize = strlen($requestXml);
        }
        $firstSend = false;

        $this->_lastNetworkDuration = 0;

        $time_start = microtime(true);
        if ($this->_connectionString['type'] == 'socket') {
          $ssl_options = false;
          if (isset($this->_connectionString['ssl']) && $this->_connectionString['ssl'] == true) {
            $ssl_options["enabled"] = true;
            $ssl_options["ca"] = $this->_sslCustomCA;
            $ssl_options["cn"] = $this->_sslCustomCN;
          }
          $rawResponse = cps2_exchange($this->_connectionString['host'], $this->_connectionString['port'], $requestXml, $this->_storageName, $this->_lastNetworkDuration, $this->_hmacUserKey, $this->_hmacSignKey, $ssl_options);
          if ($json) { // TODO: Jauzlabo JSON integracija
            return $rawResponse;
          }
        } else {
          // TODO: use curl?
          $rawResponse = cps_http_data(cps_http_post($this->_connectionString['url'], $requestXml, false, 'Recipient: ' . str_replace(array("\r", "\n"), '', $this->_storageName) . "\r\n", $this->_lastNetworkDuration, $this->_hmacUserKey, $this->_hmacSignKey));
        }
        $time_end = microtime(true);
        $this->_lastRequestDuration = $time_end - $time_start;
        $this->_lastResponseSize = strlen($rawResponse);

        $this->_lastRequestResponse = $rawResponse;
        if ($this->_debug) {
          echo $this->getLastRequestResponse();
        }
      } catch (CPS_Exception $exception) {
        $e = $exception;
      }
      if (isset($this->_connectionSwitcher)) {
        $quit = !$this->_connectionSwitcher->shouldRetry($rawResponse, $e, $this->getTransactionId());
      } else {
        $quit = true;
      }
      if ($quit && !is_null($e))
        throw $e;
    } while (!$quit);
    switch ($request->getCommand()) {
      case 'search':
        $ret = new CPS_SearchResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'update':
      case 'delete':
      case 'replace':
      case 'partial-replace':
      case 'partial-xreplace':
      case 'insert':
      case 'create-alert':
      case 'update-alerts':
      case 'delete-alerts':
        $ret = new CPS_ModifyResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'alternatives':
        $ret = new CPS_AlternativesResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'list-words':
        $ret = new CPS_ListWordsResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'status':
        $ret = new CPS_StatusResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'retrieve':
      case 'list-last':
      case 'list-first':
      case 'retrieve-last':
      case 'retrieve-first':
      case 'lookup':
      case 'similar':
      case 'show-history':
        $ret = new CPS_LookupResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'search-delete':
        $ret = new CPS_SearchDeleteResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'list-paths':
        $ret = new CPS_ListPathsResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'list-facets':
        $ret = new CPS_ListFacetsResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      case 'list-alerts':
        $ret = new CPS_ListAlertsResponse($this, $request, $rawResponse, $this->_noCdata);
        break;
      default:
        $ret = new CPS_Response($this, $request, $rawResponse, $this->_noCdata);
    }
    return $ret;
  }
458510
public static function validateConditionsConfig(array $json) : void
    {
        foreach ($json as $condition) {
            if (!self::keysExist(['exec'], $condition) || empty($condition['exec'])) {
                throw new \RuntimeException('Config error: \'exec\' is required for conditions');
            }
            if (!empty($condition['args']) && !is_array($condition['args'])) {
                throw new \RuntimeException('Config error: invalid \'args\' configuration');
            }
        }
    }
1029173
public static function array_insert(&$array, $item, $position) {
        if ($position == 0) {
            /* Prepend the item */
            array_unshift($array, $item);
        } else {
            if (count($array) == $position) {
                $array[] = $item;
            } else {
                array_splice($array, $position, 0, array($item));
            }
        }
    }
226458
protected function validate_item($item) {

        $allowed = array(
            'user'              => true,
            'grouping'          => true,
            'group'             => true,
            'role'              => true,
            'file'              => true,
            'scale'             => true,
            'outcome'           => true,
            'grade_item'        => true,
            'question_category' => true
        );

        if (!isset($allowed[$item])) {
            throw new coding_exception('Invalid inforef item type');
        }
    }
1275955
public function createErrorResponse(\Exception $exception, JsonRpcRequest $fromRequest = null) : JsonRpcResponse
    {
        return $this->createEmptyResponse($fromRequest)
            ->setError(
                $exception instanceof JsonRpcExceptionInterface
                    ? $exception
                    : new JsonRpcInternalErrorException($exception)
            )
        ;
    }
969963
public function attachToObject($request, $item)
    {
        if ($request->filled('widgets')) {
            $widgets = explode(',', $request->get('widgets'));
            $item->syncWidgets($this->repository->getItemsByIDs((array) $widgets));
        } else {
            $item->detachWidgets($item->widgets);
        }
    }
42180
private function validate($item, ResolveInfo $info, ResourceMetadata $resourceMetadata, string $operationName = null): void
    {
        if (null === $this->validator) {
            return;
        }

        $validationGroups = $resourceMetadata->getGraphqlAttribute($operationName, 'validation_groups', null, true);
        try {
            $this->validator->validate($item, ['groups' => $validationGroups]);
        } catch (ValidationException $e) {
            throw Error::createLocatedError($e->getMessage(), $info->fieldNodes, $info->path);
        }
    }
383983
public function create_request($par_array)
    {
        //debug_var_dump('par_array', $par_array);
        $request = $this->addChild($this->doc->documentElement, "request", $this->request_url());
        foreach ($par_array as $key => $value) {
            $request->setAttribute($key, $value);
        }
    }
1192478
protected function handleGet($item = null)
    {
        PWELogger::debug($_SERVER['REQUEST_METHOD'] . ": %s", $item);
        throw new HTTP5xxException('Not supported method for this call: ' . $_SERVER['REQUEST_METHOD'], HTTP5xxException::UNIMPLEMENTED);
    }
297737
private function process_delete_request($item) {
        global $DB;

        $gradeitem = \grade_item::fetch(array('id' => $item->id));
        if (($gbs = gradebookservices::find_ltiservice_gradebookservice_for_lineitem($item->id)) == false) {
            throw new \Exception(null, 403);
        }
        if (!$gradeitem->delete('mod/ltiservice_gradebookservices')) {
            throw new \Exception(null, 500);
        } else {
            $sqlparams = array();
            $sqlparams['id'] = $gbs->id;
            if (!$DB->delete_records('ltiservice_gradebookservices', $sqlparams)) {
                throw new \Exception(null, 500);
            }
        }
    }
1178661
private function getJsonRequest() {
        $request = $this->getRawPostData();
        if ($request == "") {
            throw new JsonRpcExeption(101, "Parse Error: no data");
        }
        $encoding = mb_detect_encoding($request, 'auto');
        if ($encoding != 'UTF-8') {
            $request = iconv($encoding, 'UTF-8', $request);
        }
        $request = json_decode($request);
        if ($request == NULL) { // parse error
            $error = $this->getJsonError();
            throw new JsonRpcExeption(101, "Parse Error: $error");
        }
        return $request;
    }
1135403
public function handle(Request $request, JsonRpcServer $server)
    {
        if (!$server->auth) {
            return true;
        }

        if (!$key = $request->header(config('jsonrpc.accessHeaderName', 'Access-Key'))) {
            throw new JsonRpcException(JsonRpcException::CODE_UNAUTHORIZED);
        }

        $service = array_search($key, config('jsonrpc.keys', []), true);

        if ($service === false) {
            throw new JsonRpcException(JsonRpcException::CODE_UNAUTHORIZED);
        }

        $server->serviceName = $service;

        return true;
    }