PHP code example of letscodehu / php-dynamic-proxy

1. Go to this page and download the library: Download letscodehu/php-dynamic-proxy 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/ */

    

letscodehu / php-dynamic-proxy example snippets


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);