Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to bits 0.3.0 and snowflake_id() #63

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/verbs-opinions.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class JobApplicationController
{
public function store(JobApplicationRequest $request) {
ApplicationSubmitted::fire(
applicant_id: Snowflake::make()->id(),
applicant_id: snowflake_id(),
// ...
);
}
Expand Down
3 changes: 1 addition & 2 deletions examples/Monopoly/src/Http/Controllers/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions examples/Monopoly/tests/MonopolyTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Glhd\Bits\Snowflake;
use Thunk\Verbs\Examples\Monopoly\Events\Gameplay\EndedTurn;
use Thunk\Verbs\Examples\Monopoly\Events\Gameplay\PaidRent;
use Thunk\Verbs\Examples\Monopoly\Events\Gameplay\PlayerMoved;
Expand Down Expand Up @@ -30,8 +29,8 @@
// Game setup
// ---------------------------------------------------------------------------------------------------------------------------

$player1_id = Snowflake::make()->id();
$player2_id = Snowflake::make()->id();
$player1_id = snowflake_id();
$player2_id = snowflake_id();

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

Expand Down
3 changes: 1 addition & 2 deletions examples/Subscriptions/src/Events/SubscriptionStarted.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions src/Attributes/Autodiscovery/AppliesToState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Attributes/Autodiscovery/StateId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Lifecycle/EventStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/Lifecycle/StateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/Support/PendingEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
3 changes: 1 addition & 2 deletions src/VerbsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
});
Expand Down
5 changes: 2 additions & 3 deletions tests/Feature/VerbFakesTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Glhd\Bits\Snowflake;
use Thunk\Verbs\Contracts\StoresEvents;
use Thunk\Verbs\Event;
use Thunk\Verbs\Facades\Verbs;
Expand Down Expand Up @@ -50,14 +49,14 @@ class VerbFakesTestEvent extends Event
{
public function __construct(?int $id = null)
{
$this->id = $id ?? Snowflake::make()->id();
$this->id = $id ?? snowflake_id();
}
}

class UncommittedVerbFakesTestEvent extends Event
{
public function __construct(?int $id = null)
{
$this->id = $id ?? Snowflake::make()->id();
$this->id = $id ?? snowflake_id();
}
}
7 changes: 3 additions & 4 deletions tests/Unit/EventStoreFakeTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Glhd\Bits\Snowflake;
use Thunk\Verbs\Attributes\Autodiscovery\AppliesToState;
use Thunk\Verbs\Contracts\StoresEvents;
use Thunk\Verbs\Event;
Expand Down Expand Up @@ -117,15 +116,15 @@ class EventStoreFakeTestEvent extends Event
{
public function __construct(?int $id = null)
{
$this->id = $id ?? Snowflake::make()->id();
$this->id = $id ?? snowflake_id();
}
}

class UncommittedEventStoreFakeTestEvent extends Event
{
public function __construct(?int $id = null)
{
$this->id = $id ?? Snowflake::make()->id();
$this->id = $id ?? snowflake_id();
}
}

Expand All @@ -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();
}
}
Loading