[TYPO3-50-general] Generic Object Access
Sebastian Kurfürst
sebastian at typo3.org
Mon Jan 5 22:10:47 CET 2009
Hi,
today, after programming for the fifth time some code which would call
the appropriate getter/setter on an object if you had the property
name, I decided to do it at one central place.
That's why I added a static class: \F3\FLOW3\Reflection\ObjectAccess
(see [1]) which provides methods to handle these getter/setter
invocations.
The most important two methods on it are:
setProperty:
/**
* Set a property for a given object.
* Tries to set the property by the following ways:
* - if public setter method exists, call it.
* - if public property exists, set it directly.
* - if the target object is an instance of ArrayObject, it sets the
property on it without checking if it existed.
* - else, throw exception
*
getProperty:
/**
* Get a property of a given object.
* Tries to get the property by the following ways:
* - if public getter method exists, call it.
* - if public property exists, return the value of it.
* - if the target object is an instance of ArrayObject, it gets the
property on it if it exists.
* - else, throw exception
*
I think this handles most cases for generic getting and setting
properties.
I am currently in the process of adjusting the PropertyMapper.
Currently, it is only able to map to setter method names. After the
refactoring, it'll use the methods above, so it can set public
properties or ArrayAccess as well.
Do you think this makes sense? Are there more places where this should
be used? Does something come directly to your mind? :-)
Greets,
Sebastian
[1] http://forge.typo3.org/repositories/entry/package-flow3/trunk/Classes/Reflection/F3_FLOW3_Reflection_ObjectAccess.php?rev=1695
--
Gimme five!
More information about the TYPO3-project-5_0-general
mailing list