Created
March 21, 2018 08:24
-
-
Save finagin/c1d388b6380551deaf31024e5a53febd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Finagin; | |
| use Finagin\Traits\Readable; | |
| use Finagin\Traits\TraitBootstrapper; | |
| class Example | |
| { | |
| use Readable, TraitBootstrapper; | |
| function __construct() | |
| { | |
| static::boot(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Finagin\Traits; | |
| trait Readable | |
| { | |
| protected function bootReadable() | |
| { | |
| var_dump('Readable booted'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Finagin\Traits; | |
| /** | |
| * Trait TraitBootstrapper | |
| * | |
| * @package Finagin\Traits | |
| */ | |
| trait TraitBootstrapper | |
| { | |
| protected function boot() | |
| { | |
| foreach (class_uses(static::class) as $trait) { | |
| $boot = 'boot'.substr(strrchr($trait, "\\"), 1); | |
| if (method_exists($this, $boot)) { | |
| call_user_func([$this, $boot]); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment