PHP code example of robin-malfait / event-sourcing

1. Go to this page and download the library: Download robin-malfait/event-sourcing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

robin-malfait / event-sourcing example snippets

 
 namespace App\Users\Events;

use EventSourcing\Domain\DomainEvent;

class UserWasRegistered implements DomainEvent
{
    private $user_id;

    private $email;

    private $password; // Yes, this is encrypted

    public function __construct($user_id, $email, $password)
    {
        $this->user_id = $user_id;
        $this->email = $email;
        $this->password = $password;
    }

    /**
     * @return UserId
     */
    public function getAggregateId()
    {
        return $this->user_id;
    }

    public function getMetaData() 
    {
        return []; // Could be for example the logged in user, ...
    }

    /**
     * @return array
     */
    public function serialize()
    {
        return [
            'user_id' => $this->user_id,
            'email' => $this->email,
            'password' => $this->password
        ];
    }

    /**
     * @param array $data
     * @return mixed
     */
    public static function deserialize(array $data)
    {
        return new static(
            $data['user_id'],
            $data['email'],
            $data['password']
        );
    }
}

 php
'providers' => [
    ...
    \EventSourcing\Laravel\EventSourcingServiceProvider::class,
]
 php
php artisan vendor:publish --provider="EventSourcing\Laravel\EventSourcingServiceProvider"

php artisan event-sourcing:table

php artisan event-sourcing:table

php artisan event-sourcing:1to2 eventstore_backup eventstore
bash
php artisan event-sourcing:1to2