okapi-web / php-aop

PHP-AOP is a library that adds aspect oriented programming capabilities to PHP.
https://github.com/okapi-web/php-aop
MIT License
32 stars 3 forks source link

Add custom dependency injection logic for aspects #37

Open WalterWoshid opened 1 year ago

WalterWoshid commented 1 year ago

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

WalterWoshid commented 1 year ago

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

WalterWoshid commented 1 year ago
WalterWoshid commented 1 year ago

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

WalterWoshid commented 1 year ago

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 commented 1 year ago

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