Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'hotfix/3348' into develop

Forward port #3423
  • Loading branch information...
commit 524e5b3cd2d29f7df95267851b590e507b1c3f05 2 parents ed0fc53 + ac29623
@weierophinney weierophinney authored
View
13 library/Zend/ServiceManager/ServiceManager.php
@@ -419,16 +419,21 @@ public function get($name, $usePeeringServiceManagers = true)
} while ($this->hasAlias($cName));
}
- if (isset($this->instances[$cName])) {
- return $this->instances[$cName];
- }
-
$instance = null;
$retrieveFromPeeringManagerFirst = $this->retrieveFromPeeringManagerFirst();
if ($usePeeringServiceManagers && $retrieveFromPeeringManagerFirst) {
$instance = $this->retrieveFromPeeringManager($name);
+
+ if(null !== $instance) {
+ return $instance;
+ }
}
+
+ if (isset($this->instances[$cName])) {
+ return $this->instances[$cName];
+ }
+
if (!$instance) {
if ($this->canCreate(array($cName, $name))) {
$instance = $this->create(array($cName, $name));
View
32 tests/ZendTest/ServiceManager/ServiceManagerTest.php
@@ -667,4 +667,36 @@ public function testDuplicateNewInstanceMultipleAbstractFactories()
$this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
$this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
}
+
+ /**
+ * @covers Zend\ServiceManager\ServiceManager::setService
+ * @covers Zend\ServiceManager\ServiceManager::get
+ * @covers Zend\ServiceManager\ServiceManager::retrieveFromPeeringManagerFirst
+ * @covers Zend\ServiceManager\ServiceManager::setRetrieveFromPeeringManagerFirst
+ * @covers Zend\ServiceManager\ServiceManager::addPeeringServiceManager
+ */
+ public function testRetrieveServiceFromPeeringServiceManagerIfretrieveFromPeeringManagerFirstSetToTrueAndServiceNamesAreSame()
+ {
+ $foo1 = "foo1";
+ $boo1 = "boo1";
+ $boo2 = "boo2";
+
+ $this->serviceManager->setService($foo1, $boo1);
+ $this->assertEquals($this->serviceManager->get($foo1), $boo1);
+
+ $serviceManagerChild = new ServiceManager();
+ $serviceManagerChild->setService($foo1, $boo2);
+ $this->assertEquals($serviceManagerChild->get($foo1), $boo2);
+
+ $this->assertFalse($this->serviceManager->retrieveFromPeeringManagerFirst());
+ $this->serviceManager->setRetrieveFromPeeringManagerFirst(true);
+ $this->assertTrue($this->serviceManager->retrieveFromPeeringManagerFirst());
+
+ $this->serviceManager->addPeeringServiceManager($serviceManagerChild);
+
+ $this->assertContains($serviceManagerChild, $this->readAttribute($this->serviceManager, 'peeringServiceManagers'));
+
+ $this->assertEquals($serviceManagerChild->get($foo1), $boo2);
+ $this->assertEquals($this->serviceManager->get($foo1), $boo2);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.