@param JsonRpcRequest $request
@param array $item

@return void
358354
protected function bindIdIfProvided(JsonRpcRequest $request, array $item) : void
    {
        /** If no id defined => request is a notification */
        if (isset($item[self::KEY_ID])) {
            $request->setId(
                $item[self::KEY_ID] == (string)((int)$item[self::KEY_ID])
                    ? (int)$item[self::KEY_ID] // Convert it in case it's a string containing an int
                    : (string)$item[self::KEY_ID] // Convert to string in all other cases
            );
        }
    }
940927
public function postNew(ItemNew $request)
    {
        $file = $request->file('doc');

        $item = new Item();

        $item->name = $request->input('name');
        $item->description = $request->input('description');
        $item->auction = $request->input('type') == 'auction';
        $item->quantity = $request->input('type') == 'auction'
            ? 1
            : $request->input('quantity');
        $item->commission = 0;
        $item->startPrice = $request->input('start_price');
        $item->biddingPrice = $request->input('type') == 'auction'
            ? $request->input('start_price')
            : null;
        $item->fixedPrice = $request->input('fixed_price');
        $item->reservePrice = $request->input('reserve_price');
        $item->startDate = strtotime($request->input('start_date').' '.$request->input('start_time'));
        $item->startDate = $item->startDate < time() ? time() : $item->startDate;
        $item->duration = ListingDuration::where(
            'duration',
            $request->input('duration')
        )->value('duration');
        $item->endDate = $item->getEndDate();
        $item->collectionLocation = $request->input('collection_location');
        $item->paymentOther = (bool) $request->input('payment_other');
        $item->returnsPeriod = $request->input('returns_period');

        $item->created = time();
        $item->condition()->associate($request->input('condition'));
        $item->seller()->associate(Auth::user());

        $item->save();

        foreach ((array) $request->input('categories') as $category_id) {
            if ($category = Category::find($category_id)) {
                $item->categories()->save($category);
            }
        }

        if (mustard_loaded('media')) {
            $photos = [];

            if ($request->hasFile('photos')) {
                foreach ($request->file('photos') as $file) {
                    $photos[] = [
                        'real_path' => $file->getRealPath(),
                        'filename'  => $file->getClientOriginalName(),
                    ];
                }
            }

            if ($request->session()->has('photos')) {
                foreach ($request->session()->pull('photos') as $file) {
                    $photos[] = $file;
                }
            }

            $primary_set = false;

            foreach ($photos as $file) {
                $pp = new \PhotoProcessor($file['real_path']);

                try {
                    $pp->validate();
                } catch (\PhotoFormatUnknownException $e) {
                    self::formFlash(array_keys(array_except($request->all(), ['photos'])));

                    return redirect()->back()->withErrors([$file['filename'].' is not an image format we could recognise.']);
                }

                $photo = new \Hamjoint\Mustard\Media\Photo();

                if (!$primary_set) {
                    $photo->primary = $primary_set = true;
                }

                $photo->processed = false;

                $photo->item()->associate($item);

                $photo->save();

                $pp->process($photo);
            }
        }

        foreach ((array) $request->input('delivery_options') as $delivery_option) {
            $validator = \Validator::make(
                $delivery_option,
                [
                    'name'         => 'required|min:3',
                    'price'        => 'required|monetary',
                    'arrival_time' => 'required|intrange',
                ]
            );

            // Skip if fails validation
            if ($validator->fails()) {
                continue;
            }

            $do = new DeliveryOption();

            $do->name = $delivery_option['name'];

            $do->price = $delivery_option['price'];

            if (preg_match('/(\d+)-(\d+)/', $delivery_option['arrival_time'], $matches)) {
                $do->minArrivalTime = $matches[1];

                $do->maxArrivalTime = $matches[2];
            } else {
                $do->minArrivalTime = $do->maxArrivalTime = $delivery_option['arrival_time'];
            }

            $item->deliveryOptions()->save($do);
        }

        $item->seller->sendEmail(
            'You have listed an item',
            'mustard::emails.item.listed',
            [
                'item_id'   => $item->itemId,
                'item_name' => $item->name,
            ]
        );

        return redirect($item->url);
    }
