public function testAddCallWithConstructorCallWillNotAddCallButSetConstructorArguments() { $dependency = new Dependency('className'); $call = new DependencyCall('__construct'); $dependency->addCall($call); $this->assertNull($dependency->getCalls()); $this->assertNull($dependency->getConstructorArguments()); $argument = new DependencyCallArgument(); $call->addArgument($argument); $dependency->addCall($call); $expected = array($argument); $this->assertNull($dependency->getCalls()); $this->assertEquals($expected, $dependency->getConstructorArguments()); }
/** * 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; }