Hello, everybody, i’m a php developer comes from china. After developed the extension named “Xaop” i wan to show it to phper for better uses of the AOP programming. the project can be found in github:
https://github.com/liqiongfan/xaop Here are some introduce and some usage of the extension “Xaop”: 1: PHPDoc based aop: ```php <?php /** * @Aspect */ class Swing { /** *@api(type=JSON, charset=UTF-8) */ public function good() { return [ ‘name’ => ‘Xaop’, ‘version’ => ‘0.99’]; } } ``` The xaop can parse the phpdoc and fetch the annotation of the doc, and do the aop job. Xaop contains the internal annotation support, which were: @api @disable @deprecated @before @after @success @failure and the user-defined annotation(need to implements the interface: Xaop\Annotations) 2: The method injection aop: Method injection aop support five aop mode: 1. before use the function :Xaop::addBeforeAop() to do the job. 2. after use Xaop::addAfterAop(). 3. after_return use Xaop::addAfterReturnAop(). 4. after_throw use Xaop::addAfterThrowAop(). 5. around use Xaop::AddAroundAop() to do the job. Here are some example for using the Xaop extension: 1: for before|after aop class Swing { function __get() { echo ‘yes’; } } Xaop::addBeforeAop(Swing::class, ‘__get*’, function(){ echo ‘before swing::__get()’; }); after doing the above job. when calling the __get function, it will first run the aop function and then the user-class function so output was: ```before swing::__get() yes``` 2. around aops: class Swing { function __get() { echo ‘yes’; } } Xaop::addAroundAop(Swing::class, ‘__get*’, function($xaopExec){ echo ‘before’; Xaop::exec($xaopExec);// This will run the metod context. currently means the Swing::__get() method echo ‘after’; }); so output was: ``` before yes after ``` The around aop will catch the all process of the target method, you can determine where|when to run. wish every one loves it. for this goal, i want to have a pecl account, please give me have a try. Thank you.