Skip to content
jrdn hannah edited this page Nov 18, 2015 · 2 revisions

Repositories

Repositories are used to communicate with the event store. They are simple interfaces

use FullRent\Core\Subscription\Subscription;
use FullRent\Core\Subscription\ValueObjects\SubscriptionId;
use SmoothPhp\Contracts\EventSourcing\AggregateRoot;
interface SubscriptionRepository
{
    /**
     * @param SubscriptionId $id
     * @return Subscription
     */
    public function load($id);

    /**
     * @param AggregateRoot $aggregateRoot
     * @return void
     */
    public function save(AggregateRoot $aggregateRoot);
}

Take the opportunity to help your self and get the type hints in the comments right. Load takes a ID VO and returns the aggregate. The Save function takes anything that interfaces the AggregateRoot

Concrete

You also need to build a concrete instance which implements your interface. To make life easier just extend the SmoothPhp\EventSourcing\EventSourcedRepository class. There are two abstract getter methods with need to be set correctly

 /**
     * @return string
     */
    protected function getPrefix()
    {
        return 'subscription-';
    }

    /**
     * @return string
     */
    protected function getAggregateType()
    {
        return Subscription::class;
    }

Get prefix helps the eventstore by prefixing what ever you said in the aggregate for example subscription-12312-123-12512

This helps debugging and filtering by aggregate type in the eventstore.

getAggregateType simply returns the string on the class the repository builds

Clone this wiki locally