-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
ObjectManager.php
170 lines (155 loc) · 5 KB
/
ObjectManager.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
<?php
namespace Doctrine\Persistence;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
/**
* Contract for a Doctrine persistence layer ObjectManager class to implement.
*/
interface ObjectManager
{
/**
* Finds an object by its identifier.
*
* This is just a convenient shortcut for getRepository($className)->find($id).
*
* @param string $className The class name of the object to find.
* @param mixed $id The identity of the object to find.
* @psalm-param class-string<T> $className
*
* @return object|null The found object.
* @psalm-return T|null
*
* @template T of object
*/
public function find($className, $id);
/**
* Tells the ObjectManager to make an instance managed and persistent.
*
* The object will be entered into the database as a result of the flush operation.
*
* NOTE: The persist operation always considers objects that are not yet known to
* this ObjectManager as NEW. Do not pass detached objects to the persist operation.
*
* @param object $object The instance to make managed and persistent.
*
* @return void
*/
public function persist($object);
/**
* Removes an object instance.
*
* A removed object will be removed from the database as a result of the flush operation.
*
* @param object $object The object instance to remove.
*
* @return void
*/
public function remove($object);
/**
* Merges the state of a detached object into the persistence context
* of this ObjectManager and returns the managed copy of the object.
* The object passed to merge will not become associated/managed with this ObjectManager.
*
* @deprecated Merge operation is deprecated and will be removed in Persistence 2.0.
* Merging should be part of the business domain of an application rather than
* a generic operation of ObjectManager.
*
* @param object $object
*
* @return object
*/
public function merge($object);
/**
* Clears the ObjectManager. All objects that are currently managed
* by this ObjectManager become detached.
*
* @param string|null $objectName if given, only objects of this type will get detached.
*
* @return void
*/
public function clear($objectName = null);
/**
* Detaches an object from the ObjectManager, causing a managed object to
* become detached. Unflushed changes made to the object if any
* (including removal of the object), will not be synchronized to the database.
* Objects which previously referenced the detached object will continue to
* reference it.
*
* @deprecated Detach operation is deprecated and will be removed in Persistence 2.0. Please use
* {@see ObjectManager::clear()} instead.
*
* @param object $object The object to detach.
*
* @return void
*/
public function detach($object);
/**
* Refreshes the persistent state of an object from the database,
* overriding any local changes that have not yet been persisted.
*
* @param object $object The object to refresh.
*
* @return void
*/
public function refresh($object);
/**
* Flushes all changes to objects that have been queued up to now to the database.
* This effectively synchronizes the in-memory state of managed objects with the
* database.
*
* @return void
*/
public function flush();
/**
* Gets the repository for a class.
*
* @param string $className
* @psalm-param class-string<T> $className
*
* @return ObjectRepository
* @psalm-return ObjectRepository<T>
*
* @template T
*/
public function getRepository($className);
/**
* Returns the ClassMetadata descriptor for a class.
*
* The class name must be the fully-qualified class name without a leading backslash
* (as it is returned by get_class($obj)).
*
* @param string $className
* @psalm-param class-string<T> $className
*
* @return ClassMetadata
* @psalm-return ClassMetadata<T>
*
* @template T of object
*/
public function getClassMetadata($className);
/**
* Gets the metadata factory used to gather the metadata of classes.
*
* @return ClassMetadataFactory
* @psalm-return ClassMetadataFactory<ClassMetadata<object>>
*/
public function getMetadataFactory();
/**
* Helper method to initialize a lazy loading proxy or persistent collection.
*
* This method is a no-op for other objects.
*
* @param object $obj
*
* @return void
*/
public function initializeObject($obj);
/**
* Checks if the object is part of the current UnitOfWork and therefore managed.
*
* @param object $object
*
* @return bool
*/
public function contains($object);
}