PHP code example of tractorcow / classproxy
1. Go to this page and download the library: Download tractorcow/classproxy 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/ */
tractorcow / classproxy example snippets
// Create a proxy creator
$proxy = ProxyFactory::create(DataBase::class)
->addMethod('connect', function ($args, $next) use ($logger) {
$logger->log("Connecting to server " . $args[0]['server'];
return $next(...$args);
});
// Generate instance of our proxy
$instance = $proxy->instance();
assert($instance instanceof Database); // Yep!
// Connects to underlying database, logging the call
$instance->connect([
'server' => 'localhost',
'user' => 'root'
]);