Skip to content

Commit 77f1c9e

Browse files
ACPT-1929: Fixing issuls in ACPT-1493
* fixing inheritance issues * fixing issues with types (by removing feature)
1 parent 781f340 commit 77f1c9e

File tree

1 file changed

+24
-20
lines changed
  • lib/internal/Magento/Framework/ObjectManager/Resetter

1 file changed

+24
-20
lines changed

lib/internal/Magento/Framework/ObjectManager/Resetter/Resetter.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(
5757
if (!$resetData) {
5858
throw new LocalizedException(__('Error parsing %1', $resetPath));
5959
}
60-
$this->classList = array_replace($this->classList, $resetData);
60+
$this->classList += $resetData;
6161
}
6262
$this->resetAfterWeakMap = new WeakMap;
6363
}
@@ -85,7 +85,7 @@ public function addInstance(object $instance) : void
8585
{
8686
if ($instance instanceof ResetAfterRequestInterface
8787
|| \method_exists($instance, self::RESET_STATE_METHOD)
88-
|| isset($this->classList[\get_class($instance)])
88+
|| $this->isObjectInClassList($instance)
8989
) {
9090
$this->resetAfterWeakMap[$instance] = true;
9191
}
@@ -129,8 +129,18 @@ public function setObjectManager(ObjectManagerInterface $objectManager) : void
129129
$this->objectManager = $objectManager;
130130
}
131131

132+
public function isObjectInClassList(object $object)
133+
{
134+
foreach ($this->classList as $key => $value) {
135+
if ($object instanceof $key) {
136+
return true;
137+
}
138+
}
139+
return false;
140+
}
141+
132142
/**
133-
* State reset without reflection
143+
* State reset using reflection (or RESET_STATE_METHOD instead if it exists)
134144
*
135145
* @param object $instance
136146
* @return void
@@ -142,29 +152,23 @@ private function resetStateWithReflection(object $instance)
142152
$instance->{self::RESET_STATE_METHOD}();
143153
return;
144154
}
145-
$className = \get_class($instance);
155+
foreach ($this->classList as $className => $value) {
156+
if ($instance instanceof $className) {
157+
$this->resetStateWithReflectionByClassName($instance, $className);
158+
}
159+
}
160+
}
161+
private function resetStateWithReflectionByClassName(object $instance, string $className)
162+
{
163+
$classResetValues = $this->classList[$className] ?? [];
146164
$reflectionClass = $this->reflectionCache[$className]
147165
?? $this->reflectionCache[$className] = new \ReflectionClass($className);
148166
foreach ($reflectionClass->getProperties() as $property) {
149-
$type = $property->getType()?->getName();
150-
if (empty($type) && preg_match('/@var\s+([^\s]+)/', $property->getDocComment(), $matches)) {
151-
$type = $matches[1];
152-
if (\str_contains($type, '[]')) {
153-
$type = 'array';
154-
}
155-
}
156167
$name = $property->getName();
157-
if (!in_array($type, ['bool', 'array', 'null', 'true', 'false'], true)) {
168+
if (!array_key_exists($name, $classResetValues)) {
158169
continue;
159170
}
160-
$value = $this->classList[$className][$name] ??
161-
match ($type) {
162-
'bool' => false,
163-
'true' => true,
164-
'false' => false,
165-
'array' => [],
166-
'null' => null,
167-
};
171+
$value = $classResetValues[$name];
168172
$property->setAccessible(true);
169173
$property->setValue($instance, $value);
170174
$property->setAccessible(false);

0 commit comments

Comments
 (0)