letscodehu / php-dynamic-proxy
PHP 动态代理生成器
1.0.5
2017-02-18 07:32 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 3.7.*
README
PHP 动态代理生成器。
基于 Javassist ProxyFactory
用法
Config::set(["CACHE_DIRECTORY" => "/tmp/php-dynamic-proxy"]); $class = new ReflectionClass("Class"); $methodOverrides = [ new MethodHook { public function supports(ReflectionMethod $method) { return $method->getName() == "test"; } public function invoke($proxy, ReflectionMethod $method, array $args) { // before original method $returnValue = $method->invokeArgs($proxy, $args); // after original method return $returnValue; } } ]; $proxy = ProxyFactory::create($class, $methodOverrides);