コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 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')));
 }