Make Phemto use allready created object

Hi,

I’m using Phemto and is wondering if you can make Phemto use an object you’ve allready created when sending objects to an constructor for example.

I want to be able to create an object

$o = new Object();

and then say something like

$injector->for(“IObject”)->use($o);

-Martin

Use the Value lifecycle.


$o = new Object();
$injector->for("IObject")->use(new Value($o));

I don’t use Phemto, so I’m not quite sure if this is one of the possibilities. I don’t see it in the unit tests, and knowing McGruff, he won’t implement functionality before writing the Unit Test to prove said functionality actually works.

EDIT:
Guess Ren is right.

Thanks, I’ll try it out later today.

My version of Phemto (latest I believe) the for method does not seem to exist.

I would want something like this to work:

$injector->whenCreating("IConfig")->willUse(new Reused(new Config()));

Hi…


$injector->whenCreating('IObject')->willUse($o);

You can actually use anything which is not a Lifecycle or string…


$injector->forVariable('this_year')->willUse(2010);

If you want to instantiate a string, then you must wrap it in a Value object.

yours, Marcus.