Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

[BUG] Service Manager Not Shared Duplicate new Instance with multiple Abstract Factories #3237

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/Zend/ServiceManager/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,8 @@ protected function createFromAbstractFactory($canonicalName, $requestedName)
));
}
try {
$this->pendingAbstractFactoryRequests[get_class($abstractFactory)] = $requestedName;
if ($abstractFactory->canCreateServiceWithName($this, $canonicalName, $requestedName)) {
$this->pendingAbstractFactoryRequests[get_class($abstractFactory)] = $requestedName;
$instance = $this->createServiceViaCallback(
array($abstractFactory, 'createServiceWithName'),
$canonicalName,
Expand Down
13 changes: 13 additions & 0 deletions tests/ZendTest/ServiceManager/ServiceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,17 @@ public function testCanGetAliasedServicesFromPeeringServiceManagers()

$this->assertSame($service, $this->serviceManager->get('alias-name'));
}

/**
* @covers Zend\ServiceManager\ServiceManager::get
*/
public function testDuplicateNewInstanceMultipleAbstractFactories()
{
$this->serviceManager->setAllowOverride(true);
$this->serviceManager->setShareByDefault(false);
$this->serviceManager->addAbstractFactory('ZendTest\ServiceManager\TestAsset\BarAbstractFactory');
$this->serviceManager->addAbstractFactory('ZendTest\ServiceManager\TestAsset\FooAbstractFactory');
$this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
$this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
}
}