1 | <?php |
||
21 | class VersionManager |
||
22 | { |
||
23 | /** |
||
24 | * @var VersionManager |
||
25 | */ |
||
26 | private static $instance = null; |
||
27 | |||
28 | /** |
||
29 | * @var VersionStoreInterface |
||
30 | */ |
||
31 | protected $versionStore; |
||
32 | |||
33 | /** |
||
34 | * VersionManager constructor. |
||
35 | * |
||
36 | * @param VersionStoreInterface $versionStore |
||
37 | */ |
||
38 | private function __construct(VersionStoreInterface $versionStore) |
||
42 | |||
43 | /** |
||
44 | * @return VersionManager |
||
45 | */ |
||
46 | public static function create() |
||
54 | |||
55 | /** |
||
56 | * @param VersionStoreInterface $versionStore |
||
57 | */ |
||
58 | public static function setVersionStore(VersionStoreInterface $versionStore) |
||
62 | |||
63 | /** |
||
64 | * @param EventSourcedAggregateRootInterface $aggregate |
||
65 | * |
||
66 | * @return int |
||
67 | */ |
||
68 | public static function versionOf(EventSourcedAggregateRootInterface $aggregate) |
||
72 | |||
73 | /** |
||
74 | * @param EventSourcedAggregateRootInterface $aggregate |
||
75 | */ |
||
76 | public static function persistVersionOf(EventSourcedAggregateRootInterface $aggregate) |
||
80 | |||
81 | /** |
||
82 | * @param string $className |
||
83 | * |
||
84 | * @return int |
||
85 | */ |
||
86 | public static function versionOfClass($className) |
||
90 | |||
91 | /** |
||
92 | * @param string $className |
||
93 | * @param int $version |
||
94 | */ |
||
95 | public static function persistVersionOfClass($className, $version) |
||
99 | |||
100 | /** |
||
101 | * @param string $aggregateClassName |
||
102 | * |
||
103 | * @return int |
||
104 | */ |
||
105 | protected function getAggregateRootVersion($aggregateClassName) |
||
109 | |||
110 | /** |
||
111 | * @param string $aggregateClassName |
||
112 | * @param int $version |
||
113 | */ |
||
114 | protected function setAggregateRootVersion($aggregateClassName, $version) |
||
118 | } |
||
119 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: