Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e5cab1

Browse files
committed
Catch only UninitializedPropertyException when getting a value per PropertyAcessor
1 parent a975d5e commit 1e5cab1

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ public function mapDataToForms($data, $forms)
5252
$form->setData($this->propertyAccessor->getValue($data, $propertyPath));
5353
} catch (AccessException $e) {
5454
// Skip unitialized properties on $data
55-
if (!$e instanceof UninitializedPropertyException
56-
// For versions without UninitializedPropertyException check the exception message
57-
&& (class_exists(UninitializedPropertyException::class) || false === strpos($e->getMessage(), 'You should initialize it'))
58-
) {
59-
throw $e;
60-
}
55+
$this->catchUninitializedPropertyException($e);
6156
}
6257
} else {
6358
$form->setData($config->getData());
@@ -118,7 +113,24 @@ private function getPropertyValue($data, $propertyPath)
118113
try {
119114
return $this->propertyAccessor->getValue($data, $propertyPath);
120115
} catch (AccessException $e) {
116+
117+
// The following line might be removed in future versions
118+
// See https://github.com/symfony/symfony/issues/36754
119+
$this->catchUninitializedPropertyException($e);
120+
121121
return null;
122122
}
123123
}
124+
125+
/**
126+
* Throw everything but UninitializedPropertyException
127+
*/
128+
private function catchUninitializedPropertyException(AccessException $e) {
129+
if (!$e instanceof UninitializedPropertyException
130+
// For versions without UninitializedPropertyException check the exception message
131+
&& (class_exists(UninitializedPropertyException::class) || false === strpos($e->getMessage(), 'You should initialize it'))
132+
) {
133+
throw $e;
134+
}
135+
}
124136
}

0 commit comments

Comments
 (0)