streak icon indicating copy to clipboard operation
streak copied to clipboard

make snapshotter generic and add adapter for aggregate root

Open alanbem opened this issue 5 years ago • 0 comments

e.g.

namespace Entity;

interface Snapshotter
{
    public function restoreToSnapshot(Entity $entity) : ?Entity;

    public function takeSnapshot(Entity $entity) : void;
}

and

namespace Entity\AggregateRoot;

interface Snapshotter
{
    public function restoreToSnapshot(AggregateRoot $aggregate) : ?AggregateRoot;

    public function takeSnapshot(AggregateRoot $aggregate) : void;
}

class EntitySnapshotterAdapter implements AggregateRoot\Snapshotter
{
    private $snapshotter;
   
    public function __construct(Entity\Snapshotter $snasphotter)
    {
        $this->snapshotter = $snapshotter;
    }
   
    public function restoreToSnapshot(AggregateRoot $aggregate) : ?AggregateRoot
    { 
        return $this->snapshotter->restoreToSnapshot($aggregate);
    }

    public function takeSnapshot(AggregateRoot $aggregate) : void
    {
        $this->snapshotter->takeSnapshot($aggregate);
    }
}

Just an idea - needs some refinement.

alanbem avatar Jul 20 '19 19:07 alanbem