borkness/phproxy

Simple trait to allow static proxies similar to Laravel Facades

v1.0.0 2020-10-06 20:09 UTC

This package is auto-updated.

Last update: 2024-05-07 03:35:56 UTC


README

StyleCI Build Status

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';
    }
}