Bug #70872
closedPropertyMapper shouldn't be a Singleton
100%
Description
Hello.
I have a problem with PropertyMapper being a Singleton, becasue on each ->convert()
call it kills own property messages
.
I have an input from a user, which I need to convert with custom TypeConverter (I convert a csv-file to ObjectStorage with specific objects). And whenever some error occurs on this phase (e.g. wrong file content) I return an instance of \TYPO3\CMS\Extbase\Error\Error
from convertFrom()
of my TypeConverter. This works nice and errorAction()
of my Controller is called, so I'm able to show an error to a user.
But at same time and same request I'm asking external service for additional objects, I need to construct and show to a user. External service returns a JSON response, which is converted to array and I'm using PropertyMapper to map array to needed objects. And this phase is crucial: as soon as I make first call to $propertyMapper->convert()
all the errors from the previous phase are lost and no errorAction()
is called, so user sees a success screen, while an error happened in reality.
Sure, there are workarounds:
1. Don't use PropertyMapper, but create objects via 'new', 'objectManager->get' or whatever and then set their properties by set-ers. The problem with this workaround is, that in case I need some sophisticated TypeConverter I can't use it.
2. Merge error messages every time, when you use PropertyMapper:
$propertyMapper = $this->_objectManager->get(PropertyMapper::class); $messages = $propertyMapper->getMessages(); $object = $propertyMapper->convert($dataArray, Object::class); $propertyMapper->getMessages()->merge($messages);
But this really a hack.
So, it makes sense to avoid Singleton for PropertyMapper.
Updated by Viktor Livakivskyi about 9 years ago
One more benefit of using PropertyMapper
over objectManager->get()
is the ability to use property validation out-of-the-box.
Updated by Gerrit Code Review over 4 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65045
Updated by Gerrit Code Review over 4 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65045
Updated by Gerrit Code Review over 4 years ago
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65114
Updated by Gerrit Code Review over 4 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65114
Updated by Gerrit Code Review over 4 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65114
Updated by Gerrit Code Review over 4 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65114
Updated by Benni Mack over 4 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 2f05c8dc939da54850a230190b2656b2ef73542a.