Ejemplo n.º 1
0
 /**
  * return params route
  * @param $name
  * @param string $type
  * @return array
  */
 protected function getParamsByResource(&$name, $type = 'item')
 {
     $parentResource = null;
     $parameters = [];
     $version = $this->getScope()->getDunglasResource()->getVersion();
     if ($resource = $this->resourceCollection->getResourceForEntityWithVersion($name, $version)) {
         $parameters = $resource->getRouteKeyParams($name);
         if (empty($parameters)) {
             $parameters['id'] = $this->propertyAccessor->getValue($name, 'id');
         }
         if (null !== $resource->getParent() && !isset($parameters[$resource->getParentName()])) {
             $parentResource = $resource->getParent();
             $parentObject = $this->propertyAccessor->getValue($name, Inflector::singularize($resource->getParentName()));
             $parentParams = $parentResource->getRouteKeyParams($parentObject);
             $parameters = array_merge($parentParams, $parameters);
         }
         $name = $this->getItemRouteName($resource, $type);
     }
     return $parameters;
 }
Ejemplo n.º 2
0
 /**
  * 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()));
 }