Skip to content

Commit

Permalink
Rename mount to boot
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCoulbourne committed Nov 7, 2024
1 parent a51cff5 commit 353f61e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Lifecycle/Broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/Lifecycle/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -97,12 +97,12 @@ public function replay(Event $event): void
}

/** @return Collection<int, Hook> */
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;
Expand Down
6 changes: 3 additions & 3 deletions src/Lifecycle/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Lifecycle/Phase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

enum Phase: string
{
case Mount = 'mount';
case Boot = 'boot';
case Authorize = 'authorize';
case Validate = 'validate';
case Apply = 'apply';
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/MountHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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';
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/RegisteredListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 353f61e

Please sign in to comment.