From 353f61ec99a9bac6d0874f92f101b7aac6a3159b Mon Sep 17 00:00:00 2001 From: Daniel Coulbourne Date: Thu, 7 Nov 2024 16:06:39 -0500 Subject: [PATCH] Rename mount to boot --- src/Lifecycle/Broker.php | 2 +- src/Lifecycle/Dispatcher.php | 14 +++++++------- src/Lifecycle/Hook.php | 6 +++--- src/Lifecycle/Phase.php | 2 +- tests/Feature/MountHookTest.php | 4 ++-- tests/Feature/RegisteredListenerTest.php | 5 +++-- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Lifecycle/Broker.php b/src/Lifecycle/Broker.php index 3d03c097..b4f2d376 100644 --- a/src/Lifecycle/Broker.php +++ b/src/Lifecycle/Broker.php @@ -37,7 +37,7 @@ public function fire(Event $event): ?Event return null; } - $this->dispatcher->mount($event); + $this->dispatcher->boot($event); // NOTE: Any changes to how the dispatcher is called here // should also be applied to the `replay` method diff --git a/src/Lifecycle/Dispatcher.php b/src/Lifecycle/Dispatcher.php index 8849b902..d34edf78 100644 --- a/src/Lifecycle/Dispatcher.php +++ b/src/Lifecycle/Dispatcher.php @@ -38,13 +38,13 @@ public function skipPhases(Phase ...$phases): void $this->skipped_phases = $phases; } - public function mount(Event $event): bool + public function boot(Event $event): bool { - if (! $this->shouldDispatchPhase(Phase::Mount)) { + if (! $this->shouldDispatchPhase(Phase::Boot)) { return true; } - $this->getMountHooks($event)->each(fn (Hook $hook) => $hook->mount($this->container, $event)); + $this->getBootHooks($event)->each(fn (Hook $hook) => $hook->boot($this->container, $event)); return true; } @@ -97,12 +97,12 @@ public function replay(Event $event): void } /** @return Collection */ - protected function getMountHooks(Event $event): Collection + protected function getBootHooks(Event $event): Collection { - $hooks = $this->hooksFor($event, Phase::Mount); + $hooks = $this->hooksFor($event, Phase::Boot); - if (method_exists($event, 'mount')) { - $hooks->prepend(Hook::fromClassMethod($event, 'mount')->forcePhases(Phase::Mount)); + if (method_exists($event, 'boot')) { + $hooks->prepend(Hook::fromClassMethod($event, 'boot')->forcePhases(Phase::Boot)); } return $hooks; diff --git a/src/Lifecycle/Hook.php b/src/Lifecycle/Hook.php index 7a142419..76113516 100644 --- a/src/Lifecycle/Hook.php +++ b/src/Lifecycle/Hook.php @@ -72,13 +72,13 @@ public function runsInPhase(Phase $phase): bool return isset($this->phases[$phase]) && $this->phases[$phase] === true; } - public function mount(Container $container, Event $event): bool + public function boot(Container $container, Event $event): bool { - if ($this->runsInPhase(Phase::Mount)) { + if ($this->runsInPhase(Phase::Boot)) { return $this->execute($container, $event) ?? true; } - throw new RuntimeException('Hook::mount called on a non-mount hook.'); + throw new RuntimeException('Hook::boot called on a non-boot hook.'); } public function validate(Container $container, Event $event): bool diff --git a/src/Lifecycle/Phase.php b/src/Lifecycle/Phase.php index 4c10fb34..1be5cb33 100644 --- a/src/Lifecycle/Phase.php +++ b/src/Lifecycle/Phase.php @@ -4,7 +4,7 @@ enum Phase: string { - case Mount = 'mount'; + case Boot = 'boot'; case Authorize = 'authorize'; case Validate = 'validate'; case Apply = 'apply'; diff --git a/tests/Feature/MountHookTest.php b/tests/Feature/MountHookTest.php index 9c59209f..795b90b0 100644 --- a/tests/Feature/MountHookTest.php +++ b/tests/Feature/MountHookTest.php @@ -5,7 +5,7 @@ use Thunk\Verbs\Facades\Verbs; use Thunk\Verbs\Lifecycle\Phase; -it('can modify props on events in the mount phase', function () { +it('can modify props on events in the Boot phase', function () { Verbs::registerListener(Listener::class); $e = EventWithNullProp::fire( @@ -26,7 +26,7 @@ class EventWithNullProp extends Event class Listener { - #[On(Phase::Mount)] + #[On(Phase::Boot)] public static function setNameToLilWayne(EventWithNullProp $event) { $event->name = 'Lil Wayne'; diff --git a/tests/Feature/RegisteredListenerTest.php b/tests/Feature/RegisteredListenerTest.php index 9d6b8b7d..7ae3da56 100644 --- a/tests/Feature/RegisteredListenerTest.php +++ b/tests/Feature/RegisteredListenerTest.php @@ -27,7 +27,8 @@ class EveryoneException extends Exception {} class EveryListener { - #[On(Phase::Mount)] + + #[On(Phase::Boot)] public static function every(Event $event) { throw new EveryoneException; @@ -36,7 +37,7 @@ public static function every(Event $event) class OneListener { - #[On(Phase::Mount)] + #[On(Phase::Boot)] public static function one(EventOne $event) { throw new JustOneException();