diff --git a/src/Annotations/Feature.php b/src/Annotations/Feature.php index 683a315..d4acae3 100644 --- a/src/Annotations/Feature.php +++ b/src/Annotations/Feature.php @@ -1,7 +1,7 @@ name = $name; + } else { + $this->name = $name['value']; + } + } + + public function getName() + { + return $this->name; + } } diff --git a/src/Listener/AnnotationSubscriber.php b/src/Listener/AnnotationSubscriber.php index a1e4e98..e58c330 100644 --- a/src/Listener/AnnotationSubscriber.php +++ b/src/Listener/AnnotationSubscriber.php @@ -74,6 +74,18 @@ public function onKernelController(ControllerEvent $event) } $object = new ReflectionClass($controller[0]); + + // check for php8 attributes on the controller class + if (method_exists($object, 'getAttributes')) { + foreach ($object->getAttributes(Feature::class) as $attribute) { + $name = $attribute->getArguments()['name']; + if (!$this->manager->isActive($name)) { + throw new NotFoundHttpException(sprintf('Feature %s for class %s is not active.', $name, $object->getName())); + } + } + } + + foreach ($this->reader->getClassAnnotations($object) as $annotation) { if ($annotation instanceof Feature) { if (!$this->manager->isActive($annotation->name)) { @@ -83,6 +95,17 @@ public function onKernelController(ControllerEvent $event) } $method = $object->getMethod($controller[1]); + + // check for php8 attributes on the method + if (method_exists($method, 'getAttributes')) { + foreach ($method->getAttributes(Feature::class) as $attribute) { + $name = $attribute->getArguments()['name']; + if (!$this->manager->isActive($name)) { + throw new NotFoundHttpException(sprintf('Feature %s for method %s is not active.', $name, $method->getName())); + } + } + } + foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof Feature) { if (!$this->manager->isActive($annotation->name)) { diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index fe3e24e..b2fd401 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,11 +1,13 @@ services: flagception.manager.feature_manager: class: Flagception\Manager\FeatureManager + tags: + - { name: routing.condition_service } arguments: - '@flagception.activator.chain_activator' - '@flagception.decorator.chain_decorator' public: true - + Flagception\Manager\FeatureManagerInterface: '@flagception.manager.feature_manager' flagception.expression_language: