borkness / phproxy
Simple trait to allow static proxies similar to Laravel Facades
v1.0.0
2020-10-06 20:09 UTC
Requires (Dev)
- php-di/php-di: ^6.2
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2025-04-07 05:43:38 UTC
README
Phproxy is a class that can be used to statically call the methods of an underlying class similar to Facades in Laravel.
Usage
Initial Setup
In order to use Phproxy you must implement a PSR-11 compatible container. Implementations you could use are:
- PHP-DI (Recommended)
- League Container
- Aura-DI
Once you have installed and created the container you need to call the setInstanceResolver()
method passing in the container.
\Borkness\Phproxy\Phproxy::setInstanceResolver($container);
Creating a proxy class
To create a proxy class you will need to extend the Phproxy abstract class overriding the getClassIdentifier()
method. You must add the string you used for the class when setting up the DI container.
Example:
<?php namespace App\Proxies; use Borkness\Phproxy\Phproxy; class Database extends Phproxy { public static function getClassIdentifier() { return 'db'; } }