aviator/makeable

此包已被废弃,不再维护。未建议替代包。

静态构造器特质和接口。

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

概述

此包提供了一个静态构造器接口和一个实现该接口的特质。

安装

通过Composer

composer require aviator/makeable

测试

通过Composer

composer test

用法

使用特质

class Something
{
    use MakeableTrait;
}

然后可以使用 Class::make(...$args) 来实例化类

$instance = Something::make($arg1, $arg2);

接口是可选的,尽管在复合接口中指定静态构造器应该存在可能很有用

interface SomeInterface extends Makeable, SomeOtherInterface
{
    /* ... etc */
}

由于静态构造器只是简单地返回 new static(...$args),因此可以在抽象类和父类中使用,而无需在子类中重复使用

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

其他

许可证

此包使用MIT许可证 (MIT)进行许可。