[TYPO3-mvc] Cloning properties in setter and getter methods of models (blog example)
Sebastian Kurfürst
sebastian at typo3.org
Wed Feb 16 10:07:42 CET 2011
Hey Thomas,
> What if the addObject($object) method of the model
> grabs the $object, does some mighty magic with it
> and then attaches it to the object storage?
In this case, I would either add an explicit Doc Comment stating the
fact, or return a cloned list of objects.
> And if not, how
> could I ensure, that the developer _must_ use
> the addObject() method, to add objects?
You cannot easily. Alternatively, you could write some wrapper
ArrayObject (or the like) which throws exceptions if somebody writes to
it. Then, you could return the wrapped ObjectStorage.
> ...because the mighty magic happens when the object gets persisted.
> (The only thing bad about this is, that those $objects will have a
> wrong or no storage page assigned, until they get persisted. So you
> can't rely on a correct storage page, because the lazy properties
> are not yet correct. Hopefully that's understandable.)
Persistence Hooks are not yet implemented, as it's actually quite
difficult to archive correctly, as the order in which these "persist"
hooks are called on the different objects must be well-defined.
Greets,
Sebastian
More information about the TYPO3-project-typo3v4mvc
mailing list