jasonej/bootable-traits

快速轻松地在任何类中启用特质的启动。

v1.0.0 2020-02-14 02:35 UTC

This package is auto-updated.

Last update: 2024-09-14 12:46:48 UTC


README

一个用于启用特质启动的简单包。

安装

composer require jasonej/bootable-traits

使用

<?php

use Jasonej\BootableTraits\BootsTraits;

trait ExampleTrait
{
    public $booted = false;

    public function bootExampleTrait(): void
    {
        $this->booted = true;
    }
}

class ExampleClass
{
    use BootsTraits;
    use ExampleTrait;

    public function __construct()
    {
        static::bootTraits($this);
    }
}
<?php

use Jasonej\BootableTraits\BootsTraits;

trait ExampleTrait
{
    public static $booted = false;

    public static function bootExampleTrait(): void
    {
        static::$booted = true;
    }
}

class ExampleClass
{
    use BootsTraits;
    use ExampleTrait;

    public static function init()
    {
        static::bootTraits();
    }
}