public function testDIMultiInstance() { $key1 = 'hello'; $value1 = new \stdClass(); $key2 = 'Night'; $value2 = new \stdClass(); //register key1 in first instance, key2 in second instance $this->ray->set($key1, $value1); $ray = new RayContainer(new Forge(new Config())); $ray->set($key2, $value2); $adapter = new RayAdapter($ray); $this->container->provider($adapter); $this->assertEquals($value1, $this->container->get($key1)); $this->assertEquals($value2, $this->container->get($key2)); }
/** * Get instance with container * * @param string $in Scope::SINGLETON | Scope::PROTOTYPE * @param string $bindingToType AbstractModule::TO_CLASS | AbstractModule::TO_PROVIDER ... * @param mixed $target target interface or class * * @return mixed */ public function getInstanceWithContainer($in, $bindingToType, $target) { if ($in === Scope::SINGLETON && $this->container->has($target)) { $instance = $this->container->get($target); return $instance; } $isToClassBinding = $bindingToType === AbstractModule::TO_CLASS; $instance = $isToClassBinding ? $this->injector->getInstance($target) : $this->getProvidedInstance($target); if ($in === Scope::SINGLETON) { $this->container->set($target, $instance); } return $instance; }