forked from nextras/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIRepository.php
More file actions
211 lines (147 loc) · 4.09 KB
/
IRepository.php
File metadata and controls
211 lines (147 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php declare(strict_types = 1);
/**
* This file is part of the Nextras\Orm library.
* This file was inspired by PetrP's ORM library https://github.com/PetrP/Orm/.
* @license MIT
* @link https://github.com/nextras/orm
*/
namespace Nextras\Orm\Repository;
use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Entity\IEntity;
use Nextras\Orm\Entity\Reflection\EntityMetadata;
use Nextras\Orm\Mapper\IMapper;
use Nextras\Orm\Model\IModel;
interface IRepository
{
public function getModel(): IModel;
public function setModel(IModel $model);
public function getMapper(): IMapper;
/**
* Hydrates entity.
* @return IEntity|null
*/
public function hydrateEntity(array $data);
/**
* Attaches entity to repository.
*/
public function attach(IEntity $entity);
/**
* Detaches entity from repository.
*/
public function detach(IEntity $entity);
/**
* Returns possible entity class names for current repository.
* @return string[]
*/
public static function getEntityClassNames(): array;
/**
* @param string|null $entityClass for STI (must extends base class)
* Returns entity metadata.
*/
public function getEntityMetadata(string $entityClass = NULL): EntityMetadata;
/**
* Returns entity class name.
*/
public function getEntityClassName(array $data): string;
/**
* Returns IEntity filtered by conditions
* @return IEntity|null
*/
public function getBy(array $conds);
/**
* Returns entity by primary value.
* @param mixed $primaryValue
* @return IEntity|null
*/
public function getById($primaryValue);
/**
* Returns entity collection with all entities.
*/
public function findAll(): ICollection;
/**
* Returns entity collection filtered by conditions.
*/
public function findBy(array $where): ICollection;
/**
* Returns entities by primary values.
* @param mixed[] $primaryValues
*/
public function findById($primaryValues): ICollection;
/**
* Returns collection functions instance.
* @return object
*/
public function getCollectionFunction(string $name);
/**
* @return mixed
*/
public function persist(IEntity $entity, bool $withCascade = true);
/**
* @return mixed
*/
public function persistAndFlush(IEntity $entity, bool $withCascade = true);
/**
* @param IEntity|mixed $entity
*/
public function remove($entity, bool $withCascade = true): IEntity;
/**
* @param IEntity|mixed $entity
*/
public function removeAndFlush($entity, bool $withCascade = true): IEntity;
/**
* Flushes all persisted changes in all repositories.
*/
public function flush();
/**
* DO NOT CALL THIS METHOD DIRECTLY.
* @internal
* @ignore
*/
public function doPersist(IEntity $entity);
/**
* DO NOT CALL THIS METHOD DIRECTLY.
* @internal
* @ignore
*/
public function doRemove(IEntity $entity);
/**
* DO NOT CALL THIS METHOD DIRECTLY.
* @internal
* @ignore
* The first key contains all flushed persisted entities.
* The second key contains all flushed removed entities.
* @return array<array<IEntity>> Returns array where index 0 contains all persited, index 1 contains array of removed entities.
*/
public function doFlush();
/**
* DO NOT CALL THIS METHOD DIRECTLY.
* @internal
* @ignore
*/
public function doClear();
/**
* DO NOT CALL THIS METHOD DIRECTLY.
* Fires the event on the entity.
* @internal
* @ignore
* @return void
*/
public function doRefreshAll(bool $allowOverwrite);
// === events ======================================================================================================
/** @internal */
public function onBeforePersist(IEntity $entity);
/** @internal */
public function onAfterPersist(IEntity $entity);
/** @internal */
public function onBeforeInsert(IEntity $entity);
/** @internal */
public function onAfterInsert(IEntity $entity);
/** @internal */
public function onBeforeUpdate(IEntity $entity);
/** @internal */
public function onAfterUpdate(IEntity $entity);
/** @internal */
public function onBeforeRemove(IEntity $entity);
/** @internal */
public function onAfterRemove(IEntity $entity);
}