Commit 55a9cb1c authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Renommage "UnicaenAuth\Provider\Role\Db" en "UnicaenAuth\Provider\Role\DbRole".

parent 68a72222
......@@ -94,7 +94,7 @@ $bjyauthorize = array(
* NB: si le rôle par défaut 'guest' est fourni ici, il ne sera pas ajouté en double dans les ACL.
* NB: si la connexion à la base échoue, ce n'est pas bloquant!
*/
'UnicaenAuth\Provider\Role\Db' => array(
'UnicaenAuth\Provider\Role\DbRole' => array(
'object_manager' => 'doctrine.entitymanager.orm_default',
'role_entity_class' => 'UnicaenAuth\Entity\Db\Role',
),
......@@ -174,7 +174,7 @@ return array(
'UnicaenAuth\Provider\Identity\Ldap' => 'UnicaenAuth\Provider\Identity\LdapServiceFactory',
'UnicaenAuth\Provider\Identity\Db' => 'UnicaenAuth\Provider\Identity\DbServiceFactory',
'UnicaenAuth\Provider\Role\Config' => 'UnicaenAuth\Provider\Role\ConfigServiceFactory',
'UnicaenAuth\Provider\Role\Db' => 'UnicaenAuth\Provider\Role\DbServiceFactory',
'UnicaenAuth\Provider\Role\DbRole' => 'UnicaenAuth\Provider\Role\DbRoleServiceFactory',
),
),
'controllers' => array(
......
<?php
namespace UnicaenAuth\Provider\Role;
use Doctrine\DBAL\DBALException;
use PDOException;
use Zend\Permissions\Acl\Role\RoleInterface;
use UnicaenAuth\Acl\NamedRole;
use BjyAuthorize\Provider\Role\ObjectRepositoryProvider;
use BjyAuthorize\Acl\HierarchicalRoleInterface;
/**
* Role provider based on a {@see \Doctrine\Common\Persistence\ObjectRepository}
*/
class Db extends ObjectRepositoryProvider
{
/**
* {@inheritDoc}
*/
public function getRoles()
{
// try {
// $result = $this->objectRepository->findAll();
// }
// catch (PDOException $exc) {
// return array();
// }
//
// $roles = array();
//
// // Pass One: Build each object
// foreach ($result as $role) { /* @var $role \UnicaenAuth\Entity\Db\Role */
// if (!$role instanceof RoleInterface) {
// continue;
// }
//
// $roleId = $role->getRoleId();
// $parent = null;
//
// if ($role instanceof HierarchicalRoleInterface && $parent = $role->getParent()) {
// $parent = $parent->getRoleId();
// }
//
// $roles[$roleId] = new NamedRole($roleId, $parent, $role->getName());
// }
//
// // Pass Two: Re-inject parent objects to preserve hierarchy
// /* @var $roleObj NamedRole */
// foreach ($roles as $roleObj) {
// $parentRoleObj = $roleObj->getParent();
//
// if ($parentRoleObj && $parentRoleObj->getRoleId()) {
// $roleObj->setParent($roles[$parentRoleObj->getRoleId()]);
// }
// }
//
// return array_values($roles);
try {
$roles = parent::getRoles();
}
catch (DBALException $exc) {
$roles = array();
}
catch (PDOException $exc) {
$roles = array();
}
return $roles;
}
}
\ No newline at end of file
<?php
namespace UnicaenAuth\Provider\Role;
use Doctrine\DBAL\DBALException;
use PDOException;
use BjyAuthorize\Provider\Role\ObjectRepositoryProvider;
/**
* Role provider based on a {@see \Doctrine\Common\Persistence\ObjectRepository}
*/
class DbRole extends ObjectRepositoryProvider
{
/**
* {@inheritDoc}
*/
public function getRoles()
{
try {
$roles = parent::getRoles();
}
catch (DBALException $exc) {
$roles = array();
}
catch (PDOException $exc) {
$roles = array();
}
return $roles;
}
}
\ No newline at end of file
......@@ -7,26 +7,26 @@ use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Factory responsible of instantiating {@see \UnicaenAuth\Provider\Role\Db}
* Factory responsible of instantiating {@see \UnicaenAuth\Provider\Role\DbRole}
*/
class DbServiceFactory implements FactoryInterface
class DbRoleServiceFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*
* @return Db
* @return DbRole
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('BjyAuthorize\Config');
if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\Db'])) {
if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\DbRole'])) {
throw new InvalidArgumentException(
'Config for "UnicaenAuth\Provider\Role\Db" not set'
'Config for "UnicaenAuth\Provider\Role\DbRole" not set'
);
}
$providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\Db'];
$providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\DbRole'];
if (! isset($providerConfig['role_entity_class'])) {
throw new InvalidArgumentException('role_entity_class not set in the bjyauthorize role_providers config.');
......@@ -39,6 +39,6 @@ class DbServiceFactory implements FactoryInterface
/* @var $objectManager \Doctrine\Common\Persistence\ObjectManager */
$objectManager = $serviceLocator->get($providerConfig['object_manager']);
return new Db($objectManager->getRepository($providerConfig['role_entity_class']));
return new DbRole($objectManager->getRepository($providerConfig['role_entity_class']));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment