[dev] Injector musings

Michael M Slusarz slusarz at horde.org
Thu Mar 25 20:36:39 UTC 2010


Quoting Chuck Hagenbuch <chuck at horde.org>:

> Quoting Michael M Slusarz <slusarz at horde.org>:
>
>> Thus, the need for something like:
>> $contents = $injector->getInstance('IMP_Contents', 1 . IMP::IDX_SEP  
>> . 'INBOX');
>> $contents2 = $injector->getInstance('IMP_Contents', 2 .  
>> IMP::IDX_SEP . 'INBOX');
>>
>> Then later on, when I call
>> $injector->getInstance('IMP_Contents', 1 . IMP::IDX_SEP . 'INBOX');
>>
>> I will get the $contents object that was previously instantiated.
>
> Ah, okay. So I think what's called here for is a factory. Something like:
>
> $contentsFactory = $injector->getInstance('IMP_Contents_Factory');
> $contents1 = $contentsFactory->getContents(1, 'INBOX');
> $contents2 = $contentsFactory->getContents(2, 'INBOX');
>
> ... etc. The factory can internally manage whether or not a contents  
> object has been created before.

If someone could check out what I just did re: Horde_Editor, that  
would be great.  Seems a bit of overkill in that I had to create a  
binder to point to a factory which, in turn, creates the Editor  
object.  But I can't figure out another way to do it given the current  
injector API (injector factories do not provide any help here).

As mentioned previously, the current injector API seems to have a  
limitation when it comes to run-time configuration.  In other words,  
objects that require the same standardized setup but may contain  
different data depending on the run-time environment.

michael

-- 
___________________________________
Michael Slusarz [slusarz at horde.org]



More information about the dev mailing list