Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form] Made data mappers completely responsible for dealing with empt…
…y values. Removed duplication of code.
- Loading branch information
Showing
3 changed files
with
56 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,22 +23,24 @@ class PropertyPathMapper implements DataMapperInterface | |
*/ | ||
public function mapDataToForms($data, array $forms) | ||
{ | ||
if (!empty($data) && !is_array($data) && !is_object($data)) { | ||
if (null === $data || array() === $data) { | ||
return; | ||
} | ||
|
||
if (!is_array($data) && !is_object($data)) { | ||
throw new UnexpectedTypeException($data, 'object, array or empty'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
MDrollette
Contributor
|
||
} | ||
|
||
if (!empty($data)) { | ||
$iterator = new VirtualFormAwareIterator($forms); | ||
$iterator = new \RecursiveIteratorIterator($iterator); | ||
$iterator = new VirtualFormAwareIterator($forms); | ||
$iterator = new \RecursiveIteratorIterator($iterator); | ||
|
||
foreach ($iterator as $form) { | ||
/* @var FormInterface $form */ | ||
$propertyPath = $form->getPropertyPath(); | ||
$config = $form->getConfig(); | ||
foreach ($iterator as $form) { | ||
/* @var FormInterface $form */ | ||
$propertyPath = $form->getPropertyPath(); | ||
$config = $form->getConfig(); | ||
|
||
if (null !== $propertyPath && $config->getMapped()) { | ||
$form->setData($propertyPath->getValue($data)); | ||
} | ||
if (null !== $propertyPath && $config->getMapped()) { | ||
$form->setData($propertyPath->getValue($data)); | ||
} | ||
} | ||
} | ||
|
@@ -48,6 +50,14 @@ public function mapDataToForms($data, array $forms) | |
*/ | ||
public function mapFormsToData(array $forms, &$data) | ||
{ | ||
if (null === $data) { | ||
return; | ||
} | ||
|
||
if (!is_array($data) && !is_object($data)) { | ||
throw new UnexpectedTypeException($data, 'object, array or empty'); | ||
} | ||
|
||
$iterator = new VirtualFormAwareIterator($forms); | ||
$iterator = new \RecursiveIteratorIterator($iterator); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What is the reason for removing the empty() check? I'm now getting this exception even though $data is an empty string.
http://s.drollette.com/1W1w441L3t2Y1h1G2E3I