Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

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

Closed
Sharaal opened this issue May 13, 2013 · 5 comments
Closed

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

Sharaal opened this issue May 13, 2013 · 5 comments

Comments

@Sharaal
Copy link

Sharaal commented May 13, 2013

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
Copy link
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.

@Sharaal
Copy link
Author

Sharaal commented May 13, 2013

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
Copy link
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
Copy link
Contributor

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

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

@ThaDafinser
Copy link
Contributor

ping @dragonprojects

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants