Undefined method "->getServiceLocator()" in IdentityFactory #4464

Closed
dragonprojects opened this Issue May 13, 2013 · 5 comments

Projects

None yet

4 participants

@dragonprojects

In "Zend\Mvc\Controller\Plugin\Service\IdentityFactory" is following Line:

$services = $serviceLocator->getServiceLocator();

But the $serviceLocator has no method "getServiceLocator", the object is the service locator.

So this implementation would be correct:

public function createService(ServiceLocatorInterface $serviceLocator)
{
    $helper = new Identity();
    if ($serviceLocator->has('Zend\Authentication\AuthenticationService')) {
        $helper->setAuthenticationService($serviceLocator->get('Zend\Authentication\AuthenticationService'));
    }
    return $helper;
}
@Ocramius
Zend Framework member

That won't work. The problem here is that $serviceLocator is an instance of Zend\ServiceManager\AbstractPluginManager. That's a common problem of ZF2 right now, and it's not just happening in this factory.

@dragonprojects

Then check the given variable can be a solution, or?

if ($serviceLocator instanceof ServiceLocatorAwareInterface) {
    $serviceLocator = $serviceLocator->getServiceLocator();
}

In my case $serviceLocator is a object of service manager. Did i do something wrong?
Have only add the identity factory into the service manager config:

'service_manager' => array(
    'factories' => array(
        'Identity' => 'Zend\Mvc\Controller\Plugin\Service\IdentityFactory',
    ),
),
@Ocramius
Zend Framework member

That's surely a good idea to have some type hinting and avoid this typical question. Anyway, this plugin's factory can be used only in a plugin manager right now.

@ThaDafinser

@dragonprojects @Ocramius is this now a question or a suggestion?

When it's a question -> can this get closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment