diff --git a/composer.json b/composer.json index a3b0eafe..bb9f963e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^8.1", - "glhd/bits": "^0.2", + "glhd/bits": "^0.3.0", "illuminate/contracts": "^10.0", "internachi/modular": "^2.0", "spatie/laravel-package-tools": "^1.14.0", diff --git a/docs/verbs-opinions.md b/docs/verbs-opinions.md index cae46aff..2ce7a72c 100644 --- a/docs/verbs-opinions.md +++ b/docs/verbs-opinions.md @@ -81,7 +81,7 @@ class JobApplicationController { public function store(JobApplicationRequest $request) { ApplicationSubmitted::fire( - applicant_id: Snowflake::make()->id(), + applicant_id: snowflake_id(), // ... ); } diff --git a/examples/Monopoly/src/Http/Controllers/PlayerController.php b/examples/Monopoly/src/Http/Controllers/PlayerController.php index 2e0f313e..cb2667ab 100644 --- a/examples/Monopoly/src/Http/Controllers/PlayerController.php +++ b/examples/Monopoly/src/Http/Controllers/PlayerController.php @@ -2,7 +2,6 @@ namespace Thunk\Verbs\Examples\Monopoly\Http\Controllers; -use Glhd\Bits\Snowflake; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Session; @@ -13,7 +12,7 @@ class PlayerController extends Controller { public function store(Request $request, int $game_id) { - $player_id = Snowflake::make()->id(); + $player_id = snowflake_id(); Session::put('user.current_player_id', $player_id); diff --git a/examples/Monopoly/tests/MonopolyTest.php b/examples/Monopoly/tests/MonopolyTest.php index 30817e7f..45a3b3e6 100644 --- a/examples/Monopoly/tests/MonopolyTest.php +++ b/examples/Monopoly/tests/MonopolyTest.php @@ -1,6 +1,5 @@ id(); - $player2_id = Snowflake::make()->id(); + $player1_id = snowflake_id(); + $player2_id = snowflake_id(); $game_state = verb(new GameStarted())->state(GameState::class); diff --git a/examples/Subscriptions/src/Events/SubscriptionStarted.php b/examples/Subscriptions/src/Events/SubscriptionStarted.php index 4cf8f7d2..0cb5a913 100644 --- a/examples/Subscriptions/src/Events/SubscriptionStarted.php +++ b/examples/Subscriptions/src/Events/SubscriptionStarted.php @@ -2,7 +2,6 @@ namespace Thunk\Verbs\Examples\Subscriptions\Events; -use Glhd\Bits\Snowflake; use Thunk\Verbs\Event; use Thunk\Verbs\Examples\Subscriptions\Models\Subscription; use Thunk\Verbs\Examples\Subscriptions\States\GlobalReportState; @@ -20,7 +19,7 @@ class SubscriptionStarted extends Event public function states(): StateCollection { - $this->subscription_id ??= Snowflake::make()->id(); + $this->subscription_id ??= snowflake_id(); return new StateCollection([ SubscriptionState::load($this->subscription_id), diff --git a/src/Attributes/Autodiscovery/AppliesToState.php b/src/Attributes/Autodiscovery/AppliesToState.php index 82cc6b64..e0675a39 100644 --- a/src/Attributes/Autodiscovery/AppliesToState.php +++ b/src/Attributes/Autodiscovery/AppliesToState.php @@ -3,7 +3,6 @@ namespace Thunk\Verbs\Attributes\Autodiscovery; use Attribute; -use Glhd\Bits\Snowflake; use Illuminate\Support\Arr; use Illuminate\Support\Str; use InvalidArgumentException; @@ -32,7 +31,7 @@ public function discoverState(Event $event, StateManager $manager): array // If the ID hasn't been set yet, we'll automatically set one if ($id === null && $this->autofill) { - $id = Snowflake::make()->id(); + $id = snowflake_id(); $event->{$property} = $id; } diff --git a/src/Attributes/Autodiscovery/StateId.php b/src/Attributes/Autodiscovery/StateId.php index 9c2b717a..d6ae7634 100644 --- a/src/Attributes/Autodiscovery/StateId.php +++ b/src/Attributes/Autodiscovery/StateId.php @@ -3,7 +3,6 @@ namespace Thunk\Verbs\Attributes\Autodiscovery; use Attribute; -use Glhd\Bits\Snowflake; use Illuminate\Support\Arr; use InvalidArgumentException; use Thunk\Verbs\Event; @@ -29,7 +28,7 @@ public function discoverState(Event $event, StateManager $manager): array // If the ID hasn't been set yet, we'll automatically set one if ($id === null && $this->autofill) { - $id = Snowflake::make()->id(); + $id = snowflake_id(); $this->property->setValue($event, $id); } diff --git a/src/Lifecycle/EventStore.php b/src/Lifecycle/EventStore.php index a47c6fa4..8c432293 100644 --- a/src/Lifecycle/EventStore.php +++ b/src/Lifecycle/EventStore.php @@ -3,7 +3,6 @@ namespace Thunk\Verbs\Lifecycle; use Glhd\Bits\Bits; -use Glhd\Bits\Snowflake; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Builder as BaseBuilder; use Illuminate\Support\Collection; @@ -143,7 +142,7 @@ protected function formatRelationshipsForWrite(array $event_objects): array { return collect($event_objects) ->flatMap(fn (Event $event) => $event->states()->map(fn ($state) => [ - 'id' => Snowflake::make()->id(), + 'id' => snowflake_id(), 'event_id' => Verbs::toId($event->id), 'state_id' => Verbs::toId($state->id), 'state_type' => $state::class, diff --git a/src/Lifecycle/StateManager.php b/src/Lifecycle/StateManager.php index b8de93f4..542caeb1 100644 --- a/src/Lifecycle/StateManager.php +++ b/src/Lifecycle/StateManager.php @@ -3,7 +3,6 @@ namespace Thunk\Verbs\Lifecycle; use Glhd\Bits\Bits; -use Glhd\Bits\Snowflake; use Illuminate\Database\Eloquent\Collection; use Ramsey\Uuid\UuidInterface; use Symfony\Component\Uid\AbstractUid; @@ -30,7 +29,7 @@ public function __construct( public function register(State $state): State { - $state->id ??= Snowflake::make()->id(); + $state->id ??= snowflake_id(); return $this->remember($state); } @@ -73,7 +72,7 @@ public function singleton(string $type): State } $state = $this->snapshots->loadSingleton($type) ?? $type::make(); - $state->id ??= Snowflake::make()->id(); + $state->id ??= snowflake_id(); $this->events ->read(state: $state, after_id: $state->last_event_id, up_to_id: $this->max_event_id, singleton: true) diff --git a/src/Support/PendingEvent.php b/src/Support/PendingEvent.php index 1c69abb2..b362dab3 100644 --- a/src/Support/PendingEvent.php +++ b/src/Support/PendingEvent.php @@ -3,7 +3,6 @@ namespace Thunk\Verbs\Support; use Closure; -use Glhd\Bits\Snowflake; use Illuminate\Support\Arr; use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Macroable; @@ -159,7 +158,7 @@ protected function setDefaultExceptionMapper(): void protected function conditionallySetId(): void { if ($this->event instanceof Event) { - $this->event->id ??= Snowflake::make()->id(); + $this->event->id ??= snowflake_id(); } } } diff --git a/src/VerbsServiceProvider.php b/src/VerbsServiceProvider.php index bf4349ec..a3deda25 100644 --- a/src/VerbsServiceProvider.php +++ b/src/VerbsServiceProvider.php @@ -2,7 +2,6 @@ namespace Thunk\Verbs; -use Glhd\Bits\Snowflake; use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Container\Container; use Illuminate\Events\Dispatcher as LaravelDispatcher; @@ -126,7 +125,7 @@ public function boot() $this->app->make(LaravelDispatcher::class)->listen('*', function (string $name, array $data) { [$event] = $data; if (isset($event) && $event instanceof Event) { - $event->id ??= Snowflake::make()->id(); + $event->id ??= snowflake_id(); $this->app->make(BrokersEvents::class)->fire($event); } }); diff --git a/tests/Feature/VerbFakesTest.php b/tests/Feature/VerbFakesTest.php index 6b319e36..0b8e4424 100644 --- a/tests/Feature/VerbFakesTest.php +++ b/tests/Feature/VerbFakesTest.php @@ -1,6 +1,5 @@ id = $id ?? Snowflake::make()->id(); + $this->id = $id ?? snowflake_id(); } } @@ -58,6 +57,6 @@ class UncommittedVerbFakesTestEvent extends Event { public function __construct(?int $id = null) { - $this->id = $id ?? Snowflake::make()->id(); + $this->id = $id ?? snowflake_id(); } } diff --git a/tests/Unit/EventStoreFakeTest.php b/tests/Unit/EventStoreFakeTest.php index 5ee4a4f5..bd56c38e 100644 --- a/tests/Unit/EventStoreFakeTest.php +++ b/tests/Unit/EventStoreFakeTest.php @@ -1,6 +1,5 @@ id = $id ?? Snowflake::make()->id(); + $this->id = $id ?? snowflake_id(); } } @@ -125,7 +124,7 @@ class UncommittedEventStoreFakeTestEvent extends Event { public function __construct(?int $id = null) { - $this->id = $id ?? Snowflake::make()->id(); + $this->id = $id ?? snowflake_id(); } } @@ -140,6 +139,6 @@ public function __construct( public ?int $state_id = null, ?int $id = null ) { - $this->id = $id ?? Snowflake::make()->id(); + $this->id = $id ?? snowflake_id(); } }