php-aop icon indicating copy to clipboard operation
php-aop copied to clipboard

Add custom dependency injection logic for aspects

Open WalterWoshid opened this issue 2 years ago • 5 comments

Maybe a protected method in the kernel that allows to add custom logic for dependency injection when instantiating new aspects

WalterWoshid avatar Sep 10 '23 22:09 WalterWoshid

Also see https://github.com/okapi-web/php-aop/issues/9#issuecomment-1662251236

WalterWoshid avatar Sep 10 '23 23:09 WalterWoshid

  • [ ] Make sure that aspects are instantiated when needed, this could be done by adding an instruction to the constructor in the woven class

WalterWoshid avatar Sep 16 '23 16:09 WalterWoshid

Done: https://github.com/okapi-web/php-aop/pull/67

WalterWoshid avatar Nov 05 '23 22:11 WalterWoshid

Hi @jakublabno, I believe this is a feature you wanted, check out PHP-AOP: 1.2.8 :)

This is not yet documented, but the only thing you have to do is extend the dependencyInjectionHandler method in your AopKernel and pass in a Closure which accepts a class-string of the Aspect and should return an instance of that Aspect.

You can also look at the CustomDependencyInjectionHandler test for a better example!

WalterWoshid avatar Nov 05 '23 22:11 WalterWoshid

Reopened due to: https://github.com/okapi-web/php-aop/issues/37#issuecomment-1722263089

WalterWoshid avatar Nov 05 '23 22:11 WalterWoshid