forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntityManagerInterface.php
241 lines (211 loc) · 7.41 KB
/
EntityManagerInterface.php
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
declare(strict_types=1);
namespace Doctrine\ORM;
use DateTimeInterface;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\FilterCollection;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Persistence\ObjectManager;
interface EntityManagerInterface extends ObjectManager
{
/**
* {@inheritDoc}
*
* @param class-string<T> $className
*
* @return EntityRepository<T>
*
* @template T of object
*/
public function getRepository(string $className): EntityRepository;
/**
* Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.
*/
public function getCache(): Cache|null;
/**
* Gets the database connection object used by the EntityManager.
*/
public function getConnection(): Connection;
public function getMetadataFactory(): ClassMetadataFactory;
/**
* Gets an ExpressionBuilder used for object-oriented construction of query expressions.
*
* Example:
*
* <code>
* $qb = $em->createQueryBuilder();
* $expr = $em->getExpressionBuilder();
* $qb->select('u')->from('User', 'u')
* ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));
* </code>
*/
public function getExpressionBuilder(): Expr;
/**
* Starts a transaction on the underlying database connection.
*/
public function beginTransaction(): void;
/**
* Executes a function in a transaction.
*
* The function gets passed this EntityManager instance as an (optional) parameter.
*
* {@link flush} is invoked prior to transaction commit.
*
* If an exception occurs during execution of the function or flushing or transaction commit,
* the transaction is rolled back, the EntityManager closed and the exception re-thrown.
*
* @psalm-param callable(self): T $func The function to execute transactionally.
*
* @return mixed The value returned from the closure.
* @psalm-return T
*
* @template T
*/
public function wrapInTransaction(callable $func): mixed;
/**
* Commits a transaction on the underlying database connection.
*/
public function commit(): void;
/**
* Performs a rollback on the underlying database connection.
*/
public function rollback(): void;
/**
* Creates a new Query object.
*
* @param string $dql The DQL string.
*/
public function createQuery(string $dql = ''): Query;
/**
* Creates a native SQL query.
*/
public function createNativeQuery(string $sql, ResultSetMapping $rsm): NativeQuery;
/**
* Create a QueryBuilder instance
*/
public function createQueryBuilder(): QueryBuilder;
/**
* Finds an Entity by its identifier.
*
* @param string $className The class name of the entity to find.
* @param mixed $id The identity of the entity to find.
* @param LockMode|int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @param int|null $lockVersion The version of the entity to find when using
* optimistic locking.
* @psalm-param class-string<T> $className
* @psalm-param LockMode::*|null $lockMode
*
* @return object|null The entity instance or NULL if the entity can not be found.
* @psalm-return T|null
*
* @throws OptimisticLockException
* @throws ORMInvalidArgumentException
* @throws TransactionRequiredException
* @throws ORMException
*
* @template T of object
*/
public function find(string $className, mixed $id, LockMode|int|null $lockMode = null, int|null $lockVersion = null): object|null;
/**
* Refreshes the persistent state of an object from the database,
* overriding any local changes that have not yet been persisted.
*
* @param LockMode|int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @psalm-param LockMode::*|null $lockMode
*
* @throws ORMInvalidArgumentException
* @throws ORMException
* @throws TransactionRequiredException
*/
public function refresh(object $object, LockMode|int|null $lockMode = null): void;
/**
* Gets a reference to the entity identified by the given type and identifier
* without actually loading it, if the entity is not yet loaded.
*
* @param class-string<T> $entityName The name of the entity type.
* @param mixed $id The entity identifier.
*
* @return T|null The entity reference.
*
* @throws ORMException
*
* @template T of object
*/
public function getReference(string $entityName, mixed $id): object|null;
/**
* Closes the EntityManager. All entities that are currently managed
* by this EntityManager become detached. The EntityManager may no longer
* be used after it is closed.
*/
public function close(): void;
/**
* Acquire a lock on the given entity.
*
* @psalm-param LockMode::* $lockMode
*
* @throws OptimisticLockException
* @throws PessimisticLockException
*/
public function lock(object $entity, LockMode|int $lockMode, DateTimeInterface|int|null $lockVersion = null): void;
/**
* Gets the EventManager used by the EntityManager.
*/
public function getEventManager(): EventManager;
/**
* Gets the Configuration used by the EntityManager.
*/
public function getConfiguration(): Configuration;
/**
* Check if the Entity manager is open or closed.
*/
public function isOpen(): bool;
/**
* Gets the UnitOfWork used by the EntityManager to coordinate operations.
*/
public function getUnitOfWork(): UnitOfWork;
/**
* Create a new instance for the given hydration mode.
*
* @psalm-param string|AbstractQuery::HYDRATE_* $hydrationMode
*
* @throws ORMException
*/
public function newHydrator(string|int $hydrationMode): AbstractHydrator;
/**
* Gets the proxy factory used by the EntityManager to create entity proxies.
*/
public function getProxyFactory(): ProxyFactory;
/**
* Gets the enabled filters.
*/
public function getFilters(): FilterCollection;
/**
* Checks whether the state of the filter collection is clean.
*/
public function isFiltersStateClean(): bool;
/**
* Checks whether the Entity Manager has filters.
*/
public function hasFilters(): bool;
/**
* {@inheritDoc}
*
* @param string|class-string<T> $className
*
* @psalm-return ($className is class-string<T> ? Mapping\ClassMetadata<T> : Mapping\ClassMetadata<object>)
*
* @psalm-template T of object
*/
public function getClassMetadata(string $className): Mapping\ClassMetadata;
}