aop-io / php-aop
Implements a simplified subset of AOP pragmatism and provides the AOP (Aspect Oriented Programming) features for PHP.
Requires
- php: >=5.4
Suggests
- aop-io/pecl-aop-interceptor: Interceptor using the PECL AOP extension.
This package is auto-updated.
Last update: 2024-11-05 23:01:42 UTC
README
Implements a simplified subset of AOP (Aspect Oriented Programming) pragmatism and provides the AOP features for PHP application.
Only one dependency, the code interceptor.
The PHP lib of AOP.io provides an abstraction layer easy to use for AOP development, so it can work with several PHP code interceptors.
The first interceptor implemented uses PECL AOP-PHP extension.
Other interceptors are planned. If you want to create an interceptor, see the skeleton.
Getting Started
Install
-
Install an interceptor, e.g: PECL AOP-PHP extension.
-
Download PHP AOP.io lib (and configure your autoloader) or use composer
require: "aop-io/php-aop"
.
Usage
use Aop\Aop; // Init new Aop(); function hello($name) { return $name } // Interception of kind 'around' Aop::addAround('hello()', function($joinPoint) { // In this context, // $joinPoint is an instance of \Aop\JoinPoint\AroundFunctionJoinPoint // get an array with all arguments values var_dump($joinPoint->getArgs()); // (array) 0 => World ! // change the return value $joinPoint->setReturnValue('Hello Nico !'); // Proceed the execution of the function ( hello() ) $joinPoint->proceed(); }); echo hello('World !'); // Hello Nico !
License
MIT (c) 2013, Nicolas Tallefourtane.