/** * {@inheritDoc} */ public function loadMetadata($class) { // Try get object annotation from class $objectAnnotation = null; $classAnnotations = Reflection::loadClassAnnotations($this->reader, $class, true); foreach ($classAnnotations as $classAnnotation) { if ($classAnnotation instanceof ObjectAnnotation) { if ($objectAnnotation) { throw new \RuntimeException(sprintf('Many @Transformer\\Object annotation in class "%s".', $class)); } $objectAnnotation = $classAnnotation; } } if (!$objectAnnotation) { throw new TransformAnnotationNotFoundException(sprintf('Not found @Object annotations in class "%s".', $class)); } // Try get properties annotations $properties = []; $classProperties = Reflection::getClassProperties($class, true); foreach ($classProperties as $classProperty) { $propertyAnnotations = $this->reader->getPropertyAnnotations($classProperty); foreach ($propertyAnnotations as $propertyAnnotation) { if ($propertyAnnotation instanceof PropertyAnnotation) { $property = new PropertyMetadata($propertyAnnotation->propertyName ?: $classProperty->getName(), $propertyAnnotation->groups, $propertyAnnotation->shouldTransform, $propertyAnnotation->expressionValue); $properties[$classProperty->getName()] = $property; } } } return new ObjectMetadata($objectAnnotation->transformedClass, $properties); }
/** * {@inheritDoc} */ public function loadMetadata($class) { // Try get @Object annotation $objectAnnotation = null; $classAnnotations = Reflection::loadClassAnnotations($this->reader, $class); foreach ($classAnnotations as $classAnnotation) { if ($classAnnotation instanceof ObjectAnnotation) { if ($objectAnnotation) { throw new \RuntimeException(sprintf('Many @Normalize\\Object annotations in class "%s".', $class)); } $objectAnnotation = $classAnnotation; } } // Try get @Property annotation from properties $properties = []; $classProperties = Reflection::getClassProperties($class, true); if ($objectAnnotation && $objectAnnotation->allProperties) { foreach ($classProperties as $classProperty) { /** @var PropertyAnnotation $propertyAnnotation */ $propertyAnnotation = $this->reader->getPropertyAnnotation($classProperty, 'FivePercent\\Component\\ModelNormalizer\\Annotation\\Property'); if ($propertyAnnotation) { $properties[$classProperty->getName()] = new PropertyMetadata($propertyAnnotation->fieldName ?: $classProperty->getName(), $propertyAnnotation->groups, $propertyAnnotation->shouldNormalize, $propertyAnnotation->expressionValue, $propertyAnnotation->denormalizerClass); } else { $properties[$classProperty->getName()] = new PropertyMetadata($classProperty->getName(), [], false, null); } } } else { foreach ($classProperties as $classProperty) { $propertyAnnotations = $this->reader->getPropertyAnnotations($classProperty); foreach ($propertyAnnotations as $propertyAnnotation) { if ($propertyAnnotation instanceof PropertyAnnotation) { $properties[$classProperty->getName()] = new PropertyMetadata($propertyAnnotation->fieldName ?: $classProperty->getName(), $propertyAnnotation->groups, $propertyAnnotation->shouldNormalize, $propertyAnnotation->expressionValue, $propertyAnnotation->denormalizerClass); } } } } if (!count($properties) && !$objectAnnotation) { throw new NormalizeAnnotationNotFoundException(sprintf('Not found normalize annotations in class "%s".', $class)); } return new ObjectMetadata($properties); }
/** * {@inheritDoc} */ public function loadMetadata($class) { $properties = Reflection::getClassProperties($class, true); $metadataProperties = []; foreach ($properties as $property) { $docBlock = new DocBlock($property); $docVarTags = $docBlock->getTagsByName('var'); if (count($docVarTags)) { /** @var \phpDocumentor\Reflection\DocBlock\Tag\VarTag $docVarTag */ $docVarTag = array_pop($docVarTags); $types = $docVarTag->getTypes(); $types = array_map(function ($type) { return ltrim($type, '\\'); }, $types); if (count($types)) { $propertyMetadata = new PropertyMetadata($types); $metadataProperties[$property->getName()] = $propertyMetadata; } } } $classMetadata = new ClassMetadata($metadataProperties); return $classMetadata; }
/** * Get properties for class * * @param ActionInterface $action * @param CallableInterface $callable * @param string $class * * @return \ReflectionProperty[] */ protected function getPropertiesForClass(ActionInterface $action, CallableInterface $callable, $class) { return Reflection::getClassProperties($class); }