Skip to content

Commit b06d179

Browse files
authored
Switch to bits 0.3.0 and snowflake_id() (#63)
Switch to bits 0.3.0
1 parent c4aabc1 commit b06d179

File tree

13 files changed

+18
-29
lines changed

13 files changed

+18
-29
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"require": {
2020
"php": "^8.1",
21-
"glhd/bits": "^0.2",
21+
"glhd/bits": "^0.3.0",
2222
"illuminate/contracts": "^10.0",
2323
"internachi/modular": "^2.0",
2424
"spatie/laravel-package-tools": "^1.14.0",

docs/verbs-opinions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class JobApplicationController
8181
{
8282
public function store(JobApplicationRequest $request) {
8383
ApplicationSubmitted::fire(
84-
applicant_id: Snowflake::make()->id(),
84+
applicant_id: snowflake_id(),
8585
// ...
8686
);
8787
}

examples/Monopoly/src/Http/Controllers/PlayerController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Thunk\Verbs\Examples\Monopoly\Http\Controllers;
44

5-
use Glhd\Bits\Snowflake;
65
use Illuminate\Http\Request;
76
use Illuminate\Routing\Controller;
87
use Illuminate\Support\Facades\Session;
@@ -13,7 +12,7 @@ class PlayerController extends Controller
1312
{
1413
public function store(Request $request, int $game_id)
1514
{
16-
$player_id = Snowflake::make()->id();
15+
$player_id = snowflake_id();
1716

1817
Session::put('user.current_player_id', $player_id);
1918

examples/Monopoly/tests/MonopolyTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use Glhd\Bits\Snowflake;
43
use Thunk\Verbs\Examples\Monopoly\Events\Gameplay\EndedTurn;
54
use Thunk\Verbs\Examples\Monopoly\Events\Gameplay\PaidRent;
65
use Thunk\Verbs\Examples\Monopoly\Events\Gameplay\PlayerMoved;
@@ -30,8 +29,8 @@
3029
// Game setup
3130
// ---------------------------------------------------------------------------------------------------------------------------
3231

33-
$player1_id = Snowflake::make()->id();
34-
$player2_id = Snowflake::make()->id();
32+
$player1_id = snowflake_id();
33+
$player2_id = snowflake_id();
3534

3635
$game_state = verb(new GameStarted())->state(GameState::class);
3736

examples/Subscriptions/src/Events/SubscriptionStarted.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Thunk\Verbs\Examples\Subscriptions\Events;
44

5-
use Glhd\Bits\Snowflake;
65
use Thunk\Verbs\Event;
76
use Thunk\Verbs\Examples\Subscriptions\Models\Subscription;
87
use Thunk\Verbs\Examples\Subscriptions\States\GlobalReportState;
@@ -20,7 +19,7 @@ class SubscriptionStarted extends Event
2019

2120
public function states(): StateCollection
2221
{
23-
$this->subscription_id ??= Snowflake::make()->id();
22+
$this->subscription_id ??= snowflake_id();
2423

2524
return new StateCollection([
2625
SubscriptionState::load($this->subscription_id),

src/Attributes/Autodiscovery/AppliesToState.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Thunk\Verbs\Attributes\Autodiscovery;
44

55
use Attribute;
6-
use Glhd\Bits\Snowflake;
76
use Illuminate\Support\Arr;
87
use Illuminate\Support\Str;
98
use InvalidArgumentException;
@@ -32,7 +31,7 @@ public function discoverState(Event $event, StateManager $manager): array
3231

3332
// If the ID hasn't been set yet, we'll automatically set one
3433
if ($id === null && $this->autofill) {
35-
$id = Snowflake::make()->id();
34+
$id = snowflake_id();
3635
$event->{$property} = $id;
3736
}
3837

src/Attributes/Autodiscovery/StateId.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Thunk\Verbs\Attributes\Autodiscovery;
44

55
use Attribute;
6-
use Glhd\Bits\Snowflake;
76
use Illuminate\Support\Arr;
87
use InvalidArgumentException;
98
use Thunk\Verbs\Event;
@@ -29,7 +28,7 @@ public function discoverState(Event $event, StateManager $manager): array
2928

3029
// If the ID hasn't been set yet, we'll automatically set one
3130
if ($id === null && $this->autofill) {
32-
$id = Snowflake::make()->id();
31+
$id = snowflake_id();
3332
$this->property->setValue($event, $id);
3433
}
3534

src/Lifecycle/EventStore.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Thunk\Verbs\Lifecycle;
44

55
use Glhd\Bits\Bits;
6-
use Glhd\Bits\Snowflake;
76
use Illuminate\Database\Eloquent\Builder;
87
use Illuminate\Database\Query\Builder as BaseBuilder;
98
use Illuminate\Support\Collection;
@@ -143,7 +142,7 @@ protected function formatRelationshipsForWrite(array $event_objects): array
143142
{
144143
return collect($event_objects)
145144
->flatMap(fn (Event $event) => $event->states()->map(fn ($state) => [
146-
'id' => Snowflake::make()->id(),
145+
'id' => snowflake_id(),
147146
'event_id' => Verbs::toId($event->id),
148147
'state_id' => Verbs::toId($state->id),
149148
'state_type' => $state::class,

src/Lifecycle/StateManager.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Thunk\Verbs\Lifecycle;
44

55
use Glhd\Bits\Bits;
6-
use Glhd\Bits\Snowflake;
76
use Illuminate\Database\Eloquent\Collection;
87
use Ramsey\Uuid\UuidInterface;
98
use Symfony\Component\Uid\AbstractUid;
@@ -30,7 +29,7 @@ public function __construct(
3029

3130
public function register(State $state): State
3231
{
33-
$state->id ??= Snowflake::make()->id();
32+
$state->id ??= snowflake_id();
3433

3534
return $this->remember($state);
3635
}
@@ -73,7 +72,7 @@ public function singleton(string $type): State
7372
}
7473

7574
$state = $this->snapshots->loadSingleton($type) ?? $type::make();
76-
$state->id ??= Snowflake::make()->id();
75+
$state->id ??= snowflake_id();
7776

7877
$this->events
7978
->read(state: $state, after_id: $state->last_event_id, up_to_id: $this->max_event_id, singleton: true)

src/Support/PendingEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Thunk\Verbs\Support;
44

55
use Closure;
6-
use Glhd\Bits\Snowflake;
76
use Illuminate\Support\Arr;
87
use Illuminate\Support\Traits\Conditionable;
98
use Illuminate\Support\Traits\Macroable;
@@ -159,7 +158,7 @@ protected function setDefaultExceptionMapper(): void
159158
protected function conditionallySetId(): void
160159
{
161160
if ($this->event instanceof Event) {
162-
$this->event->id ??= Snowflake::make()->id();
161+
$this->event->id ??= snowflake_id();
163162
}
164163
}
165164
}

0 commit comments

Comments
 (0)