/** * Create a new item. * * @param Request $request * @param string|int $id * * @throws NotFoundHttpException * @throws RuntimeException * @throws UserProtectedException * @throws UserLimitReachedException * * @return mixed */ public function __invoke(Request $request, $id) { /** * @var $resourceType ResourceInterface */ list($resourceType, $format) = $this->extractAttributes($request); /* * Workaround to ensure stockLevels are not overwritten in a PUT request. * @see https://github.com/partkeepr/PartKeepr/issues/551 */ $data = json_decode($request->getContent(), true); if (array_key_exists('stockLevels', $data)) { unset($data['stockLevels']); } $requestData = json_encode($data); $data = $this->getItem($this->dataProvider, $resourceType, $id); $context = $resourceType->getDenormalizationContext(); $context['object_to_populate'] = $data; /** * @var $part Part */ $part = $this->serializer->deserialize($requestData, $resourceType->getEntityClass(), $format, $context); if (!$this->partService->isInternalPartNumberUnique($part->getInternalPartNumber(), $part)) { throw new InternalPartNumberNotUniqueException(); } return $part; }
/** * Create a new item. * * @param Request $request * @param string|int $id * * @throws NotFoundHttpException * @throws RuntimeException * @throws UserProtectedException * @throws UserLimitReachedException * * @return mixed */ public function __invoke(Request $request, $id) { /** * @var ResourceInterface */ list($resourceType, $format) = $this->extractAttributes($request); /** * @var User */ $data = $this->getItem($this->dataProvider, $resourceType, $id); $context = $resourceType->getDenormalizationContext(); $context['object_to_populate'] = $data; if ($data->isProtected()) { throw new UserProtectedException(); } $data = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $context); if ($data->isActive()) { if ($this->userService->checkUserLimit()) { throw new UserLimitReachedException(); } } $this->userService->syncData($data); $data->setNewPassword(''); $data->setPassword(''); $data->setLegacy(false); return $data; }
/** * {@inheritdoc} */ public function current() { $result = parent::current(); if ($result !== null && $this->serializer) { $result = $this->serializer->deserialize($result, $this->itemType, null, $this->deserializeContext); } return $result; }
/** * @param $url * @param array $params * * @return array */ public function get($url, $params = array()) { $request = $this->provider->request($url, $params); $response = $this->client->send($request); $data = $response->getBody()->getContents(); $format = $this->getFormat($params, $response); return $this->serializer->deserialize($data, null, $format); }
/** * Create a new item. * * @param Request $request * @param string|int $id * * @return mixed * * @throws NotFoundHttpException * @throws RuntimeException */ public function __invoke(Request $request, $id) { list($resourceType, $format) = $this->extractAttributes($request); $data = $this->getItem($this->dataProvider, $resourceType, $id); $context = $resourceType->getDenormalizationContext(); $context['object_to_populate'] = $data; $data = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $context); return $data; }
/** * Injects the specific root node ID if "@local-tree-root" was specified * * @param Request $request * * @return mixed * * @throws RuntimeException * @throws PartLimitExceededException */ public function __invoke(Request $request) { /** * @var $resourceType ResourceInterface */ if ($this->partService->checkPartLimit()) { throw new PartLimitExceededException(); } list($resourceType, $format) = $this->extractAttributes($request); return $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext()); }
/** * {@inheritdoc} */ public function process($item) { if ($this->converter) { $item = $this->converter->convertToImportFormat($item); } $object = $this->serializer->deserialize($item, $this->context->getOption('entityName'), null); if ($this->strategy) { $object = $this->strategy->process($object); } return $object ?: null; }
/** * {@inheritdoc} */ public function process($item) { if ($this->dataConverter) { $item = $this->dataConverter->convertToImportFormat($item, false); } $this->context->setValue('itemData', $item); $object = $this->serializer->deserialize($item, $this->context->getOption('entityName'), null, $this->context->getConfiguration()); if ($this->strategy) { $object = $this->strategy->process($object); } return $object ?: null; }
/** * Return a list of class guessed * * @param $swaggerSpec * @param $name * @param $namespace * @param $directory * * @return Context */ public function createContext($swaggerSpec, $name, $namespace, $directory) { $schema = $this->serializer->deserialize(file_get_contents($swaggerSpec), Swagger::class, 'json'); $classes = $this->chainGuesser->guessClass($schema, $name); foreach ($classes as $class) { $properties = $this->chainGuesser->guessProperties($class->getObject(), $name, $classes); foreach ($properties as $property) { $property->setType($this->chainGuesser->guessType($property->getObject(), $property->getName(), $classes)); } $class->setProperties($properties); } return new Context($schema, $namespace, $directory, $classes); }
/** * @param string $response * @param array $options * * @return object */ private function getResponse($response, array $options) { if (is_string($response) && array_key_exists('class', $options)) { $response = $this->serializer->deserialize($response, $options['class'], 'json'); } return $response; }
/** * Transform a given response into a denormalized PHP object * If the config option "returnResponse" is set to TRUE, it return a Response instead * * @param ResponseInterface $response * @param ResponseDefinition $definition * @param RequestInterface $request * * @return Resource|mixed */ private function getDataFromResponse(ResponseInterface $response, ResponseDefinition $definition, RequestInterface $request) { if ($this->config['returnResponse'] === true) { return $response; } return $this->serializer->deserialize((string) $response->getBody(), Resource::class, DecoderUtils::extractFormatFromContentType($response->getHeaderLine('Content-Type')), ['response' => $response, 'responseDefinition' => $definition, 'request' => $request]); }
/** * Resolve JSON Schema for the reference * * @param Reference $reference * @param JsonSchema $currentSchema * * @throws UnsupportedException * * @return JsonSchema Return the json schema referenced */ protected function resolveSchema(Reference $reference, $currentSchema) { if ($reference->isInCurrentDocument() && $reference->hasFragment()) { return $currentSchema; } if ($reference->isRelative() && !$currentSchema->getId()) { throw new UnsupportedException(sprintf("Reference is relative and no id found in current schema, cannot resolve reference %s", $reference->getReference())); } // Build url $schemaUrl = sprintf('%s://%s:%s', $reference->getScheme() ?: 'http', $reference->getHost(), $reference->getPort() ?: '80'); if ($reference->isRelative()) { $parsedUrl = parse_url($currentSchema->getId()); $schemaUrl = sprintf('%s://%s:%s', $parsedUrl['scheme'] ?: 'http', $parsedUrl['host'], $parsedUrl['port'] ?: '80'); } if ($reference->getPath()) { $schemaUrl = sprintf("%s/%s", $schemaUrl, $reference->getPath()); } if ($reference->getQuery()) { $schemaUrl = sprintf("%s?%s", $schemaUrl, $reference->getQuery()); } if (!isset($this->schemaCache[$schemaUrl])) { $schema = $this->serializer->deserialize($this->getJsonSchemaContent($schemaUrl), 'Joli\\Jane\\Model\\JsonSchema', 'json'); $this->schemaCache[$schemaUrl] = $schema; } return $this->schemaCache[$schemaUrl]; }
/** * Injects the specific root node ID if "@local-tree-root" was specified. * * @param Request $request * * @throws RuntimeException * @throws PartLimitExceededException * @throws InternalPartNumberNotUniqueException * * @return mixed */ public function __invoke(Request $request) { if ($this->partService->checkPartLimit()) { throw new PartLimitExceededException(); } /** * @var $resourceType ResourceInterface */ list($resourceType, $format) = $this->extractAttributes($request); /** * @var $part Part */ $part = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext()); if (!$this->partService->isInternalPartNumberUnique($part->getInternalPartNumber())) { throw new InternalPartNumberNotUniqueException(); } return $part; }
/** * {@inheritdoc} */ public function loadDomainDistinguishedName($domain) { try { $json = $this->master->read('private/' . $domain . '/distinguished_name.json'); return $this->serializer->deserialize($json, DistinguishedName::class, JsonEncoder::FORMAT); } catch (\Exception $e) { throw new AcmeCliException(sprintf('Loading of domain %s distinguished name failed', $domain), $e); } }
/** * Create a new item. * * @param Request $request * * @return mixed * * @throws NotFoundHttpException * @throws RuntimeException * @throws UserLimitReachedException */ public function __invoke(Request $request) { /** * @var $resourceType ResourceInterface */ list($resourceType, $format) = $this->extractAttributes($request); if ($this->userService->checkUserLimit() === true) { throw new UserLimitReachedException(); } /** * @var User $data */ $data = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext()); $data->setProvider($this->userService->getBuiltinProvider()); $data->setLegacy(false); $this->userService->syncData($data); $data->setNewPassword(""); $data->setPassword(""); return $data; }
/** * {@inheritdoc} * * @return \Drupal\Core\Entity\EntityInterface|array */ public function processRequest(Request $request, RouteMatchInterface $route_match, SerializerInterface $serializer) { // Unserialize the content of the request if there is any. $content = $request->getContent(); if (!empty($content)) { $entity_type_id = $this->getDerivativeId(); /** @var $entity_type \Drupal\Core\Entity\EntityTypeInterface */ $entity_type = $this->manager->getDefinition($entity_type_id); return $serializer->deserialize($content, $entity_type->getClass(), $request->getContentType(), ['entity_type' => $entity_type_id]); } return []; }
/** * Create a new item. * * @param Request $request * @param string|int $id * * @return mixed * * @throws NotFoundHttpException * @throws RuntimeException * @throws UserProtectedException * @throws UserLimitReachedException */ public function __invoke(Request $request, $id) { /** * @var $resourceType ResourceInterface */ list($resourceType, $format) = $this->extractAttributes($request); /** * Workaround to ensure stockLevels are not overwritten in a PUT request. * @see https://github.com/partkeepr/PartKeepr/issues/551 */ $data = json_decode($request->getContent(), true); if (array_key_exists("stockLevels", $data)) { unset($data["stockLevels"]); } $requestData = json_encode($data); $data = $this->getItem($this->dataProvider, $resourceType, $id); $context = $resourceType->getDenormalizationContext(); $context['object_to_populate'] = $data; $data = $this->serializer->deserialize($requestData, $resourceType->getEntityClass(), $format, $context); return $data; }
/** * Parse an file into a OpenAPI Schema model * * @param string $openApiSpec * * @return OpenApi * * @throws ParseFailureException */ public function parseSchema($openApiSpec) { $openApiSpecContents = file_get_contents($openApiSpec); $schemaClass = self::OPEN_API_MODEL; $schema = null; $jsonException = null; $yamlException = null; try { $schema = $this->serializer->deserialize($openApiSpecContents, $schemaClass, self::CONTENT_TYPE_JSON); } catch (\Exception $exception) { $jsonException = $exception; } if (!$schema) { try { $schema = $this->serializer->deserialize($openApiSpecContents, $schemaClass, self::CONTENT_TYPE_YAML); } catch (\Exception $exception) { $yamlException = $exception; } if (!$schema) { throw new ParseFailureException(sprintf(self::EXCEPTION_MESSAGE, $openApiSpec), 1, $jsonException, $yamlException); } } return $schema; }
/** * Hydrate an item to persist. * * @param Request $request * * @return mixed * * @throws RuntimeException */ public function __invoke(Request $request) { list($resourceType, $format) = $this->extractAttributes($request); return $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext()); }
/** * Deserializes data into the given type. * * @param mixed $data * @param string $type * @param string $format * @param array $context * * @return object */ public function deserialize($data, $type, $format, array $context = array()) { return $this->serializer->deserialize($data, $type, $format, $context); }
/** * {@inheritDoc} */ public function deserialize($data, $type) { $fqcn = 'Xabbuh\\PandaClient\\Model\\' . $type; return $this->serializer->deserialize($data, $fqcn, 'json'); }
/** * Deserializes data into the given type. * * @param mixed $data * @param string $type * @param string $format * @param SerializationContext|array $context * * @return object|array */ public function deserialize($data, $type, $format, $context = null) { return $this->target->deserialize($data, $type, $format, $context ? $context : ($this->expectsEmptyArray ? [] : null)); }
public function makeDto(Request $request) : Dto { $commentDto = $this->serializer->deserialize($request->getContent(), CommentDto::class, 'json', ['groups' => ['create']]); $commentDto->postId = $request->attributes->get('postId'); return $commentDto; }