/** * Denormalizes a relation. * * @param ResourceInterface $currentResource * @param AttributeMetadata $attributeMetadata * @param $class * @param $value * * @return object * @throws InvalidArgumentException */ private function denormalizeRelation(ResourceInterface $currentResource, AttributeMetadata $attributeMetadata, $class, $value) { if ('Datetime' === $class) { $dateTimeNormalizer = new DateTimeNormalizer(); return $dateTimeNormalizer->denormalize($value, $class ?: null, self::FORMAT); } $attributeName = $attributeMetadata->getName(); // // Always allow IRI to be compliant with the Hydra spec // if (is_string($value)) { // $item = $this->dataProvider->getItemFromIri($value); // if (null === $item) { // throw new InvalidArgumentException(sprintf( // 'IRI not supported (found "%s" in "%s" of "%s")', // $value, // $attributeName, // $currentResource->getEntityClass() // )); // } // return $item; // } if (!$this->resourceCollection->getResourceForEntity($class)) { $shortname = ucfirst(Inflector::singularize($attributeName)); if (!$this->resourceCollection->getResourceForShortName($shortname)) { throw new InvalidArgumentException(sprintf('Type not supported (found "%s" in attribute "%s" of "%s")', $class, $attributeName, $currentResource->getEntityClass())); } else { $resource = $this->resourceCollection->getResourceForShortName($shortname); $context = $this->contextBuilder->bootstrapRelation($resource, $resource->getEntityClass()); } } else { $context = $this->contextBuilder->bootstrapRelation($currentResource, $class); } if (!$attributeMetadata->isDenormalizationLink()) { $object = $this->denormalize(json_encode($value), $resource->getEntityClass(), self::FORMAT, $context); //$this->deserializeObjects[] = $object; return $object; } throw new InvalidArgumentException(sprintf('Nested objects for attribute "%s" of "%s" are not enabled. Use serialization groups to change that behavior.', $attributeName, $currentResource->getEntityClass())); }