/** * Get shared instance * * @param $classOrAlias * @return mixed */ public function getSharedInstance($classOrAlias) { if ($this->serviceLocator->has($classOrAlias)) { return $this->serviceLocator->get($classOrAlias); } return $this->diInstanceManager->getSharedInstance($classOrAlias); }
/** * Get shared instance * * @param $classOrAlias * @return mixed */ public function getSharedInstance($classOrAlias) { if ($this->container->has($classOrAlias)) { return $this->container->get($classOrAlias); } return $this->diInstanceManager->getSharedInstance($classOrAlias); }
public function testInstanceManagerCanPersistInstancesWithParameters() { $im = new InstanceManager(); $obj1 = new TestAsset\BasicClass(); $obj2 = new TestAsset\BasicClass(); $obj3 = new TestAsset\BasicClass(); $im->addSharedInstance($obj1, 'foo'); $im->addSharedInstanceWithParameters($obj2, 'foo', array('foo' => 'bar')); $im->addSharedInstanceWithParameters($obj3, 'foo', array('foo' => 'baz')); $this->assertSame($obj1, $im->getSharedInstance('foo')); $this->assertSame($obj2, $im->getSharedInstanceWithParameters('foo', array('foo' => 'bar'))); $this->assertSame($obj3, $im->getSharedInstanceWithParameters('foo', array('foo' => 'baz'))); }