/** * {@inheritDoc} */ protected function getPropertiesForClass(ActionInterface $action, CallableInterface $callable, $class) { if (!$this->metadataFactory->supportsClass($class)) { return []; } $metadata = $this->metadataFactory->loadMetadata($class); $reflectionClass = Reflection::loadClassReflection($class); $properties = []; foreach ($metadata->getProperties() as $propertyName => $property) { $properties[] = $reflectionClass->getProperty($propertyName); } return $properties; }
/** * {@inheritDoc} */ public function loadMetadata($class) { if (is_object($class)) { $class = get_class($class); } $key = 'model_normalizer.annotated:' . $class; $metadata = $this->cache->get($key); if (null === $metadata) { $metadata = $this->delegate->loadMetadata($class); $this->cache->set($key, $metadata); } return $metadata; }
/** * {@inheritDoc} */ public function denormalize($data, ContextInterface $context) { $class = $context->getAttribute('_class'); if (!$class) { throw new DenormalizationFailedException('Undefined class for denormalization'); } $metadata = $this->metadataFactory->loadMetadata($class); if ($context->getGroups()) { $denormalizeProperties = $metadata->getPropertiesForGroups($context->getGroups()); } else { $denormalizeProperties = $metadata->getProperties(); } $classReflection = Reflection::loadClassReflection($class); if ($object = $context->getAttribute('_object')) { if (!is_object($object)) { throw UnexpectedTypeException::create($object, 'object'); } if (get_class($object) != $classReflection && !is_a($object, $class)) { throw UnexpectedTypeException::create($object, $class); } } else { $object = $classReflection->newInstanceWithoutConstructor(); } foreach ($denormalizeProperties as $denormalizePropertyName => $propertyMetadata) { $fieldName = $propertyMetadata->getFieldName(); if (!isset($data[$fieldName])) { continue; } $objectPropertyReflection = $classReflection->getProperty($denormalizePropertyName); if (!$objectPropertyReflection->isPublic()) { $objectPropertyReflection->setAccessible(true); } $denormalizedValue = $this->denormalizeValue($data[$fieldName], $propertyMetadata, $objectPropertyReflection); $objectPropertyReflection->setValue($object, $denormalizedValue); } return $object; }