477676
private function load(iterable $data, $item, $key, bool $flush, int &$flushCounter, int &$totalCounter): void
    {
        try {
            ($this->load)($data, $key, $this);
            $this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::LOAD, $item, $key, $this));
        } catch (\Throwable $e) {
            /** @var ItemExceptionEvent $event */
            $event = $this->eventDispatcher->dispatch(new ItemExceptionEvent(EtlEvents::LOAD_EXCEPTION, $item, $key, $this, $e));
            if ($event->shouldThrowException()) {
                throw $e;
            }
            $flushCounter--;
            $totalCounter--;
        }

        if (true === $flush) {
            $this->flush($flushCounter, true);
        }
    }
1327348
public function postLoad(Item $item, LifecycleEventArgs $event)
    {
        $type = $this->itemDefinitions->getConvertedType($item->getMimeType());
        $definition = $this->itemDefinitions->get($type);
        $repository = $event
            ->getEntityManager()
            ->getRepository($definition->getEntityClass());

        /** @var \UJM\ExoBundle\Entity\ItemType\AbstractItem $typeEntity */
        $typeEntity = $repository->findOneBy([
            'question' => $item,
        ]);

        if (!empty($typeEntity)) {
            $item->setInteraction($typeEntity);
        }
    }
1067909
public function getJsonRpcResponseFromException(
        \Exception $exception,
        JsonRpcRequest $fromRequest = null
    ) : JsonRpcResponse {
        $event = new ActionEvent\OnExceptionEvent($exception, $fromRequest);
        $this->dispatchJsonRpcEvent($event::EVENT_NAME, $event);

        return $this->responseCreator->createErrorResponse($event->getException(), $fromRequest);
    }
8571
public function updateItem(Item $item): void
    {
        $query = $this->connection->createQueryBuilder();

        $query
            ->update('ngbm_collection_item')
            ->set('collection_id', ':collection_id')
            ->set('position', ':position')
            ->set('value', ':value')
            ->set('value_type', ':value_type')
            ->set('config', ':config')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $item->id, Type::INTEGER)
            ->setParameter('collection_id', $item->collectionId, Type::INTEGER)
            ->setParameter('position', $item->position, Type::INTEGER)
            ->setParameter('value', $item->value, Type::STRING)
            ->setParameter('value_type', $item->valueType, Type::STRING)
            ->setParameter('config', $item->config, Type::JSON_ARRAY);

        $this->applyStatusCondition($query, $item->status);

        $query->execute();
    }
91091
private function validateArray($value, string $errorDescription) : void
    {
        if (!is_array($value)) {
            throw new JsonRpcInvalidRequestException($value, $errorDescription);
        }
    }
531095
public function put($key, $item)
    {
        $file = $this->filename($key);

        // json
        // text
        if (!file_put_contents($file, serialize($item))) {
            throw new \Exception(
                t("Failed writing cache object '!key'.", [
                    '!key' => $key
                ])
            );
        }
    }
72884
protected function _reformJsonRpcRequest($request) {
        /**
         * Sanity check, if the right properties are not found in the object,
         * pass the original along to Zend_Json_Server and let it fail.
         */
        if (!is_array($request)
            || !array_key_exists('method', $request)
            || !array_key_exists('params', $request)
        ) {
            return $request;
        }
        $meth = $request['method'];
        $meth = explode('.', $meth);
        // send everything thru Garp_Content_Manager_Proxy::pass
        $request['method'] = 'pass';
        $request['params'] = array($meth[0], $meth[1], $request['params']);
        return $request;
    }
986220
public function save(Process $process, array $item)
    {
        $this->initiateMemoryProcess($process);
        $this->memory[$process->getId()][] = json_encode($item);
    }
