/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null) { $validatorClassMetadata = $this->validatorMetadataFactory->getMetadataFor($classMetadata->getName()); foreach ($classMetadata->getAttributes() as $attributeMetadata) { $attributeName = $attributeMetadata->getName(); foreach ($validatorClassMetadata->getPropertyMetadata($attributeName) as $propertyMetadata) { if (null === $validationGroups) { foreach ($propertyMetadata->findConstraints($validatorClassMetadata->getDefaultGroup()) as $constraint) { if ($this->isRequired($constraint)) { $attributeMetadata->setRequired(true); break 2; } } } else { foreach ($validationGroups as $validationGroup) { foreach ($propertyMetadata->findConstraints($validationGroup) as $constraint) { if ($this->isRequired($constraint)) { $attributeMetadata->setRequired(true); break 3; } } } } } } return true; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null) { if (($classReflector = $this->getClassReflector($classMetadata->getReflectionClass())) && ($docBlock = $classReflector->getDocBlock())) { $classMetadata->setDescription($docBlock->getShortDescription()); } foreach ($classMetadata->getAttributes() as $attributeMetadata) { if ($reflectionProperty = $this->getReflectionProperty($classMetadata->getReflectionClass(), $attributeMetadata->getName())) { $attributeMetadata->setDescription($this->propertyInfo->getShortDescription($reflectionProperty)); } } return true; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null) { $doctrineClassMetaData = $this->entityManager->getClassMetadata($classMetadata->getReflectionClass()->getName()); $identifiers = $doctrineClassMetaData->getIdentifier(); if (1 === count($identifiers)) { $identifierName = $identifiers[0]; foreach ($classMetadata->getAttributes() as $attribute) { if ($attribute->getName() === $identifierName) { $attribute->setIdentifier(true); break; } } } return true; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null) { $reflectionClass = $classMetadata->getReflectionClass(); if ($iri = $this->reader->getClassAnnotation($reflectionClass, self::IRI_ANNOTATION_NAME)) { $classMetadata->setIri($iri->value); } foreach ($classMetadata->getAttributes() as $attributeMetadata) { $attributeName = $attributeMetadata->getName(); if ($reflectionProperty = $this->getReflectionProperty($reflectionClass, $attributeName)) { if ($iri = $this->reader->getPropertyAnnotation($reflectionProperty, self::IRI_ANNOTATION_NAME)) { $attributeMetadata->setIri($iri->value); } } } return true; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null) { $className = $classMetadata->getReflectionClass()->name; $manager = $this->managerRegistry->getManagerForClass($className); if (!$manager) { return true; } $doctrineClassMetaData = $manager->getClassMetadata($className); if (!$doctrineClassMetaData) { return true; } $identifiers = $doctrineClassMetaData->getIdentifier(); if (1 !== count($identifiers)) { return true; } $identifierName = $identifiers[0]; foreach ($classMetadata->getAttributes() as $attribute) { if ($attribute->getName() === $identifierName) { $attribute->setIdentifier(true); return true; } } return true; }
/** * Gets or creates the {@see AttributeMetadata} of the given name. * * @param ClassMetadata $classMetadata * @param string $attributeName * @param string[]|null $normalizationGroups * * @return AttributeMetadata */ private function getOrCreateAttribute(ClassMetadata $classMetadata, $attributeName, array $normalizationGroups = null, array $denormalizationGroups = null) { if (isset($classMetadata->getAttributes()[$attributeName])) { return $classMetadata->getAttributes()[$attributeName]; } $attributeMetadata = new AttributeMetadata($attributeName); $classMetadata->addAttribute($attributeMetadata); $reflectionProperty = $this->getReflectionProperty($classMetadata->getReflectionClass(), $attributeName); if (!$reflectionProperty) { return $attributeMetadata; } $types = $this->propertyInfo->getTypes($reflectionProperty); if (null !== $types) { $attributeMetadata->setTypes($types); } if (!isset($types[0])) { return $attributeMetadata; } $class = $types[0]->getClass(); if (!$this->resourceCollection->getResourceForEntity($class) && !($types[0]->isCollection() && $types[0]->getCollectionType() && ($class = $types[0]->getCollectionType()->getClass()) && $this->resourceCollection->getResourceForEntity($class))) { return $attributeMetadata; } if (null === $normalizationGroups) { $attributeMetadata->setNormalizationLink(true); } if (null === $denormalizationGroups) { $attributeMetadata->setDenormalizationLink(true); } if ($attributeMetadata->isNormalizationLink() && $attributeMetadata->isDenormalizationLink()) { return $attributeMetadata; } if (!$this->serializerClassMetadataFactory || !($relationSerializerMetadata = $this->serializerClassMetadataFactory->getMetadataFor($class))) { $attributeMetadata->setNormalizationLink(true); $attributeMetadata->setDenormalizationLink(true); return $attributeMetadata; } foreach ($relationSerializerMetadata->getAttributesMetadata() as $serializerAttributeMetadata) { $serializerAttributeGroups = $serializerAttributeMetadata->getGroups(); if (null !== $normalizationGroups && 1 <= count(array_intersect($normalizationGroups, $serializerAttributeGroups))) { $normalizationLink = false; } if (null !== $denormalizationGroups && 1 <= count(array_intersect($denormalizationGroups, $serializerAttributeGroups))) { $denormalizationLink = false; } if (isset($normalizationLink) && isset($denormalizationLink)) { return $attributeMetadata; } } if (!isset($normalizationLink)) { $attributeMetadata->setNormalizationLink(true); } if (!isset($denormalizationLink)) { $attributeMetadata->setDenormalizationLink(true); } return $attributeMetadata; }
/** * @param ClassMetadata $classMetaData * * @throws \RunTimeException */ private function checkClassMetaData(ClassMetadata $classMetaData) { if (!$classMetaData->getIdentifier()) { throw new \RunTimeException(sprintf('Class "%s" have no identifier.', $classMetaData->getName())); } }
/** * @param ClassMetadata $classMetaData * * @throws \Exception */ private function checkClassMetaData(ClassMetadata $classMetaData) { if (($identifier = $classMetaData->getIdentifier()) === null) { throw new \Exception(sprintf('Class "%s" have no identifier', $classMetaData->getName())); } }
public function testGetReflectionClass() { $this->assertInstanceOf('\\ReflectionClass', $this->classMetadata->getReflectionClass()); }