本文整理汇总了PHP中Symfony\Component\Serializer\SerializerInterface::deserialize方法的典型用法代码示例。如果您正苦于以下问题:PHP SerializerInterface::deserialize方法的具体用法?PHP SerializerInterface::deserialize怎么用?PHP SerializerInterface::deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Serializer\SerializerInterface
的用法示例。
在下文中一共展示了SerializerInterface::deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* 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;
}
示例2: __invoke
/**
* 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;
}
示例3: current
/**
* {@inheritdoc}
*/
public function current()
{
$result = parent::current();
if ($result !== null && $this->serializer) {
$result = $this->serializer->deserialize($result, $this->itemType, null, $this->deserializeContext);
}
return $result;
}
示例4: get
/**
* @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);
}
示例5: __invoke
/**
* 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;
}
示例6: __invoke
/**
* 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());
}
示例7: process
/**
* {@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;
}
示例8: process
/**
* {@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;
}
示例9: createContext
/**
* 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);
}
示例10: getResponse
/**
* @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;
}
示例11: getDataFromResponse
/**
* 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]);
}
示例12: resolveSchema
/**
* 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];
}
示例13: __invoke
/**
* 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;
}
示例14: loadDomainDistinguishedName
/**
* {@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);
}
}
示例15: __invoke
/**
* 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;
}