Issues

ZF2-567: AbstractFactory : createServiceWithName even if canCreateServiceWithName return false

Issue Type: Bug Created: 2012-09-18T09:48:46.000+0000 Last Updated: 2012-10-08T20:12:23.000+0000 Status: Closed Fix version(s): Reporter: Frederic Bouchery (bouchery) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\ServiceManager

Related issues: Attachments:

Description

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

<pre class="highlight"> 
<?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.

Comments

Posted by Ralph Schindler (ralph) on 2012-10-08T20:12:23.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2593

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts