hirethunk / verbs Goto Github PK
View Code? Open in Web Editor NEWVerbs is an event sourcing package for PHP artisans
Home Page: https://verbs.thunk.dev
License: MIT License
Verbs is an event sourcing package for PHP artisans
Home Page: https://verbs.thunk.dev
License: MIT License
Verbs stores the user's event data mingled with internal Verbs data. Thus:
phase
property. (Type of App\Events\BrokeVerbs::$phase must be Thunk\Verbs\Lifecycle\Phase (as in class Thunk\Verbs\Event)
)id
property (of type int
), no error will be thrown, but Verbs will nuke it and overwrite it with that row's id
snowflake.The phase
one isn't too bad. You get an error, and anyone encountering it will likely realize they need to rename their phase
in that event.
The id
one is kinda nasty. It's highly likely someone will try this, and it just silently overwrites their data.
Some questions:
id
in both the id
column of an event and also in the JSON data
column?phase
in the database at all?<?php
namespace App\Events;
use Thunk\Verbs\Event;
class BrokeVerbsPhase extends Event {
public function __construct(public string $phase) {
}
public function handle() {
}
}
<?php
namespace App\Events;
use Thunk\Verbs\Event;
class BrokeVerbsId extends Event {
public function __construct(public int $id) {
}
public function handle() {
}
}
Then just fire those events.
0.0.6
8.1.26
10.10
macOS
No response
Upon trying to install Verbs itself, to check out the tests and such, I get this:
Could not fetch https://api.github.com/repos/DanielCoulbourne/bugg, please review your configured GitHub OAuth token or enter a new one to access private repos
composer install
8.1.26
x.x.x
macOS, Windows, Linux
No response
I was following the Verbs quickstart tutorial and ran into a bug while creating a new event using artisan.
The problem appears to be on lines 75/76, basically when it checks if there is a path, it appends a '/', but for the first iteration, it is the full path to the app directory, in my case: "C:\laragon6\www\verbs\app\Events", so by adding a forward slash to the front it breaks.
I believe the intent was to use the for loop to create any needed subdirectories which makes sense. I changed the implementation slightly to use PHP constants for directory separators and to use the Illuminate Filesystem.
A related problem, while I was running the code below, I tested generating additional levels of directories, for example:
php artisan verbs:event Test\\Directory\\CustomerBeganTrial
The path is created correctly, but the class name and namespace are not correct, not a huge deal.
use Illuminate\Support\Facades\File;
protected function forceWrite($dir, $contents)
{
// break the path into parts
$parts = explode(DIRECTORY_SEPARATOR, $dir);
// pop the last part off to get the file name
$file = array_pop($parts);
// rejoin the parts to get the directory
$dir = implode(DIRECTORY_SEPARATOR, $parts);
// okay make sure the directory exists
File::ensureDirectoryExists($dir);
// now write the file
File::put($dir.DIRECTORY_SEPARATOR.$file, $contents);
}
I'd be happy to put together a PR with suggestions. Thanks! ๐
php artisan verbs:event CustomerBeganTrial
ErrorException
mkdir(): No such file or directory
at vendor\hirethunk\verbs\src\Helpers\Stub.php:76
72โ $file = array_pop($parts);
73โ $dir = '';
74โ foreach ($parts as $part) {
75โ if (! is_dir($dir .= "/$part")) {
โ 76โ mkdir($dir);
77โ }
78โ }
79โ file_put_contents("$dir/$file", $contents);
80โ }
1 vendor\hirethunk\verbs\src\Helpers\Stub.php:76
2 vendor\hirethunk\verbs\src\Helpers\Stub.php:48
Thunk\Verbs\Helpers\Stub::forceWrite("/C:\laragon6\www\verbs\app\Events", "<?php
namespace App\Events;
use Thunk\Verbs\Event;
class CustomerBeganTrial extends Event
{
public function handle()
{
// The best things in life are free, not cheap. - Lil Wayne
}
}
")
0.0.6
8.2.0
10.10.0
Windows
No response
On one of my events, I loaded a state, but ended up deleting its apply()
function. This led to me getting an error message like this:
I could make this error go away by simply removing #[StateId(PlayerState::class)]
from the $player_id
, or by adding a public function apply(PlayerState $state)
. But if I declare the StateId and then never apply it, I got the confusing error above.
apply()
for that state.0.0.7
8.1
10.10
macOS
My suggestion would be to either:
I get the following errors when trying to use Postgres. It seems to work in MySQL.
SQLSTATE[21000]: Cardinality violation: 7 ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time
HINT: Ensure that no rows proposed for insertion within the same command have duplicate constrained values. (Connection: pgsql, SQL: insert into "verb_snapshots" ("created_at", "data", "id", "last_event_id", "type", "updated_at") values (2023-11-21 04:57:14, {"balance_in_cents":100000,"id":117488472096960512,"last_event_id":117488472088571904}, 117488472096960512, 117488472088571904, App\States\AccountState, 2023-11-21 04:57:14), (2023-11-21 04:57:14, {"balance_in_cents":100000,"id":117488472096960512,"last_event_id":117488472088571904}, 117488472096960512, 117488472088571904, App\States\AccountState, 2023-11-21 04:57:14) on conflict ("id") do update set "data" = "excluded"."data", "last_event_id" = "excluded"."last_event_id", "updated_at" = "excluded"."updated_at")
Follow one of the examples and try to run the tests.
0.0.5
8.2.0
10.10
macOS
It doesn't seem to be calling upsert twice so I'm not sure why we're getting this error.
My question is: in the doc you are talking about replaying events.
How do we replay events using your packages ?
I don't see any console commands for that...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.