Project

General

Profile

Actions

Bug #70872

closed

PropertyMapper shouldn't be a Singleton

Added by Viktor Livakivskyi about 9 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2015-10-20
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
7
PHP Version:
5.6
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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.

Actions #1

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.

Actions #2

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

Actions #3

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

Actions #4

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

Actions #5

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

Actions #6

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

Actions #7

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

Actions #8

Updated by Benni Mack over 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #9

Updated by Benni Mack about 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF