aviator/makeable

This package is abandoned and no longer maintained. No replacement package was suggested.

Static constructor trait and interface.

0.1.0 2017-11-30 17:05 UTC

This package is auto-updated.

Last update: 2024-04-21 19:37:14 UTC


README

Build Status Latest Stable Version License

Overview

This package provides a static constructor interface, and a trait that implements the interface.

Installation

Via Composer:

composer require aviator/makeable

Testing

Via Composer:

composer test

Usage

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();

Other

License

This package is licensed with the MIT License (MIT).