AbstractSnapshotStore::serializeAggregateRoot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * event-sourcing (https://github.com/phpgears/event-sourcing).
5
 * Event Sourcing base.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/event-sourcing
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\EventSourcing\Store\Snapshot;
15
16
use Gears\EventSourcing\Aggregate\AggregateRoot;
17
use Gears\EventSourcing\Aggregate\Serializer\AggregateSerializer;
18
19
/**
20
 * Abstract snapshot implementation.
21
 */
22
abstract class AbstractSnapshotStore implements SnapshotStore
23
{
24
    /**
25
     * @var AggregateSerializer
26
     */
27
    private $serializer;
28
29
    /**
30
     * AbstractSnapshotStore constructor.
31
     *
32
     * @param AggregateSerializer $serializer
33
     */
34
    public function __construct(AggregateSerializer $serializer)
35
    {
36
        $this->serializer = $serializer;
37
    }
38
39
    /**
40
     * Serialize aggregate root.
41
     *
42
     * @param AggregateRoot $aggregateRoot
43
     *
44
     * @return string
45
     */
46
    final protected function serializeAggregateRoot(AggregateRoot $aggregateRoot): string
47
    {
48
        return $this->serializer->serialize($aggregateRoot);
49
    }
50
51
    /**
52
     * Deserialize aggregate root.
53
     *
54
     * @param string $serialized
55
     *
56
     * @return AggregateRoot
57
     */
58
    final protected function deserializeAggregateRoot(string $serialized): AggregateRoot
59
    {
60
        return $this->serializer->fromSerialized($serialized);
61
    }
62
}
63