/** * Injects everything into the passed object/instance * * @param mixed $object instance * @param string $containerName the container that holds the maps/dependencies */ public static function inject($object, $containerName = 'main') { $injector = new self(); $injector->setObject($object); $injector->setContainer(Pd_Container::get($containerName)); $injector->injectObject(); }
/** * Creates the object and sets all the dependencies required * for construction. * * @param string $className * @param string $containerName * @return mixed object */ public static function construct($className, $containerName = 'main') { $constructor = new self(); $constructor->setClassName($className); $constructor->setContainer(Pd_Container::get($containerName)); $constructor->constructObject(); return $constructor->object(); }
protected function setUp() { $this->containerName = 'PdTests_MakeTests_MakeTest'; $this->className = 'PdTests_stubs_Dummy'; $container = Pd_Container::get($this->containerName); $container->dependencies()->set('Force', 'a forced var'); $container->dependencies()->set('Pear', 'a fruit'); $container->dependencies()->set('Apple', 'red!!!'); $this->object = Pd_Make::name($this->className, $this->containerName); }
public function testBuildByReadingClassForMap() { $containerName = $this->containerName . '_testingReadClass'; $container = Pd_Container::get($containerName); $container->maps()->set($this->className, null); $container->dependencies()->set('Apple', 'color:red'); $container->dependencies()->set('Banana', 'color:yellow'); $this->builder->setContainer($container); $this->builder->constructObject(); $object = $this->builder->object(); $this->assertEquals('color:yellow', $object->getConstructorArg()); }
protected function setUp() { $this->containerName = 'PdTests_MakeTests_InjectorTest'; $this->className = 'PdTests_stubs_Dummy'; $container = Pd_Container::get($this->containerName); $container->dependencies()->set('Force', 'a forced var'); $container->dependencies()->set('Pear', 'a fruit'); $container->dependencies()->set('Apple', 'it is red'); $this->object = new PdTests_stubs_Dummy(); $this->injector = new Pd_Make_Setter(); $this->injector->setObject($this->object); $this->injector->setContainer($container); $this->injector->injectObject(); }
public function testNewSingleton() { $container = Pd_Container::get('newTest'); $this->assertEquals(null, $container->dependencies()->get('someValue')); }