This package provides a static constructor interface, and a trait that implements the interface.
Via Composer:
composer require aviator/makeable
Via Composer:
composer test
Use the trait:
class Something
{
use MakeableTrait;
}Then the class can be instantiated using Class::make(...$args):
$instance = Something::make($arg1, $arg2);The interface is optional, though it can be useful in composite interfaces to specify that a static constructor should be present:
interface SomeInterface extends Makeable, SomeOtherInterface
{
/* ... etc */
}Since the static constructor simply returns new static(...$args), it can be used in abstract classes and parent classes without having to re-use it on child classes:
abstract class Seuss
{
use MakeableTrait;
}
class ThingOne extends Seuss {};
class ThingTwo extends ThingOne {};
// Get an instance of ThingOne
$instance = ThingOne::make();
// Get an instance of ThingTwo
$instance = ThingTwo::make();This package is licensed with the MIT License (MIT).