-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mount Hook and allow classnames in registration
- Loading branch information
1 parent
7ec1450
commit dc6b725
Showing
10 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,14 @@ | |
|
||
namespace Thunk\Verbs\Examples\Bank\Events; | ||
|
||
use Illuminate\Support\Facades\Mail; | ||
use Thunk\Verbs\Attributes\Autodiscovery\StateId; | ||
use Thunk\Verbs\Event; | ||
use Thunk\Verbs\Examples\Bank\Mail\WelcomeEmail; | ||
use Thunk\Verbs\Facades\Verbs; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Mail; | ||
use Thunk\Verbs\Examples\Bank\Models\Account; | ||
use Thunk\Verbs\Examples\Bank\Mail\WelcomeEmail; | ||
use Thunk\Verbs\Attributes\Autodiscovery\StateId; | ||
use Thunk\Verbs\Examples\Bank\States\AccountState; | ||
use Thunk\Verbs\Facades\Verbs; | ||
|
||
class AccountOpened extends Event | ||
{ | ||
|
@@ -39,4 +40,12 @@ public function handle() | |
|
||
Verbs::unlessReplaying(fn () => Mail::send(new WelcomeEmail($this->user_id))); | ||
} | ||
|
||
public static function migrate() | ||
{ | ||
return [ | ||
1 => fn(Collection $v0) => $v0->except('user_id'), | ||
2 => fn(Collection $v1) => $v1->merge(['email' => '[email protected]']), | ||
]; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Thunk\Verbs\Attributes\Hooks\On; | ||
use Thunk\Verbs\Event; | ||
use Thunk\Verbs\Facades\Verbs; | ||
use Thunk\Verbs\Lifecycle\Phase; | ||
|
||
|
||
it('can modify props on events in the mount phase', function () { | ||
Verbs::registerListener(Listener::class); | ||
|
||
$e = EventWithNullProp::fire( | ||
album: 'Tha Carter 2' | ||
); | ||
|
||
expect($e) | ||
->name | ||
->toBe('Lil Wayne'); | ||
}); | ||
|
||
class EventWithNullProp extends Event | ||
{ | ||
public ?string $name = null; | ||
public string $album; | ||
} | ||
|
||
class Listener | ||
{ | ||
#[On(Phase::Mount)] | ||
public static function setNameToLilWayne(EventWithNullProp $event) | ||
{ | ||
$event->name = 'Lil Wayne'; | ||
} | ||
} |