Ejemplo n.º 1
0
 /**
  * Creates an instance of the provided dependency
  * @param string $interface Full class name of the interface or parent class
  * @param Dependency $dependency Definition of the class to create
  * @param array $exclude Array with the interface as key and an array with
  * id's of dependencies as key to exclude from the get calls.
  * @return mixed Instance of the dependency
  * @throws zibo\ZiboException when the dependency could not be created
  */
 protected function create($interface, Dependency $dependency, array $exclude = null)
 {
     if (!self::$objectFactory) {
         self::$objectFactory = new ObjectFactory();
     }
     if (!$exclude) {
         $exclude = array($interface => array($dependency->getId() => true));
     } elseif (!isset($exclude[$interface])) {
         $exclude[$interface] = array($dependency->getId() => true);
     } else {
         $exclude[$interface][$dependency->getId()] = true;
     }
     $className = $dependency->getClassName();
     $arguments = $dependency->getConstructorArguments();
     $arguments = $this->getCallbackArguments($arguments, $exclude);
     $instance = self::$objectFactory->create($className, $interface, $arguments);
     $calls = $dependency->getCalls();
     if ($calls) {
         foreach ($calls as $call) {
             $arguments = $this->getCallbackArguments($call->getArguments(), $exclude);
             $callback = new Callback(array($instance, $call->getMethodName()));
             $callback->invokeWithArrayArguments($arguments);
         }
     }
     return $instance;
 }