jasonej/bootable-traits

Quickly and easily enable booting of traits in any class.

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

This package is auto-updated.

Last update: 2024-04-14 12:01:55 UTC


README

A simple package for enabling the booting of traits.

Installation

composer require jasonej/bootable-traits

Usage

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