public function create(string $resourceClass, array $options = []) : PropertyNameCollection
{
if ($this->decorated) {
try {
$propertyNameCollection = $this->decorated->create($resourceClass, $options);
} catch (ResourceClassNotFoundException $resourceClassNotFoundException) {
// Ignore not found exceptions from parent
}
}
try {
$reflectionClass = new \ReflectionClass($resourceClass);
} catch (\ReflectionException $reflectionException) {
if (isset($propertyNameCollection)) {
return $propertyNameCollection;
}
throw new ResourceClassNotFoundException(sprintf('The resource class "%s" does not exist.', $resourceClass));
}
$propertyNames = [];
// Properties
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
if (null !== $this->reader->getPropertyAnnotation($reflectionProperty, ApiProperty::class)) {
$propertyNames[$reflectionProperty->name] = true;
}
}
// Methods
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
$propertyName = $this->reflection->getProperty($reflectionMethod->name);
if (!preg_match('/^[A-Z]{2,}/', $propertyName)) {
$propertyName = lcfirst($propertyName);
}
if (null !== $propertyName && null !== $this->reader->getMethodAnnotation($reflectionMethod, ApiProperty::class)) {
$propertyNames[$propertyName] = true;
}
}
// Inherited from parent
if (isset($propertyNameCollection)) {
foreach ($propertyNameCollection as $propertyName) {
$propertyNames[$propertyName] = $propertyName;
}
}
return new PropertyNameCollection(array_keys($propertyNames));
}