[TYPO3-mvc] non-db based value objects and embedded values - how to?
Martin Kutschker
masi-no at spam-typo3.org
Sun May 30 19:46:39 CEST 2010
Hi!
Or how to extend the data mapper? As I perceive it the data mapper is currently limited to scalars
and object relations. Even value objects are treated as relations in as much as Extbase supports
AFAIK only value objects which values are based on a DB table.
I have tried to represent a TCA select field with fixed values (defined in the TCA as array) as a
value object (with a factory). But other value objects can be imagined, the DateTime object used by
Extbase itself is such an example.
A solution I can imagine is that whenever the data mapper processes a property that isn't a scalar
it will look for a factory class. If found it will use it, if not it will proceed as as usual (and
restore the object).
An alternative solution could be to add a new configuration option to the persistence configuration
is TS. I see three options:
config.tx_extbase.persistence.classes.Tx_Foobar.mapping {
properties {
# use static method of a factory class
# arguments: DB field value and object
myProperty1.instantiation = Factory::create
# use a method of the model class itself
# arguments: DB field value
myProperty2.instantiation = createProperty
# use the constructor of the property class
# arguments: DB field value
myProperty3a.instantiation = PropertyClass
# use the constructor of the property class
# arguments for constructor: DB field value
# arguments for injection method: object
myProperty3b.instantiation = PropertyClass/injectionMethod
}
}
Cases 2 and 3 differ in syntax only in the first letter: methods start with a lower case letter,
classes with one in upper case.
Case 3 has variant that lets you define an injector separated with a slash form the class name to be
called after calling the constructor.
A bit more complex are embedded values (eg a range object that consists of a start date and an end
date). The issue is to find a way so that the instantiation method gets all the values from the row
it needs.
A possible way is to extend the syntax from above with a "columns" option:
config.tx_extbase.persistence.classes.Tx_Foobar.mapping {
properties {
myProperty.instantiation = <method>
myProperty.columns = column1,column2
}
}
Now the method isn't called with just one parameter but with one for each listed columns (in the
order of the TS configuration). Possible alternatives to using multiple parameters are passing an
array or an object (of type stdObj).
config.tx_extbase.persistence.classes.Tx_Foobar.mapping {
properties {
myProperty.instantiation = <method>
myProperty.columns = <columns>
myProperty.argument = list | array | object
}
}
Does this make any sense to you?
Masi
More information about the TYPO3-project-typo3v4mvc
mailing list