Re: [BUG] Service Manager Not Shared Duplicate new Instance with multiple Abstract Factories

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [BUG] Service Manager Not Shared Duplicate new Instance with multiple Abstract Factories

Marco Pivetta
Heya,

Are you able to convert this to a PR with the failing test case attached?




On 17 December 2012 13:46, richard [via Zend Framework Community] <[hidden email]> wrote:
Example test:

class notSharedByDefault extends ServiceManager
{
    protected $shareByDefault = false;
}

public function testDuplicateNewInstanceMultipleAbstractFactories()
{
    $this->serviceManager = new notSharedByDefault();
    $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'));
}

The first instance of Bar is created. The second instance of Bar cannot be created. The FooAbstractFactory adds a $this->pendingAbstractFactoryRequests which then prevents canCreateFromAbstractFactory returning true where it should.

This appears to be due to lines <a href="tel:892%2F893" value="+39892893" target="_blank">892/893 in Zend\ServiceManager\ServiceManager:
$this->pendingAbstractFactoryRequests[get_class($abstractFactory)] = $requestedName;
if ($abstractFactory->canCreateServiceWithName($this, $canonicalName, $requestedName)) {

This also appears to be fixable by reversing the order of lines <a href="tel:892%2F893" value="+39892893" target="_blank">892/893 :
if ($abstractFactory->canCreateServiceWithName($this, $canonicalName, $requestedName)) {
    $this->pendingAbstractFactoryRequests[get_class($abstractFactory)] = $requestedName;


To start a new topic under Zend Framework, email [hidden email]
To unsubscribe from Zend Framework Community, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: [BUG] Service Manager Not Shared Duplicate new Instance with multiple Abstract Factories

richard
Hi,

I have posted a PR @ https://github.com/zendframework/zf2/pull/3237

regards