AbstractFactory : createServiceWithName even if canCreateServiceWithName return false #2593

Closed
zfbot opened this Issue Sep 28, 2012 · 2 comments

Projects

None yet

3 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-567
Issue Type:Bug
Reporter:Frederic Bouchery
Created:09/18/12
Assignee:weierophinney
Components:Zend\ServiceManager

Description

This code echos "create the wrong one" instead of "create the good one" :

<?php
class Af1 implements \Zend\ServiceManager\AbstractFactoryInterface
{
    public function canCreateServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        return true;
    }

    public function createServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        echo "create the good one";
        return new stdClass();
    }
}

class Af2 implements \Zend\ServiceManager\AbstractFactoryInterface
{
    public function canCreateServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        return false;
    }

    public function createServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        echo "create the wrong one";
        return new stdClass();
    }
}

$sm = new \Zend\ServiceManager\ServiceManager();
$sm->addAbstractFactory('Af1');
$sm->addAbstractFactory('Af2');

$sm->get('test');
?>```
If I switch both "addAbstractFactory", it work fine.

zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-567

Known GitHub users mentioned in the original message or comment:
@weierophinney

Member

Invalid, see #3003.

@Maks3w Maks3w closed this Nov 18, 2012
@Ocramius Ocramius added a commit to Ocramius/zf2 that referenced this issue Nov 18, 2012
@Ocramius Ocramius Adding tests for zendframework/zendframework#2593 3439512
@weierophinney weierophinney added a commit that referenced this issue Nov 19, 2012
@weierophinney weierophinney Merge branch 'hotfix/3003'
Close #3003
Fix #2593
3d3fbd3
@weierophinney weierophinney added a commit to zendframework/zend-servicemanager that referenced this issue May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/3003' dbd9ca8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment