Сериализует переданный объект запроса к API в массив

@param CreateRefundRequestInterface $request Сериализуемый объект запроса

@return array Ассоциативный массив для передачи в API
439820
public function serialize(CreateRefundRequestInterface $request)
    {
        $result = array(
            'payment_id' => $request->getPaymentId(),
            'amount'     => array(
                'value'    => $request->getAmount()->getValue(),
                'currency' => $request->getAmount()->getCurrency(),
            ),
        );
        if ($request->hasComment()) {
            $result['comment'] = $request->getComment();
        }
        if ($request->hasReceipt()) {
            $receipt           = $request->getReceipt();
            $result['receipt'] = array();
            /** @var ReceiptItem $item */
            foreach ($receipt->getItems() as $item) {
                $itemArray = array(
                    'description'     => $item->getDescription(),
                    'amount'          => array(
                        'value'    => $item->getPrice()->getValue(),
                        'currency' => $item->getPrice()->getCurrency(),
                    ),
                    'quantity'        => $item->getQuantity(),
                    'vat_code'        => $item->getVatCode(),
                );

                if ($item->getPaymentSubject()) {
                    $itemArray['payment_subject'] = $item->getPaymentSubject();
                }

                if ($item->getPaymentMode()) {
                    $itemArray['payment_mode'] = $item->getPaymentMode();
                }

                $result['receipt']['items'][] = $itemArray;
            }
            $value = $receipt->getEmail();
            if (!empty($value)) {
                $result['receipt']['email'] = $value;
            }
            $value = $receipt->getPhone();
            if (!empty($value)) {
                $result['receipt']['phone'] = $value;
            }
            $value = $receipt->getTaxSystemCode();
            if (!empty($value)) {
                $result['receipt']['tax_system_code'] = $value;
            }
        }

        return $result;
    }
1371852
public function indexAction(Request $request)
    {
        $this->checkPermission();

        $form = $this->createForm(BanType::class);

        if ($request->isMethod('POST')) {
            $form->handleRequest($request);

            if ($form->isValid()) {
                $path = $form['path']->getData();

                $this->get('kunstmaan_cache.helper.varnish')->banPath($path, $form['allDomains']->getData());

                $this->addFlash('success', 'kunstmaan_cache.varnish.ban.success');
            }
        }

        return [
            'form' => $form->createView(),
        ];
    }
414688
protected function createRequestBody(Request $request) : array
    {
        $requests = array_map(
            function(RpcRequest $request) {
                return base64_encode($request->toProtobufRequest()->toStream()->getContents());
            },
            $request->getRequests()
        );

        return array(
            'Timestamp'   => $request->getTimestamp(),
            'Latitude'    =>  $request->getPosition()->getLatitude(),
            'Longitude'   => $request->getPosition()->getLongitude(),
            'Altitude'    => $request->getPosition()->getAltitude(),
            'AuthTicket'  => base64_encode($request->getAuthData()->getData()),
            'SessionData' => base64_encode($request->getSessionHash()),
            'Requests'    => $requests
        );
    }
1216827
public function toArray($request)
    {
        return [
            'id' => $this->id,
            'type' => $this->type,
            'name' => $this->name,
            'slug' => $this->slug,
            'sku' => $this->sku,
            'description' => $this->description,
            'status' => $this->status,
            'in_stock' => $this->in_stock,
            'track_stock' => $this->track_stock,
            'price' => $this->price,
            'qty' => $this->qty,
            'is_taxable' => $this->is_taxable,
            'meta_title' => $this->meta_title,
            'meta_description' => $this->meta_description,
            'weight' => $this->weight,
            'width' => $this->width,
            'height' => $this->height,
            'length' => $this->length,
            'properties' => new PropertyCollectionResource($this->getPropertiesAll()),
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
335716
public function postGenerator(Request $request)
    {
        $commandArg = [];
        $commandArg['name'] = $request->crud_name;

        if ($request->has('fields')) {
            $fieldsArray = [];
            $validationsArray = [];
            $x = 0;
            foreach ($request->fields as $field) {
                if ($request->fields_required[$x] == 1) {
                    $validationsArray[] = $field;
                }

                $fieldsArray[] = $field . '#' . $request->fields_type[$x];

                $x++;
            }

            $commandArg['--fields'] = implode(";", $fieldsArray);
        }

        if (!empty($validationsArray)) {
            $commandArg['--validations'] = implode("#required;", $validationsArray) . "#required";
        }

        if ($request->has('route')) {
            $commandArg['--route'] = $request->route;
        }

        if ($request->has('view_path')) {
            $commandArg['--view-path'] = $request->view_path;
        }

        if ($request->has('controller_namespace')) {
            $commandArg['--controller-namespace'] = $request->controller_namespace;
        }

        if ($request->has('model_namespace')) {
            $commandArg['--model-namespace'] = $request->model_namespace;
        }

        if ($request->has('route_group')) {
            $commandArg['--route-group'] = $request->route_group;
        }

        if ($request->has('relationships')) {
            $commandArg['--relationships'] = $request->relationships;
        }

        if ($request->has('form_helper')) {
            $commandArg['--form-helper'] = $request->form_helper;
        }

        if ($request->has('soft_deletes')) {
            $commandArg['--soft-deletes'] = $request->soft_deletes;
        }

        try {
            Artisan::call('crud:generate', $commandArg);

            $menus = json_decode(File::get(base_path('resources/laravel-admin/menus.json')));

            $name = $commandArg['name'];
            $routeName = ($commandArg['--route-group']) ? $commandArg['--route-group'] . '/' . snake_case($name, '-') : snake_case($name, '-');

            $menus->menus = array_map(function ($menu) use ($name, $routeName) {
                if ($menu->section == 'Resources') {
                    array_push($menu->items, (object) [
                        'title' => $name,
                        'url' => '/' . $routeName,
                    ]);
                }

                return $menu;
            }, $menus->menus);

            File::put(base_path('resources/laravel-admin/menus.json'), json_encode($menus));

            Artisan::call('migrate');
        } catch (\Exception $e) {
            return Response::make($e->getMessage(), 500);
        }

        return redirect('admin/generator')->with('flash_message', 'Your CRUD has been generated. See on the menu.');
    }
747421
public function toArray($request)
    {
        return [
            'id'            => (int) $this->id,
            'author_id'     => $this->author_id,
            'language_code' => $this->language_code,
            'title'         => $this->title,
            'body'          => $this->body,
            'custom_fields' => $this->custom_fields,
            'is_active'     => $this->is_active,
            'created_at'    => $this->created_at->toIso8601String(),
            'updated_at'    => $this->updated_at->toIso8601String(),
        ];
    }
1126326
public function toArray($request)
    {
        return [
            'id'         => (int) $this->id,
            'email'      => $this->email,
            'name'       => $this->name,
            'first_name' => $this->first_name,
            'last_name'  => $this->last_name,
            'roles'      => Role::collection($this->whenLoaded('roles')),
        ];
    }
960111
public function putDraftCollectionAction(Request $request)
    {
        $result = [];
        foreach ($request->request->all() as $data) {
            if (!isset($data['type']) || !isset($data['uid'])) {
                throw new BadRequestHttpException("type and/or uid is missing.");
            }

            try {
                $content = $this->updateClassContentDraft($data['type'], $data['uid'], $data);
                $result[] = [
                    'uid'        => $content->getUid(),
                    'type'       => $content->getContentType(),
                    'statusCode' => 200,
                    'message'    => 'OK',
                ];
            } catch (AccessDeniedException $e) {
                $result[] = [
                    'uid'        => $data['uid'],
                    'type'       => $data['type'],
                    'statusCode' => 401,
                    'message'    => $e->getMessage(),
                ];
            } catch (\Exception $e) {
                $result[] = [
                    'uid'        => $data['uid'],
                    'type'       => $data['type'],
                    'statusCode' => 500,
                    'message'    => $e->getMessage(),
                ];
            }
        }

        $this->getEntityManager()->flush();

        return $this->createJsonResponse($result);
    }
98780
public function cgetAction(Request $request)
    {
        $serializationGroups = [];
        $locale = $this->getLocale($request);

        if ('true' == $request->get('flat')) {
            $list = $this->getList($request, $locale);
        } else {
            if (true == $request->get('bySystem')) {
                $contacts = $this->getContactsByUserSystem();
                $serializationGroups[] = 'select';
            } else {
                $contacts = $this->getDoctrine()->getRepository(
                    $this->container->getParameter('sulu.model.contact.class')
                )->findAll();
                $serializationGroups = array_merge(
                    $serializationGroups,
                    static::$contactSerializationGroups
                );
            }
            // convert to api-contacts
            $apiContacts = [];
            foreach ($contacts as $contact) {
                $apiContacts[] = $this->getContactManager()->getContact($contact, $locale);
            }

            $exclusion = null;
            if (count($serializationGroups) > 0) {
                $exclusion = new Exclusion($serializationGroups);
            }

            $list = new CollectionRepresentation($apiContacts, self::$entityKey, null, $exclusion, $exclusion);
        }

        $view = $this->view($list, 200);

        // set serialization groups
        if (count($serializationGroups) > 0) {
            $context = new Context();
            $context->setGroups($serializationGroups);
            $view->setContext($context);
        }

        return $this->handleView($view);
    }
462429
private function parseParameters(RequestInterface $request): array
    {
        $parameters = [];
        $versionHeaders = $request->getHeader(self::API_VERSION_HEADER);
        $groupHeaders = $request->getHeader(self::API_GROUPS_HEADER);

        $versionHeader = reset($versionHeaders);
        $groupHeader = reset($groupHeaders);

        if (preg_match(self::API_VERSION_REGEXP, $versionHeader, $matches)) {
            $parameters['serialization_version'] = $matches['version'];
        }

        if (preg_match(self::API_GROUPS_REGEXP, $groupHeader, $matches)) {
            $parameters['serialization_groups'] = array_map(
                'trim',
                explode(',', $matches['groups'])
            );
        }

        return array_merge(
            $request->get('_borobudur', []),
            $parameters
        );
    }
739812
public function toArray($request)
    {
        /** @var Country $this->resource */
        return [
            'id'                => $this->id,
            'capital'           => $this->capital,
            'citizenship'       => $this->citizenship,
            'country_code'      => $this->country_code,
            'currency'          => $this->currency,
            'currency_code'     => $this->currency_code,
            'currency_sub_unit' => $this->currency_sub_unit,
            'currency_symbol'   => $this->currency_symbol,
            'currency_decimals' => $this->currency_decimals,
            'full_name'         => $this->full_name,
            'iso_3166_2'        => $this->iso_3166_2,
            'iso_3166_3'        => $this->iso_3166_3,
            'name'              => $this->name,
            'region_code'       => $this->region_code,
            'sub_region_code'   => $this->sub_region_code,
            'eea'               => $this->eea,
            'calling_code'      => $this->calling_code,
            'flag'              => $this->flag,
        ];
    }
1209172
public function toArray($request)
    {
        /** @var \Unite\Transactions\Models\Transaction $this->resource */
        return [
            'id'                 => $this->id,
            'type'               => $this->type,
            'subject_type'       => $this->subject_type,
            'subject_id'         => $this->subject_id,
            'amount'             => $this->amount,
            'balance'            => $this->balance,
            'variable_symbol'    => (int)$this->variable_symbol,
            'specific_symbol'    => (int)$this->specific_symbol,
            'description'        => $this->description,
            'posted_at'          => (string)$this->posted_at,
            'created_at'         => (string)$this->created_at,
            'destination_iban'   => $this->destination_iban,
            'transaction_source' => new SourceResource($this->source)
        ];
    }
923359
public function toArray($request)
    {
        return [
            'id' => $this->id,
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'email' => $this->email,
            'phone' => $this->phone,
            'company_name' => $this->company_name,
            'image_path' => $this->image_path,
            'status' => $this->status,
            'language' => $this->language,
            'address' => $this->addresses,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
490788
public function toArray($request)
    {
        return [
            'id'              => (int) $this->id,
            'author_id'       => $this->author_id,
            'language_code'   => $this->language_code,
            'title'           => $this->title,
            'teaser'          => $this->teaser,
            'body'            => $this->body,
            'seo_title'       => $this->seo_title,
            'seo_description' => $this->seo_description,
            'is_active'       => $this->is_active,
            'created_at'      => dateTimeToRequestTimezone($this->created_at)->toIso8601String(),
            'updated_at'      => dateTimeToRequestTimezone($this->updated_at)->toIso8601String(),
        ];
    }
450546
public function createAction(Request $request)
    {
        $stocklevel = new StockLevel();
        $form = $this->createForm(new StockLevelType(), $stocklevel);
        if ($form->handleRequest($request)->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($stocklevel);
            $em->flush();

            return $this->redirect($this->generateUrl('stock_stocklevel_show', array('id' => $stocklevel->getId())));
        }

        return array(
            'stocklevel' => $stocklevel,
            'form'   => $form->createView(),
        );
    }
672597
public function quicklistAction(Request $request)
    {
        $quicklist = $this->get('zicht_admin.quicklist');
        if ($request->get('repo') && $request->get('pattern')) {
            if ($request->get('language')) {
                $language = $request->get('language');
            } else {
                $language = null;
            }
            return new JsonResponse($quicklist->getResults($request->get('repo'), $request->get('pattern'), $language));
        }

        return array(
            'repos' => $quicklist->getRepositoryConfigs()
        );
    }
174741
private function buildRequest($request): GenericRequest
    {
        if ($request instanceof GenericRequest) {
            $this->logger->debug('request object used as is');

            return $request;
        }

        $requestFactory = new GenericRequestFactory();

        if ($request instanceof MessageInterface) {
            $this->logger->debug('request object created from PSR-7 http message');

            return $requestFactory->createRequestFromPsr7Message($request);
        }

        if (is_array($request)) {
            $this->logger->debug('request object created from array');

            return $requestFactory->createRequestFromArray($request);
        }

        if (is_string($request)) {
            $this->logger->debug('request object created from string');

            return $requestFactory->createRequestFromString($request);
        }

        throw new UnexpectedValueException(
            'the request parameter has to be a string, an array or an instance of \Psr\Http\Message\MessageInterface'
        );
    }