https://github.com/tractorcow/classproxy
Create partial proxies for classes
https://github.com/tractorcow/classproxy
class php proxy reflection
Last synced: 3 months ago
JSON representation
Create partial proxies for classes
- Host: GitHub
- URL: https://github.com/tractorcow/classproxy
- Owner: tractorcow
- Created: 2018-02-13T21:20:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-26T02:03:04.000Z (about 2 years ago)
- Last Synced: 2025-04-14T20:13:33.228Z (3 months ago)
- Topics: class, php, proxy, reflection
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Partial proxy class builder
[](https://travis-ci.org/tractorcow/classproxy)
[](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)Dynamically scaffold proxy classes that actually extend the class being proxied,
allowing them to be used in type-strict applications.No it's not prophecy because this is designed for partial proxies, not testing.
## Installation
```sh
composer require tractorcow/classproxy
```## Examples
```php
// 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'
]);
```