Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 55895a5

Browse files
kynxOcramius
authored andcommitted
Fixed creationContext not being passed to abstract factory canCreate()
1 parent 8fc7cff commit 55895a5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/ServiceManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function has($name)
236236

237237
// Check abstract factories
238238
foreach ($this->abstractFactories as $abstractFactory) {
239-
if ($abstractFactory->canCreate($this, $name)) {
239+
if ($abstractFactory->canCreate($this->creationContext, $name)) {
240240
return true;
241241
}
242242
}
@@ -605,7 +605,7 @@ private function getFactory($name)
605605

606606
// Check abstract factories
607607
foreach ($this->abstractFactories as $abstractFactory) {
608-
if ($abstractFactory->canCreate($this, $name)) {
608+
if ($abstractFactory->canCreate($this->creationContext, $name)) {
609609
return $abstractFactory;
610610
}
611611
}

test/AbstractPluginManagerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Zend\ServiceManager\Exception\InvalidArgumentException;
1717
use Zend\ServiceManager\Exception\InvalidServiceException;
1818
use Zend\ServiceManager\Exception\ServiceNotFoundException;
19+
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
1920
use Zend\ServiceManager\Factory\FactoryInterface;
2021
use Zend\ServiceManager\Factory\InvokableFactory;
2122
use Zend\ServiceManager\ServiceManager;
@@ -349,4 +350,17 @@ public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInv
349350
stdClass::class => new stdClass(),
350351
]]);
351352
}
353+
354+
public function testAbstractFactoryGetsCreationContext()
355+
{
356+
$serviceManager = new ServiceManager();
357+
$pluginManager = new TestAsset\SimplePluginManager($serviceManager);
358+
$abstractFactory = $this->prophesize(AbstractFactoryInterface::class);
359+
$abstractFactory->canCreate($serviceManager, 'foo')
360+
->willReturn(true);
361+
$abstractFactory->__invoke($serviceManager, 'foo', null)
362+
->willReturn(new InvokableObject());
363+
$pluginManager->addAbstractFactory($abstractFactory->reveal());
364+
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
365+
}
352366
}

0 commit comments

Comments
 (0)