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

Cannot get a name and parameters for RoleProviderPluginManager #373

Closed
ashatrov opened this issue May 4, 2017 · 2 comments
Closed

Cannot get a name and parameters for RoleProviderPluginManager #373

ashatrov opened this issue May 4, 2017 · 2 comments

Comments

@ashatrov
Copy link
Contributor

ashatrov commented May 4, 2017

Hi! I have fatal error with PHP7.0.18 + ZF2.5.3 + ZF-Commons/zfc-rbac 2.6.2

Fatal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: ZfcRbac\Role\RoleProviderPluginManager::get was unable to fetch or create an instance for in /var/www/vhosts/pf-portal/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:555
Stack trace:
#0 /var/www/vhosts/pf-portal/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(161): Zend\ServiceManager\ServiceManager->get(NULL, true)
#1 /var/www/vhosts/pf-portal/vendor/zf-commons/zfc-rbac/src/ZfcRbac/Factory/RoleServiceFactory.php(60): Zend\ServiceManager\AbstractPluginManager->get(NULL, false)
#2 /var/www/vhosts/pf-portal/vendor/zf-commons/zfc-rbac/src/ZfcRbac/Factory/RoleServiceFactory.php(77): ZfcRbac\Factory\RoleServiceFactory->__invoke(Object(Zend\ServiceManager\ServiceManager), 'ZfcRbac\\Service...')
#3 [internal function]: ZfcRbac\Factory\RoleServiceFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'zfcrbacservicer...', 'ZfcRbac\\Service...')
#4 /var/www/vhosts/pf-portal/vendor/zendframework/zend-se in /var/www/vhosts/pf-portal/vendor/zendframework/zend-servicemanager/src/ServiceManager.php on line 555

The issue in \ZfcRbac\Factory\RoleServiceFactory

with this code:

$roleProvider = $pluginManager->get(key($roleProviderConfig), current($roleProviderConfig));

The internal pointer in array $roleProviderConfig is in the end of array, because of that key($roleProviderConfig) and current($roleProviderConfig) return null.

There is two options to fix it on place:

  1. Reset internal pointer in array to the beginning:
reset($roleProviderConfig);
$roleProvider = $pluginManager->get(key($roleProviderConfig), current($roleProviderConfig));
  1. Use different functions, which work without pointer.
$roleProvider = $pluginManager->get(array_keys($roleProviderConfig)[0], $roleProviderConfig[array_keys($roleProviderConfig)[0]]);

I think first is better and it is good practice to get first element of associative array.

@ashatrov
Copy link
Contributor Author

ashatrov commented May 4, 2017

My config looks like this:

'zfc_rbac' => [
    'role_provider' => [
        'ZfcRbac\Role\ObjectRepositoryRoleProvider' => [
            'object_manager' => 'doctrine.entitymanager.orm_default',
            'class_name' => 'Module\User\Entity\Role',
            'role_name_property' => 'name',
        ],
    ],
],

prolic added a commit that referenced this issue May 7, 2017
…eters_for_RoleProviderPluginManager

Cannot get a name and parameters for RoleProviderPluginManager #373
@ghost
Copy link

ghost commented May 7, 2017

Fix PR merged into master.
This issue is fixed.

@prolic prolic closed this as completed May 9, 2017
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

2 participants