goaop / framework

:gem: Go! AOP PHP - modern aspect-oriented framework for the new level of software development
go.aopphp.com
MIT License
1.66k stars 163 forks source link

Intercept all methods from an annotated class #491

Closed cboratto closed 5 months ago

cboratto commented 8 months ago

Hi,

Not sure how to intercept all methods from an annotated class.

Looking at the test on the PR https://github.com/goaop/framework/pull/129/files#diff-2cdbb861d2c3f670e621c5cb910b07c09789e6028b262c7f4ebed60823146884R81 it seems possible to do it.

I changed the target from one of my annotation from METHOD to CLASS, but now it pops me with an error:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Aop\Aspect\HttpClientAspect::beforeMethodExecution() must implement interface Go\Aop\Intercept\MethodInvocation, instance of Go\Aop\Framework\StaticInitializationJoinpoint given, called in /home/user/aop-poc/vendor/goaop/framework/src/Aop/Framework/BeforeInterceptor.php on line 30 and defined in /home/user/aop-poc/src/Aspect/HttpClientAspect.php:28

lisachenko commented 5 months ago

Proper syntax should be @within(Some\Annotation\Class) && execution(public **->*(*)). This syntax combines "within" that matches any joinpoints inside class (method call, property access, object initialization, class initialization) and "execution" pointcut that further filters joinpoints only to method calls inside such class.

See PointcutParserTest::validPointcutDefinitions() test method for examples.