|
1
|
|
|
<?php |
|
2
|
|
|
namespace vakata\orm; |
|
3
|
|
|
|
|
4
|
|
|
class UnitOfWorkRepository implements Repository |
|
5
|
|
|
{ |
|
6
|
|
|
protected $uow; |
|
7
|
|
|
protected $repository; |
|
8
|
|
|
|
|
9
|
1 |
|
public function __construct(Repository $repository, UnitOfWork $uow) |
|
10
|
|
|
{ |
|
11
|
1 |
|
$this->repository = $repository; |
|
12
|
1 |
|
$this->uow = $uow; |
|
13
|
1 |
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function find($id) |
|
16
|
|
|
{ |
|
17
|
|
|
return $this->repository->find($id); |
|
18
|
|
|
} |
|
19
|
|
|
public function filter(string $column, $value) : Repository |
|
20
|
|
|
{ |
|
21
|
|
|
$this->repository->filter($column, $value); |
|
22
|
|
|
return $this; |
|
23
|
|
|
} |
|
24
|
|
|
public function reject(string $column, $value) : Repository |
|
25
|
|
|
{ |
|
26
|
|
|
$this->repository->reject($column, $value); |
|
27
|
|
|
return $this; |
|
28
|
|
|
} |
|
29
|
|
|
public function any(array $criteria) : Repository |
|
30
|
|
|
{ |
|
31
|
|
|
$this->repository->any($criteria); |
|
32
|
|
|
return $this; |
|
33
|
|
|
} |
|
34
|
|
|
public function all(array $criteria) : Repository |
|
35
|
|
|
{ |
|
36
|
|
|
$this->repository->all($criteria); |
|
37
|
|
|
return $this; |
|
38
|
|
|
} |
|
39
|
|
|
public function sort(string $column, bool $desc = false) : Repository |
|
40
|
|
|
{ |
|
41
|
|
|
$this->repository->sort($column, $desc); |
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
public function limit(int $limit, int $offset = 0) : Repository |
|
45
|
|
|
{ |
|
46
|
|
|
$this->repository->limit($limit, $offset); |
|
47
|
|
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
public function reset() : Repository |
|
50
|
|
|
{ |
|
51
|
|
|
$this->repository->reset(); |
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
public function append($entity) : Repository |
|
56
|
|
|
{ |
|
57
|
1 |
|
$this->uow->append($entity, $this->repository); |
|
58
|
1 |
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
public function change($entity) : Repository |
|
61
|
|
|
{ |
|
62
|
|
|
$this->uow->change($entity, $this->repository); |
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
public function remove($entity) : Repository |
|
66
|
|
|
{ |
|
67
|
|
|
$this->uow->remove($entity, $this->repository); |
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function current() |
|
72
|
|
|
{ |
|
73
|
|
|
$data = $this->repository->current(); |
|
74
|
|
|
if ($data !== null) { |
|
75
|
|
|
$this->uow->register($data, $this->repository); |
|
76
|
|
|
} |
|
77
|
|
|
return $data; |
|
78
|
|
|
} |
|
79
|
1 |
|
public function offsetGet($offset) |
|
80
|
|
|
{ |
|
81
|
1 |
|
$data = $this->repository->offsetGet($offset); |
|
82
|
1 |
|
if ($data !== null) { |
|
83
|
1 |
|
$this->uow->register($data, $this->repository); |
|
84
|
|
|
} |
|
85
|
1 |
|
return $data; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function key() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->repository->key(); |
|
91
|
|
|
} |
|
92
|
|
|
public function rewind() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->repository->rewind(); |
|
95
|
|
|
} |
|
96
|
|
|
public function next() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->repository->next(); |
|
99
|
|
|
} |
|
100
|
|
|
public function valid() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->repository->valid(); |
|
103
|
|
|
} |
|
104
|
|
|
public function offsetExists($offset) |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->repository->offsetExists($offset); |
|
107
|
|
|
} |
|
108
|
|
|
public function offsetUnset($offset) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->remove($this->offsetGet($offset)); |
|
111
|
|
|
} |
|
112
|
|
|
public function offsetSet($offset, $value) |
|
113
|
|
|
{ |
|
114
|
|
|
if ($offset !== null) { |
|
115
|
|
|
throw new \BadMethodCallException(); |
|
116
|
|
|
} |
|
117
|
|
|
$this->append($value); |
|
118
|
|
|
} |
|
119
|
|
|
public function count() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->repository->count(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function isConsumed() : bool |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->repository->isConsumed(); |
|
127
|
|
|
} |
|
128
|
|
|
public function isModified() : bool |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->repository->isModified(); |
|
131
|
|
|
} |
|
132
|
|
|
public function toArray($entity) : array |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->repository->toArray($entity); |
|
135
|
|
|
} |
|
136
|
|
|
public function search(string $q) : Repository |
|
137
|
|
|
{ |
|
138
|
|
|
$this->repository->search($q); |
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
} |