예제 #1
0
 /**
  * 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();
 }
예제 #2
0
 /**
  * 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();
 }
예제 #3
0
 /**
  * Finds the dependency, new class or pulls from container, based
  * on item.
  *
  * @param Pd_Map_Item $item
  * @return mixed dependency
  */
 protected function getDependencyForItem($item)
 {
     if ($item->newClass()) {
         $dependency = Pd_Make::name($item->newClass(), $this->_container->name());
     } else {
         $dependency = $this->_container->dependencies()->get($item->dependencyName());
     }
     return $dependency;
 }
예제 #4
0
 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);
 }
예제 #5
0
 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());
 }
예제 #6
0
 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();
 }
예제 #7
0
 public function testNewSingleton()
 {
     $container = Pd_Container::get('newTest');
     $this->assertEquals(null, $container->dependencies()->get('someValue'));
 }