tractorcow/classproxy

1.0.0 2022-04-25 23:46 UTC

This package is auto-updated.

Last update: 2024-08-26 04:54:10 UTC


README

Build Status SilverStripe supported module

动态构建代理类,这些类实际上扩展了被代理的类,使得它们可以在类型严格的应用程序中使用。

这不是预言,因为这个工具是为部分代理设计的,而不是用于测试。

安装

composer require tractorcow/classproxy

示例

// 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'
]);