Symfony\Component\Serializer\SerializerInterface::deserialize PHP Метод

deserialize() публичный Метод

Deserializes data into the given type.
public deserialize ( mixed $data, string $type, string $format )
$data mixed
$type string
$format string
    function deserialize($data, $type, $format);

Usage Example

Пример #1
0
 /**
  * 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;
 }
All Usage Examples Of Symfony\Component\Serializer\SerializerInterface::deserialize