/** * @param ArrayNormalizer $normalizer * @param mixed $value * @param PropertyMetadata $property * @param mixed $object * @param bool $inner * @return array|bool|DateTime|float|int|null|string * @throws InvalidArgumentException */ public function denormalizeProcess(ArrayNormalizer $normalizer, $value, $property, $object, $inner = false) { if ($value === null) { return null; } $transformerAliases = array(TransformerFactory::TYPE_SIMPLE_TRANSFORMER, TransformerFactory::TYPE_DATETIME_TRANSFORMER, TransformerFactory::TYPE_ARRAY_TRANSFORMER, TransformerFactory::TYPE_OBJECT_TRANSFORMER); $supports = false; foreach ($transformerAliases as $transformerAlias) { $transformer = $this->transformerFactory->getTransformer($transformerAlias, $normalizer, $this); if ($transformer->supportType($property->getType()) && $transformer->supportValueForDenormalization($value)) { if ($transformerAlias === TransformerFactory::TYPE_OBJECT_TRANSFORMER && !$inner) { $object = ObjectHelper::expose($object, $property); } $value = $transformer->denormalize($value, $property, $object); $supports = true; break; } } if (!$supports && $property->getType() !== null) { throw new InvalidArgumentException(sprintf('Unsupported type: %s', $property->getType())); } return $value; }
/** * @expectedException InvalidArgumentException */ public function testWrongAlias() { $this->transformerFactory->getTransformer('unknownTransformer', $this->normalizer, $this->processor); }