/**
  * @param array                $data
  * @param \ReflectionParameter $param
  * @param string               $format
  * @param array                $context
  *
  * @return object
  */
 protected function denormalizeParam($data, $param, $format, $context)
 {
     $name = $param->getName();
     $index = $param->getPosition();
     if (array_key_exists($name, $data)) {
         $value = $data[$name];
     } elseif (array_key_exists($index, $data)) {
         $value = $data[$index];
     } elseif ($param->isDefaultValueAvailable()) {
         $value = $param->getDefaultValue();
     } else {
         $message = sprintf('Missing parameter #%s: %s', $index, $name);
         throw new \RuntimeException($message);
     }
     if ($param->getClass()) {
         $class = $param->getClass()->getName();
     } elseif ($this->serializer->supportsDenormalization($value, MixedDenormalizer::TYPE, $format)) {
         $class = MixedDenormalizer::TYPE;
     }
     if (isset($class)) {
         $value = $this->serializer->denormalize($value, $class, $format, $context);
     }
     return $value;
 }
Exemple #2
0
 public function testSupportsArrayDeserialization()
 {
     $serializer = new Serializer(array(new GetSetMethodNormalizer(), new PropertyNormalizer(), new ObjectNormalizer(), new CustomNormalizer(), new ArrayDenormalizer()), array('json' => new JsonEncoder()));
     $this->assertTrue($serializer->supportsDenormalization(array(), __NAMESPACE__ . '\\Model[]', 'json'));
 }
 public function testDeserializeNotSupportedMissing()
 {
     $serializer = new Serializer(array(), array());
     $data = array('title' => 'foo', 'numbers' => array(5, 3));
     $this->assertFalse($serializer->supportsDenormalization(json_encode($data), '\\Symfony\\Component\\Serializer\\Tests\\Model', 'json'));
 }