This package can be used to implement Aspect Oriented Programming (AOP) in PHP in a transparent way. This means that you can add or remove aspects to a class without changing its code.
The class provides an alternative for the PHP require() function that includes a PHP class and transparently modifies it to insert aspect advice code in the pointcuts defined in the class code that is going to have new orthogonal aspects added.
Also, it can automatically include advice code in automatic pointcuts, like at the begin and end of each method.
The pointcuts are marked in the class modify as simple PHP comments, so the class behavior is not affect when AOP support is not being used.
The automatic pointcuts do not need to be marked. This approach follows exactly the AOP theory, without need to touch a single line of 3rd-party code, for example.
The class is compiled and a new class file is generated with the code of the new aspects. The compiled class version is cached to avoid the recompilation overhead next time the same class is include using the same aspects.
The technique checks for changes in one of each XML file, or in original class file or even if new XML files were added/removed.
The aspects are defined in a separate XML file that includes the definition of the PHP advice code and the pointcuts where the code should inserted.
Optionally, the advice code can be compacted into a single line before it is inserted in the pointcuts, so the original class line numbers are preserved.
Another interesting option is to define the compiled files directory.
This package requires PHP 4.3.0 as it uses the PHP tokenizer extension. It does not use any external PHP extension. Innovation Award
 June 2006
Number 3
Prize: One book of choice by Packt |
Aspect Oriented Programming (AOP) is a recent topic with growing interest in the software development community.
It allows adding and removing aspects to the main code of an application without changing its core code, making possible to adapt applications to the needs of different environments with little or no maintenance effort.
This can be used for instance to add logging and debugging support to an application without changing the code to be debugged. The debugging aspect code is defined separately from the main code.
This way the same application code can be used with debugging enabled on development environment, and debugging disabled on the production environment so it can run at maximum speed and with less memory usage.
Currently, like most other popular language, PHP does not provide built-in AOP support. However, there have been several attempts to emulate AOP concepts in PHP.
This package provides solution that achieves a great level of transparency. It can add new aspects to a PHP class without changing the original class code.
This package uses a compilation approach that works by generating a new version of the class that gets the new aspects added. A smart caching technique is used to avoid recompilation overhead when the same class is used with the same aspects.
When it is necessary to use the class without any aspects, the original class is used without the presence of any advice or callback code in the pointcuts, to not slow down the original class.
Manuel Lemos |
| |
 |
|
Innovation award
 Nominee: 2x |
|