getAttributes(Settings::class); return count($attributes) > 0; } public function loadClassMetadata(string $className): ?Settings { $reflClass = new \ReflectionClass($className); $attributes = $reflClass->getAttributes(Settings::class); if (count($attributes) < 1) { return null; } if (count($attributes) > 1) { throw new \LogicException(sprintf('The class "%s" has more than one Settings attributes! Only one is allowed', $className)); } return $attributes[0]->newInstance(); } public function loadParameterMetadata(string $className): array { $parameters = []; $reflProperties = PropertyAccessHelper::getProperties($className); foreach ($reflProperties as $reflProperty) { $attributes = $reflProperty->getAttributes(SettingsParameter::class); if (count($attributes) < 1) { continue; } if (count($attributes) > 1) { throw new \LogicException(sprintf( 'The property "%s" of the class "%s" has more than one SettingsParameter attributes! Only one is allowed', $reflProperty->getName(), $className )); } $parameters[$reflProperty->getName()] = $attributes[0]->newInstance(); } return $parameters; } public function loadEmbeddedMetadata(string $className): array { $embeddeds = []; $reflProperties = PropertyAccessHelper::getProperties($className); foreach ($reflProperties as $reflProperty) { $attributes = $reflProperty->getAttributes(EmbeddedSettings::class); if (count($attributes) < 1) { continue; } if (count($attributes) > 1) { throw new \LogicException(sprintf( 'The property "%s" of the class "%s" has more than one EmbeddedSettings attributes! Only one is allowed', $reflProperty->getName(), $className )); } $embeddeds[$reflProperty->getName()] = $attributes[0]->newInstance(); } return $embeddeds; } public function getAllManagedClassNames(): array { $pathes = $this->searchPathes; $classes = []; foreach ($pathes as $path) { //Skip non-existing directories if (!is_dir($path)) { continue; } //Find all PHP classes in the given directories $constructs = Constructs::fromDirectory($path); $names = array_map(static function (Construct $construct): string { return $construct->name(); }, $constructs); $classes = array_merge($classes, $names); } //Now filter out all classes, which donot have the #[Settings] attribute $settings_classes = []; foreach ($classes as $class) { $reflClass = new \ReflectionClass($class); $attributes = $reflClass->getAttributes(Settings::class); if (count($attributes) > 0) { $settings_classes[] = $class; } } return $settings_classes; } }