diff --git a/README.md b/README.md index b91120d..c22eb4a 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ Now that you have the basic setup, you can add some additional options and custo Default configuration: ```yaml # config/packages/loggastic.yaml -loggastic: +locastic_loggastic: # directory paths containing loggable classes or xml/yaml files loggable_paths: - '%kernel.project_dir%/Resources/config/loggastic' diff --git a/src/Annotation/Loggable.php b/src/Annotation/Loggable.php index 3847579..1c004f5 100644 --- a/src/Annotation/Loggable.php +++ b/src/Annotation/Loggable.php @@ -13,7 +13,7 @@ class Loggable public function __construct(array $groups) { - $this->groups = $groups['groups']; + $this->groups = $groups; } public function getGroups(): array diff --git a/src/Metadata/LoggableContext/Factory/AnnotationLoggableContextCollectionFactory.php b/src/Metadata/LoggableContext/Factory/AnnotationLoggableContextCollectionFactory.php index c302544..844fd2b 100644 --- a/src/Metadata/LoggableContext/Factory/AnnotationLoggableContextCollectionFactory.php +++ b/src/Metadata/LoggableContext/Factory/AnnotationLoggableContextCollectionFactory.php @@ -16,12 +16,9 @@ public function __construct(private readonly LoggableContextCollectionFactoryInt { } - /** - * {@inheritdoc} - */ public function create(): LoggableContextCollection { - if(count($this->loggablePaths) === 0) { + if (count($this->loggablePaths) === 0) { return new LoggableContextCollection([]); } @@ -34,16 +31,26 @@ public function create(): LoggableContextCollection } foreach (RecursiveClassIterator::getReflectionClasses($this->loggablePaths) as $className => $reflectionClass) { - if ( - (\PHP_VERSION_ID >= 80000 && $reflectionClass->getAttributes(Loggable::class)) || - (null !== $this->reader && $loggable = $this->reader->getClassAnnotation($reflectionClass, Loggable::class)) - ) { - if (!empty($loggable)) { - $classes[$className] = ['groups' => $loggable->getGroups()]; - } + if ($loggable = $this->getLoggableAttribute($reflectionClass)) { + $classes[$className] = ['groups' => $loggable->getGroups()]; + } + + if (null !== $this->reader && $loggable = $this->reader->getClassAnnotation($reflectionClass, Loggable::class)) { + $classes[$className] = ['groups' => $loggable->getGroups()]; } } return new LoggableContextCollection($classes); } + + private function getLoggableAttribute(\ReflectionClass $reflectionClass): ?Loggable + { + foreach ($reflectionClass->getAttributes() as $attribute) { + if (is_a($attribute->getName(), Loggable::class, true)) { + return $attribute->newInstance(); + } + } + + return null; + } }