A simple package for enabling the booting of traits.
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();
}
}