Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-26T02:03:04.000Z (over 1 year ago)
- Last Synced: 2024-09-22T03:18:23.307Z (4 months ago)
- Topics: class, php, proxy, reflection
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Partial proxy class builder
[![Build Status](https://travis-ci.org/tractorcow/classproxy.svg?branch=master)](https://travis-ci.org/tractorcow/classproxy)
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](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'
]);
```