dev-master
9999999-devUse your own interfaces by generating wrapper classes.
MIT
The Requires
The Development Requires
by Derek McLean
Wallogit.com
2017 © Pedro Peláez
Use your own interfaces by generating wrapper classes.
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., (*1)
Replacing Some\Symfony\Lib\SomeInterface with My\Awesome\Lib\SomeInterface will result in this before and after:, (*2)
<?php
namespace Some\Symfony\Lib;
class UsefulClass implements SomeInterface
{
// etc
}
<?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., (*3)
<?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
{
}
Install using composer, (*4)
$ composer require delboy1978uk/proxy-generator
You can use Del\ProxyGenerator\Service\ProxyGeneratorService if doing it programatically, or you can use the CLI command bin/proxy-generator., (*5)
$ cd bin $ ./proxy-generator 'VendorInterface' 'YourInterface' look/in/this/folder 'BaseVendorNamespace', 'YourBaseNamespace', 'relative/path/to/genarate', '/absolute/project/root/basedir'
Use your own interfaces by generating wrapper classes.
MIT