Example #1
0
 /**
  * Makes an object.
  *
  * @param Definition $definition
  *
  * @return mixed
  */
 private function makeObject(Definition $definition)
 {
     $class = $definition->getClass();
     $constructorInjections = $this->parseReference($definition->getConstructorInjections());
     $methodInjections = $this->parseReference($definition->getMethodInjections());
     $propertyInjections = $this->parseReference($definition->getPropertyInjections());
     $object = $class->newInstanceArgs($constructorInjections);
     foreach ($methodInjections as $methodName => $injections) {
         foreach ($injections as $args) {
             $class->getMethod($methodName)->invokeArgs($object, $args);
         }
     }
     foreach ($propertyInjections as $name => $value) {
         if ($class->hasProperty($name)) {
             $property = $class->getProperty($name);
             $property->setAccessible(true);
             $property->setValue($object, $value);
         } else {
             $object->{$name} = $value;
         }
     }
     return $object;
 }