Download the PHP package mad654/php-event-store without Composer
On this page you can find all versions of the php package mad654/php-event-store. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mad654/php-event-store
More information about mad654/php-event-store
Files in mad654/php-event-store
Package php-event-store
Short Description Provides classes to express object state changes as events and store them in file based eventstreams
License MIT
Informations about the package php-event-store
PHP Event Store
Plain php event store implementation for easy persistence by utilizing event sourcing.
It provides classes to express object state changes as events and store them in file based eventstreams.
Installation
You can install mad654/php-event-store via composer by adding "mad654/php-event-store": "dev-master"
as requirement to your composer.json.
By Example
For a full working example take a look at src/example
. In your vagrant box you can use it like this:
Step by step
Let's take this little example to get in touch with all the new stuff. Lets asume you want to control the light in your Kittchen and for this you have build some switch. All you need is an object which can control the state and keeps its current state over mutlitple requests:
This is a good beginning, but now you need a way to persist the state.
EventSourcedObject
Instead of creating a database you can extend your class to implement the EventSourcedObject interface. An EventSourcedObject is simply an object which should be available in his current state in the next request and for this it can publish its events as a stream and can be build from scratch based on the events:
So instead of changing your member variables directly, you will use events for this, like shown in switchOn
. So you will record
an event and you will update your state in the on
function, which is automatically be called by record
function.
If you want to see more details, take a look at the AutoTrackingEventSourcedObjectTrait
which should be a good starting point for all your event sourced objects and reduce boilerplate code.
EventSourcedObjectStore
The EventSourcedObjectStore provides a simple API which allows you to save and load objects which implements the EventEmitter interface:
If '$someEventSourcedObject' was implemented correctly, it should have the equal state - before and after the unset()
call.
By definition an EventSourcedObjectStore can only store and retrieve objects by id. Here you can find solutions for searching ...
Event
In this example we use the StateChanged event, in production you should create subclasses of this to express more precisely what happened.
In general events are immutable.
Putting all together
Some times later in an other request you want to switch on the light in the kitchen:
And again later you will switch it off again:
And again ...
And again ...
And now you are wondering why your power bill is so expensive - let's take a look at the history:
Development
Inside of the vagrant box:
All versions of php-event-store with dependencies
psr/log Version ^1.1
consolidation/log Version ^1.1
ext-json Version *
dflydev/dot-access-data Version ^2.0