<?php
use ProxyManager\Factory\AccessInterceptorValueHolderFactory;
class Foo
{
public function getValue()
{
return 10;
}
}
$factory = new AccessInterceptorValueHolderFactory();
$beforeExecution = [
'getValue' => function () {
echo 'Executing "getValue"' . PHP_EOL;
},
];
$afterExecution = [
'getValue' => function ($wrapper, $origClass, $methodName, $params, $returnValue, &$earlyReturn) {
$earlyReturn = true;
return $returnValue * 2;
},
];
// proxy for executing code before and after a method call
$proxy = $factory->createProxy(
new Foo(),
$beforeExecution,
$afterExecution
);
dump($proxy instanceOf Foo);
echo $proxy->getValue();