1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Linna Framework. |
5
|
|
|
* |
6
|
|
|
* @author Sebastian Rapetti <[email protected]> |
7
|
|
|
* @copyright (c) 2018, Sebastian Rapetti |
8
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
9
|
|
|
*/ |
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Linna\DataMapper; |
13
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract Class for ObjectMapper, uuid version. |
18
|
|
|
*/ |
19
|
|
|
abstract class UuidMapperAbstract |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Create a new instance of the DomainObject that this |
23
|
|
|
* mapper is responsible for. |
24
|
|
|
* |
25
|
|
|
* @return UuidDomainObjectInterface |
26
|
|
|
*/ |
27
|
4 |
|
public function create(): UuidDomainObjectInterface |
28
|
|
|
{ |
29
|
4 |
|
return $this->concreteCreate(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Store the DomainObject in persistent storage. Either insert |
34
|
|
|
* or update the store as required. |
35
|
|
|
* |
36
|
|
|
* @param UuidDomainObjectInterface $domainObject |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
3 |
|
public function save(UuidDomainObjectInterface &$domainObject): void |
41
|
|
|
{ |
42
|
3 |
|
if ($domainObject->getId() === '') { |
43
|
3 |
|
$this->concreteInsert($domainObject); |
44
|
3 |
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
$this->concreteUpdate($domainObject); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Delete the DomainObject from persistent storage. |
52
|
|
|
* |
53
|
|
|
* @param UuidDomainObjectInterface $domainObject |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
3 |
|
public function delete(UuidDomainObjectInterface &$domainObject): void |
58
|
|
|
{ |
59
|
3 |
|
$this->concreteDelete($domainObject); |
60
|
3 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Create a new instance of a DomainObject. |
64
|
|
|
* |
65
|
|
|
* @return UuidDomainObjectInterface |
66
|
|
|
*/ |
67
|
|
|
abstract protected function concreteCreate(): UuidDomainObjectInterface; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Insert the DomainObject to persistent storage. |
71
|
|
|
* |
72
|
|
|
* @param UuidDomainObjectInterface $domainObject |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
abstract protected function concreteInsert(UuidDomainObjectInterface &$domainObject); |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Update the DomainObject in persistent storage. |
80
|
|
|
* |
81
|
|
|
* @param UuidDomainObjectInterface $domainObject |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
abstract protected function concreteUpdate(UuidDomainObjectInterface $domainObject); |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Delete the DomainObject from peristent Storage. |
89
|
|
|
* |
90
|
|
|
* @param UuidDomainObjectInterface $domainObject |
91
|
|
|
* |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
abstract protected function concreteDelete(UuidDomainObjectInterface &$domainObject); |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Check for valid domain Object. |
98
|
|
|
* |
99
|
|
|
* @param UuidDomainObjectInterface $domainObject |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
* |
103
|
|
|
* @throws InvalidArgumentException if the domain object isn't of the type required by mapper |
104
|
|
|
*/ |
105
|
|
|
abstract protected function checkDomainObjectType(UuidDomainObjectInterface $domainObject); |
106
|
|
|
} |
107
|
|
|
|