[TYPO3-mvc] Question about restrictions in DataMapper->mapResultToPropertyValue
Franz Koch
typo3.RemoveForMessage at elements-net.de
Thu Jun 17 20:26:03 CEST 2010
Hey there,
as some of you might have read in a different thread, I'm currently
working on a import script. I try to let extbase handle most of the
validation and mapping stuff and therefor I tried to use
dataMapper->mapResultToPropertyValue to map my import data correctly on
my objects. But unfortunately this method is not working if my property
is of type string/boolean/integer/float/... - so not an object.
Code snippet:
----------------------------
> public function mapResultToPropertyValue(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $result) {
> if ($result instanceof Tx_Extbase_Persistence_LoadingStrategyInterface) {
> $propertyValue = $result;
> } else {
> $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
> $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
> if (in_array($propertyMetaData['type'], array('array', 'ArrayObject', 'SplObjectStorage', 'Tx_Extbase_Persistence_ObjectStorage'))) {
... ##### some object related stuff here
> } elseif (strpos($propertyMetaData['type'], '_') !== FALSE) {
> if (is_array($result)) {
> $propertyValue = current($result);
> } else {
> $propertyValue = $result;
> }
> }
> }
> return $propertyValue;
> }
interesting is the part below my comment, where the propertyType is
explicitly checked for a underscore. What's the reason for this?
Wouldn't it be a great idea to drop that check there and move the type
conversion for "regular" property types (string,integer,boolean,...)
from the "thawProperties" method to that method?
That would allow quite more flexibility, as "thawProperties" can't be
used for updating objects (due to setting of the uid etc) and
mapResultToPropertyValue doesn't handle everything needed. What do you
guys think about that?
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list