PHP Classes

Transparent PHP AOP: PHP AOP implementation based on cache compilation

Recommend this page to a friend!
  Info   Screenshots Screenshots   View files View files (20)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 64%Total: 1,137 All time: 3,315 This week: 349Up
Version License Categories
aop 1.0Free for non-comm...Language
Description 

Author

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
PHP Programming Innovation award nominee
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
Picture of Guilherme Blanco
Name: Guilherme Blanco <contact>
Classes: 5 packages by
Country: Brazil Brazil
Age: 40
All time rank: 22815 in Brazil Brazil
Week rank: 312 Down26 in Brazil Brazil Down
Innovation award
Innovation award
Nominee: 2x

  Files folder image Files  
File Role Description
Files folder imagetutorial (3 files)
Plain text file aop.dtd Data DTD for XAD (Xml Aspect Definitions)
Plain text file CHANGELOG.txt Doc. List of changes
Plain text file class.Advice.php Class Advice
Plain text file class.AOP.php Class Main class
Plain text file class.AOP_CodeCompiler.php Class Class to compile AOP code
Plain text file class.AOP_CodeCruncher.php Class Auxiliar class do crunch PHP code
Plain text file class.AOP_CodeParser.php Class Class to retrieve PHP code as tokens
Plain text file class.AOP_XMLElement.php Class XML Element for XML Parser class
Plain text file class.AOP_XMLReader.php Class XML Parser class
Plain text file class.Aspect.php Class Aspect loader
Plain text file class.AutoPointcut.php Class AutoPointcut Class
Plain text file class.CustomPointcut.php Class CustomPointcut Class
Plain text file class.Pointcut.php Class Pointcut holder
Plain text file class.Weave.php Class Weave
Plain text file func.require_aop.php Aux. Function require_aop
Accessible without login HTML file Manual.html Doc. Manual of usage
Accessible without login Plain text file TODO.txt Data TODO List

  Files folder image Files  /  tutorial  
File Role Description
  Plain text file class.Test.php Class Tutorial Test class
  Plain text file debugger.xml Data Tutorial XML file
  Plain text file index.php Example Tutorial main script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,137
This week:0
All time:3,315
This week:349Up
User Ratings User Comments (2)
 All time
Utility:75%StarStarStarStar
Consistency:85%StarStarStarStarStar
Documentation:70%StarStarStarStar
Examples:55%StarStarStar
Tests:-
Videos:62%StarStarStarStar
Overall:64%StarStarStarStar
Rank:678
 
Good Package for Free but not commercial use.
10 years ago (velmurugan)
82%StarStarStarStarStar
Excellent
14 years ago (kishore kumar)
85%StarStarStarStarStar