[TYPO3-50-general] Persitence: reinjectDependencies doens't work with constructor injection?
Robert Lemke
robert at typo3.org
Fri Jul 3 09:45:48 CEST 2009
Moin Andi,
On 02.07.2009, at 12:32, Andreas Förthner wrote:
>> So it's not supported yet. However it does make sense in my eyes.
>> So I
>> suggest that you implement the following for the reinject method
>> (with
>> tests and all the klimmbimm):
>>
>> - Check what (constructor) arguments have been defined in the object
>> configuration
>> - Check if class properties with the same name exist
>> - If so, reinject them through reflection after the properties have
>> been
>> injected
>
> I think the general problem is, that the constructor might not be a
> simple setter, like the inject* methods. So
> reinjecting the inject* things is a quite defined task and we can be
> sure, that there is nothing going wrong.
> Reinjecting something through reflection, which usually runs through
> the constructor is something different.
What do you mean with "which usually runs through the constructor"?
Again, here's what I meant:
class Foo {
/**
* @var Dependency
*/
protected $depencency;
/**
* ...
*/
public function _construct(Dependency $depencency, $otherStuff) {
$this->doThings($otherStuff);
$this->depencency = $dependency;
}
}
So, in the above case your analysis would reveal that $depencency
exists as constructor argument
and as property. Therefore while reconstituting the object from the
session you would reinject
$dependency directly through Reflection ($propertyReflection-
>setValue()). The constructor would
not be called in that case (because you thaw the object with the
unserialize trick).
That should all work fine, except for one thing which disturbs me a
little: The analysis should
a) theoretically not happen in the reinjection mechanism and b) maybe
not only depend on variables having
the same name.
I don't have a good solution for that at hand but maybe you do.
Thinking about it some more I'd like to ask you to do this 120%
properly - that's such an important
part of FLOW3 which deserves a clean solution. So, no hacks please ;-)
robert
More information about the TYPO3-project-5_0-general
mailing list