delboy1978uk/proxy-generator

Use your own interfaces by generating wrapper classes.

dev-master 2016-11-28 01:51 UTC

This package is auto-updated.

Last update: 2024-11-04 22:31:39 UTC


README

Build Status Code Coverage Scrutinizer Code Quality
A Proxy generator for getting third party libraries to implement your interface. Just tell it what Interface you wish to replace, and it will search through, and generate your own class extending it but implementing your own interface. ##Example Replacing Some\Symfony\Lib\SomeInterface with My\Awesome\Lib\SomeInterface will result in this before and after: ####Before

<?php

namespace Some\Symfony\Lib;

class UsefulClass implements SomeInterface 
{
    // etc
}

####After

<?php

namespace My\Awesome\Lib;

use Some\Symfony\Lib\UsefulClass as ThirdPartyUsefulClass;

class UsefulClass extends ThirdPartyUsefulClass implements SomeInterface 
{
}

For each class implementing the interface, we recursively iterate over the vendor classes and generate any classes extending them. These classes will also implement our interface.

<?php

namespace My\Awesome\Lib\Number;

use Some\Symfony\Lib\Number\UsefulNuberClass as ThirdPartyUsefulNumberClass;
use My\Awesome\Lib\SomeInterface;

class UsefulClass extends ThirdPartyUsefulNumberClass implements SomeInterface 
{
}

##Installation Install using composer

$ composer require delboy1978uk/proxy-generator

##Usage You can use Del\ProxyGenerator\Service\ProxyGeneratorService if doing it programatically, or you can use the CLI command bin/proxy-generator.

$ cd bin
$ ./proxy-generator 'VendorInterface' 'YourInterface' look/in/this/folder 'BaseVendorNamespace', 'YourBaseNamespace', 'relative/path/to/genarate', '/absolute/project/root/basedir'