850498
protected function _getJsonRpcRequest() {
        if ($this->getRequest()->getPost('request')) {
            return $this->getRequest()->getPost('request');
        }
        return $request = $this->getRequest()->getRawBody();
    }
1193222
public function listAction(Request $request)
    {
        return new JsonResponse(
            $this->finder->search(
                'UJM\ExoBundle\Entity\Item\Item',
                $request->query->all(),
                [Transfer::INCLUDE_SOLUTIONS, Transfer::INCLUDE_ADMIN_META]
            )
        );
    }
792863
public function resolve(CartItem $item, Request $request)
    {
        
        $productId = $request->query->get('id');
        $itemForm = $request->request->get('cart_item_simple');

        $productRepository = $this->manager->getRepository('EcommerceBundle:Product');
        if (!$productId || !$product = $productRepository->find($productId)) {
            // no product id given, or product not found
            throw new \Exception('Requested product was not found');
        }

        // assign the product and quantity to the item
        $item->setProduct($product);
        $item->setQuantity(intval($itemForm['quantity']));

        // calculate item price adding the special charge
        $price = $product->getPrice();
        if ($this->specialPercentageCharge > 0) {
            $price += $price * ($this->specialPercentageCharge / 100);
        }
        $item->setUnitPrice(intval($price));

        return $item;
    }
990527
public function __doRequest($request, $location, $action, $version, $oneWay = 0)
    {
        $aFind = [':ns1', 'ns1:', "\n", "\r"];
        $sReplace = '';
        $newrequest = str_replace($aFind, $sReplace, $request);

        return parent::__doRequest($newrequest, $location, $action, $version, $oneWay);
    }
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;
    }
749558
public function handle(Request $request, JsonRpcServer $server)
    {
        $data = $server->data;

        // если один вызов - приведем к массиву вызовов
        if (!\is_array($data)) {
            $calls = [$data];
        } else {
            $calls = $data;
        }

        $result = [];

        // выполняем все вызовы
        foreach ($calls as $call) {
            // создаем ответ
            $answer = new \stdClass();
            $answer->jsonrpc = '2.0';

            if (!empty($server->endpoint)) {
                $call->endpoint = $server->endpoint;
            }

            if (!empty($server->action)) {
                $call->action = $server->action;
            }

            // создаем запрос
            $jsonRpcRequest = new JsonRpcRequest($call, $server);
            $jsonRpcRequest->service = $server->serviceName;

            app()->instance(JsonRpcRequest::class, $jsonRpcRequest);

            if (null !== $jsonRpcRequest->id) {
                $answer->id = $jsonRpcRequest->id;
            }

            // выполняем запрос
            try {
                $answer->result = $jsonRpcRequest->handle();
            } catch (\Exception $e) {
                $answer->error = JsonRpcHandler::handle($e);
            }

            $result[] = $answer;
        }

        $server->setResponse($result);

        return true;
    }
1363081
public function listJsonAction(Request $request)
    {
        $totalEntities = $this->countTotal();
                
        $offset = intval($request->get('iDisplayStart'));
        $limit = intval($request->get('iDisplayLength'));
        $sortColumn = intval($request->get('iSortCol_0'));
        $sortDirection = $request->get('sSortDir_0');
        $search = $request->get('sSearch');
        $echo = intval($request->get('sEcho'));
        
        $entities = $this->findAllForDataTables($search, $sortColumn, $sortDirection, null, $request->getLocale());
        
        $totalFilteredEntities = count($entities->getScalarResult());

        // paginate
        $entities->setFirstResult($offset)
            ->setMaxResults($limit);

        $data = $entities->getResult();


        $response = array(
            'iTotalRecords'         => $totalEntities,
            'iTotalDisplayRecords'  => $totalFilteredEntities,
            'sEcho'                 => $echo,
            'aaData'                => $data
        );
        

        return new JsonResponse($response);
    }