| Conditions | 2 |
| Paths | 2 |
| Total Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function build(BlockGenerator $body) |
||
| 23 | { |
||
| 24 | $this->assertMandatoryProperties(); |
||
| 25 | |||
| 26 | if ($this->instance->hasReturnValue()) { |
||
| 27 | $returnValue = $this->instance->getReturnValue(); |
||
| 28 | } else { |
||
| 29 | throw new RuntimeException( |
||
| 30 | 'return value in instance is mandatory' |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | |||
| 34 | //@todo does it make sense to store the factory in the instance |
||
| 35 | // pool since we are using it only once? |
||
| 36 | $body |
||
| 37 | ->add('$className = \'' . $returnValue . '\';') |
||
| 38 | ->add('') |
||
| 39 | ->add('if ($this->isNotInSharedInstancePool($className)) {') |
||
| 40 | ->startIndention() |
||
| 41 | ->add('$factoryClassName = \'' . $this->instance->getClassName() . '\';') |
||
| 42 | ->add('$factory = $this->fetchFromFactoryInstancePool($factoryClassName);') |
||
| 43 | ->add('') |
||
| 44 | ->add('$this->addToSharedInstancePool($className, $factory->create());') |
||
| 45 | ->stopIndention() |
||
| 46 | ->add('}') |
||
| 47 | ->add('') |
||
| 48 | ->add('return $this->fetchFromSharedInstancePool($className);'); |
||
| 49 | |||
| 50 | return $body; |
||
| 51 | } |
||
| 52 | } |