PHP code example of tmont / phroxy
1. Go to this page and download the library: Download tmont/phroxy library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tmont / phroxy example snippets
use Tmont\Phroxy\Interceptor;
use Tmont\Phroxy\InterceptorCache;
use Tmont\Phroxy\InterceptionContext;
use ReflectionClass;
class ReturnBeforeCallInterceptor implements Interceptor {
public function onBeforeMethodCall(InterceptionContext $context) {
$context->setReturnValue('oh hai!');
}
public function onAfterMethodCall(InterceptionContext $context) {}
}
class MyClass {
public function hello() {
return 'hello';
}
}
$interceptor = new ReturnBeforeCallInterceptor();
InterceptorCache::registerInterceptor($interceptor, function($x) { return true; });
$proxy = $this->builder->build(new ReflectionClass('MyClass'));
$proxy->hello(); // "oh hai!"