@@ -18,8 +18,6 @@ class Collector
18
18
private readonly array $ skipListFromConstructed ;
19
19
private readonly array $ skipListBetweenRequests ;
20
20
21
- /** @var ObjectManager $objectManager Note: Using ObjectManagerInterface for DI to get correct instance */
22
-
23
21
public function __construct (
24
22
private readonly ObjectManagerInterface $ objectManager ,
25
23
SkipListAndFilterList $ skipListAndFilterList
@@ -76,15 +74,26 @@ function ($element) use (
76
74
}
77
75
78
76
/**
79
- * Gets shared objects from ObjectManager using reflection and clones properties that are objects
77
+ * Gets shared objects from ObjectManager using reflection and copies properties that are objects
80
78
*
81
79
* @param ShouldResetState $shouldResetState
82
80
* @return CollectedObject[]
83
81
*/
84
82
public function getSharedObjects (ShouldResetState $ shouldResetState ): array
85
83
{
84
+ if ($ this ->objectManager instanceof ObjectManager) {
85
+ $ sharedInstances = $ this ->objectManager ->getSharedInstances ();
86
+ } else {
87
+ $ obj = new \ReflectionObject ($ this ->objectManager );
88
+ if (!$ obj ->hasProperty ('_sharedInstances ' )) {
89
+ throw new \Exception ('Cannot get shared objects from ' . get_class ($ this ->objectManager ));
90
+ }
91
+ $ property = $ obj ->getProperty ('_sharedInstances ' );
92
+ $ property ->setAccessible (true );
93
+ $ sharedInstances = $ property ->getValue ($ this ->objectManager );
94
+ }
86
95
$ sharedObjects = [];
87
- foreach ($ this -> objectManager -> getSharedInstances () as $ serviceName => $ object ) {
96
+ foreach ($ sharedInstances as $ serviceName => $ object ) {
88
97
if (array_key_exists ($ serviceName , $ sharedObjects )) {
89
98
continue ;
90
99
}
@@ -154,9 +163,11 @@ public function getPropertiesFromObject(
154
163
if (array_key_exists ($ className , $ skipList )) {
155
164
return CollectedObject::getSkippedObject ();
156
165
}
157
- $ serviceName = array_search ($ object , $ this ->objectManager ->getSharedInstances ());
158
- if ($ serviceName && array_key_exists ($ serviceName , $ skipList )) {
159
- return CollectedObject::getSkippedObject ();
166
+ if ($ this ->objectManager instanceof ObjectManager) {
167
+ $ serviceName = array_search ($ object , $ this ->objectManager ->getSharedInstances ());
168
+ if ($ serviceName && array_key_exists ($ serviceName , $ skipList )) {
169
+ return CollectedObject::getSkippedObject ();
170
+ }
160
171
}
161
172
$ objReflection = new \ReflectionObject ($ object );
162
173
$ properties = [];
0 commit comments