As I wrote earlier, I am not satisfied with the Current State of AOP for PHP and started to work on AspectPHP a while ago. Today I am going to share my ideas on the subject.
Inside a method that is used as an advice a special variable, $joinPoint, is available that contains all information relevant to the join point that triggered the execution of the advice.
The example belows shows how to declare an aspect that logs all method calls:
<?php /** * An aspect that logs all method calls. * * Declare a new pointcut named callPointCut using the @pointcut * annotation that captures join points on a method regardless of * modifier, class, method, or number of parameters. * @pointcut callPointCut : call(* *->*(..)); * * Bind the after() method of this aspect as an after-advice to the * previously declared pointcut. * @after callPointCut : LoggingAspect->after(); */ classLoggingAspect { publicfunctionafter() { printf( "%s->%s() called %s->%s()\n", $joinPoint->getSource()->getDeclaringClass()->getName(), $joinPoint->getSource()->getName(), $joinPoint->getTarget()->getDeclaringClass()->getName(), $joinPoint->getTarget()->getName() ); } } ?>
Unfortunately, I am too busy with other projects (preparing for my final two exams and working on PHPUnit 3) and therefore cannot offer any downloadable code at this point.
I hope to make an initial code release within the next two months.