Phemto and Value Lifecycle

I’ve discovered Value Lifecycle in the Phemto code. it is not covered by documentation though.

I’ve expected to use the following code

class A
  protected $data;
  function __construct(array $data)

$class B
  public function __construc(A $a){}

$a=new A(array('param'=>'taram'));
$injector=new Phemto();
$injector->willUse($a); //or I can use $injector->willUse(new Value($a));

But I have an error here. In Phemto.php, line 154, injector tries to createDependencies, and fails to create dependency for an ‘array’.

I think it should just return value. So for my own use I’ve hacked code here and just return if $lifecycle is instance of Value. Is it correct?

Here is my snippet, from line 153 (Phemto 0.1, aplha 9)

class class Context {
function create($type, $nesting = array()) {
        $lifecycle = $this->pick($type, $this->repository()->candidatesFor($type));
        $context = $this->determineContext($lifecycle->class);
        if ($wrapper = $context->hasWrapper($type, $nesting)) {
            return $this->create($wrapper, $this->cons($wrapper, $nesting));

        //Change here:
        if ($lifecycle instanceof Value) return $lifecycle->instantiate(null);
        //end of change
        $instance = $lifecycle->instantiate($context->createDependencies(
                        $this->cons($lifecycle->class, $nesting)));
        foreach ($context->settersFor($lifecycle->class) as $setter) {
            $context->invoke($instance, $setter, $context->createDependencies(
                                $this->repository()->getParameters($lifecycle->class, $setter),
                                $this->cons($lifecycle->class, $nesting)));
        return $instance;


It’s just that Phemto doesn’t understand the array type hint. It just didn’t exist when I wrote the first version. willUse() should understand that it’s a non-lifecycle and just use the value. Don’t know why it failed. I’ll add it as a test case and fix it.

yours, Marcus


This failure is pretty simple.


will return value ignoring $deps parameter (for Value lifecycle). But. The code will try to build this deps before instantiate call. Of course it fails while determine array implementation. My hack just prevent this building.

Thank you for response.