Add a getAttributes to IControllerMethodReflector#37279
Conversation
Signed-off-by: Joas Schilling <coding@schilljs.com>
|
I'm on the fence here. It's a small enhancement in all fairness. |
| } else { | ||
| $reflectionMethod = new ReflectionMethod($controller, $methodName); | ||
| $attributes = $reflectionMethod->getAttributes(BruteForceProtection::class); | ||
| $attributes = $this->reflector->getAttributes(BruteForceProtection::class); |
Check failure
Code scanning / Psalm
InvalidArgument
| } else { | ||
| $reflectionMethod = new ReflectionMethod($controller, $methodName); | ||
| $attributes = $reflectionMethod->getAttributes(BruteForceProtection::class); | ||
| $attributes = $this->reflector->getAttributes(BruteForceProtection::class); |
Check failure
Code scanning / Psalm
InvalidArgument
|
|
||
| $reflectionMethod = new ReflectionMethod($controller, $methodName); | ||
| $hasAttribute = !empty($reflectionMethod->getAttributes(UseSession::class)); | ||
| $hasAttribute = !empty($this->reflector->getAttributes(UseSession::class)); |
Check failure
Code scanning / Psalm
InvalidArgument
|
|
||
| $reflectionMethod = new ReflectionMethod($controller, $methodName); | ||
| $hasAttribute = !empty($reflectionMethod->getAttributes(UseSession::class)); | ||
| $hasAttribute = !empty($this->reflector->getAttributes(UseSession::class)); |
Check failure
Code scanning / Psalm
InvalidArgument
| */ | ||
| class ControllerMethodReflector implements IControllerMethodReflector { | ||
|
|
||
| protected ?\ReflectionMethod $reflection; |
There was a problem hiding this comment.
To be more specific because exist other types of reflections:
| protected ?\ReflectionMethod $reflection; | |
| protected ?\ReflectionMethod $reflectionMethod; |
| } | ||
|
|
||
| /** | ||
| * @template T of Attribute |
There was a problem hiding this comment.
Attribute classes do not extend Attribute class, which is final. So you cannot do that.
|
Subjectively what I don't like about the controller method reflector is that is so stateful. There are two methods to work with it. One analyzes a controller method, another one allows you to test for specific attributes. It sounds a bit artificial but there is no guarantee that at the point of asking for an attribute, nobody else called the In that sense, and with the way PHP reflection works anyway, I would prefer to make the service stateless and pass the controller object and method name into This remark is not new with attributes. The problem was there with annotations as well. It is just that parsing phpdoc annotations is expensive and there the state for caching makes sense for better performance. |
|
Exactly my thoughts after seeing the resulting PR. |
As discussed in #36928 (comment)
Looking at the diff, I'm not sure it's worth it.
Checklist