public function create(string $resourceClass, string $property, array $options = []) : PropertyMetadata
{
$parentPropertyMetadata = null;
if ($this->decorated) {
try {
$parentPropertyMetadata = $this->decorated->create($resourceClass, $property, $options);
} catch (PropertyNotFoundException $propertyNotFoundException) {
// Ignore not found exception from decorated factories
}
}
try {
$reflectionClass = new \ReflectionClass($resourceClass);
} catch (\ReflectionException $reflectionException) {
return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property);
}
if ($reflectionClass->hasProperty($property)) {
$annotation = $this->reader->getPropertyAnnotation($reflectionClass->getProperty($property), ApiProperty::class);
if (null !== $annotation) {
return $this->createMetadata($annotation, $parentPropertyMetadata);
}
}
foreach (array_merge(Reflection::ACCESSOR_PREFIXES, Reflection::MUTATOR_PREFIXES) as $prefix) {
$methodName = $prefix . ucfirst($property);
if (!$reflectionClass->hasMethod($methodName)) {
continue;
}
$reflectionMethod = $reflectionClass->getMethod($methodName);
if (!$reflectionMethod->isPublic()) {
continue;
}
$annotation = $this->reader->getMethodAnnotation($reflectionMethod, ApiProperty::class);
if (null !== $annotation) {
return $this->createMetadata($annotation, $parentPropertyMetadata);
}
}
return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property);
}