{ echo __METHOD__ . ' has been executed' . PHP_EOL; } } class Aspect { public function argsAlways($params) { echo '------------------------------------------' . PHP_EOL; echo __METHOD__ . ' has been executed' . PHP_EOL; print_r($params['args']); } } $model = new Model(); //Just bind it microAOP\Proxy::__bind__($model, new Aspect()); $model->args('arg1', 'argTwo'); echo "===========================================" . PHP_EOL; $model->args('one', 'two', 'argThree'); /* output: Model::args has been executed ------------------------------------------ Aspect::argsAlways has been executed Array ( [one] => arg1 [two] => argTwo [three] => three ) ===========================================
public function fooBefore($params) { echo '------------------------------------------' . PHP_EOL; echo __METHOD__ . ' has been executed' . PHP_EOL; } } class AspectThree { public function fooAfter($params) { echo '------------------------------------------' . PHP_EOL; echo __METHOD__ . ' has been executed' . PHP_EOL; } } $model = new Model(); //Bind multi aspect objects microAOP\Proxy::__bind__($model, 'AspectOne', 'AspectTwo', 'AspectThree'); $model->foo(); /* output: ------------------------------------------ AspectOne::fooBefore has been executed ------------------------------------------ AspectTwo::fooBefore has been executed Model::foo has been executed ------------------------------------------ AspectOne::fooAfter has been executed ------------------------------------------ AspectThree::fooAfter has been executed */
echo __METHOD__ . ' has been executed' . PHP_EOL; } } class Aspect { public function saveBefore($params) { echo '------------------------------------------' . PHP_EOL; echo __METHOD__ . ' has been executed' . PHP_EOL; } public function saveAfter($params) { echo '------------------------------------------' . PHP_EOL; echo __METHOD__ . ' has been executed' . PHP_EOL; } } $model = new Model(); //Just bind it by classname microAOP\Proxy::__bind__($model, 'Aspect'); //You can bing it by Instance too, like this //microAOP\Proxy::__bind__($model, new Aspect()); $model->save(); /* output: ------------------------------------------ Aspect::saveBefore has been executed Model::save has been executed ------------------------------------------ Aspect::saveAfter has been executed */