Esempio n. 1
0
    }
}
function fooBefore()
{
    echo __FUNCTION__ . ' has been executed' . PHP_EOL;
    echo '------------------------------------------' . PHP_EOL;
}
function fooAfter()
{
    echo '------------------------------------------' . PHP_EOL;
    echo __FUNCTION__ . ' has been executed' . PHP_EOL;
}
$model = new Model();
//Bind function
microAOP\Proxy::__bind_func__($model, 'foo', 'before', 'fooBefore');
microAOP\Proxy::__bind_func__($model, 'foo', 'after', 'fooAfter');
$model->foo();
//取消绑定Model::foo中before位置的函数
microAOP\Proxy::__unbind_func__($model, 'foo', 'before');
echo '==========================================' . PHP_EOL;
$model->foo();
/*  output:

fooBefore has been executed
------------------------------------------
Model::foo has been executed
------------------------------------------
fooAfter has been executed
==========================================
Model::foo has been executed
------------------------------------------
Esempio n. 2
0
}
$model = new Model();
//Bind function
microAOP\Proxy::__bind_func__($model, 'foo', 'before', 'foo');
//Bind closure
microAOP\Proxy::__bind_func__($model, 'foo', 'after', $closure);
//Another way to bind closure
microAOP\Proxy::__bind_func__($model, 'three', 'after', function () {
    echo __FUNCTION__ . ' has been executed' . PHP_EOL;
});
//Bind Static method of class
microAOP\Proxy::__bind_func__($model, 'fooOne', 'before', 'Aspect::foo');
//Bind method of object
microAOP\Proxy::__bind_func__($model, 'two', 'before', array(new Aspect(), 'two'));
//Support for regex
microAOP\Proxy::__bind_func__($model, '/^foo.*/i', 'always', 'forRegex');
$model->foo();
echo '==========================================' . PHP_EOL;
$model->fooOne();
echo '==========================================' . PHP_EOL;
$model->two();
echo '==========================================' . PHP_EOL;
$model->three();
/*  output:

------------------------------------------
foo has been executed
Model::foo has been executed
------------------------------------------
{closure} has been executed
------------------------------------------