예제 #1
0
 /**
  * testPopulate
  *
  * @covers \RcmUser\Acl\Entity\AclRole::populate
  *
  * @return void
  */
 public function testPopulate()
 {
     $aclRole = new AclRole();
     $parentAclRole = new AclRole();
     $parentAclRole->setRoleId('ppp');
     $aclRoleA = ['roleId' => 'arrayrolea', 'parentRoleId' => 'ppp', 'description' => 'arrayRoleA', 'parentRole' => $parentAclRole];
     $aclRoleB = new AclRole();
     $parentAclRoleB = new AclRole();
     $parentAclRoleB->setRoleId('pppb');
     $aclRoleB->setRoleId('roleb');
     $aclRoleB->setParentRoleId('pppb');
     $aclRoleB->setDescription('roleb');
     $aclRoleB->setParentRole($parentAclRoleB);
     $aclRoleC = 'wrong format';
     $aclRole->populate($aclRoleA);
     $this->assertTrue($aclRole->getRoleId() === 'arrayrolea', 'Setter or getter failed.');
     $aclRole->populate($aclRoleB);
     $this->assertTrue($aclRole->getRoleId() === 'roleb', 'Setter or getter failed.');
     try {
         $aclRole->populate($aclRoleC);
     } catch (RcmUserException $e) {
         $this->assertInstanceOf('\\RcmUser\\Exception\\RcmUserException', $e);
         return;
     }
     $this->fail("Expected exception not thrown");
 }
예제 #2
0
파일: AclRole.php 프로젝트: reliv/rcm-user
 /**
  * populate
  *
  * @param array|AclRole $data data to populate with
  *
  * @return void
  * @throws RcmUserException
  */
 public function populate($data = [])
 {
     if ($data instanceof AclRole) {
         $this->setRoleId($data->getRoleId());
         $this->setDescription($data->getDescription());
         $this->setParentRoleId($data->getParentRoleId());
         $parentRole = $data->getParentRole();
         if (!empty($parentRole)) {
             $this->setParentRole($parentRole);
         }
         return;
     }
     if (is_array($data)) {
         if (isset($data['roleId'])) {
             $this->setRoleId($data['roleId']);
         }
         if (isset($data['description'])) {
             $this->setDescription($data['description']);
         }
         if (isset($data['parentRoleId'])) {
             $this->setParentRoleId($data['parentRoleId']);
         }
         if (isset($data['parentRole'])) {
             $this->setParentRoleId($data['parentRole']);
         }
         return;
     }
     throw new RcmUserException('Role data could not be populated, data format not supported');
 }
예제 #3
0
 /**
  * createNamespaceId
  *
  * @param AclRole $role     acl role
  * @param array   $aclRoles array of roles
  *
  * @return string
  */
 public function createNamespaceId(AclRole $role, $aclRoles)
 {
     $parentRoleId = $role->getParentRoleId();
     $ns = $role->getRoleId();
     if (!empty($parentRoleId)) {
         $parent = $aclRoles[$parentRoleId];
         $newns = $this->createNamespaceId($parent, $aclRoles, $ns);
         $ns = $newns . '.' . $ns;
     }
     return $ns;
 }
예제 #4
0
 /**
  * createRoleNamespaceId
  *
  * @param AclRole $aclRole  aclRole
  * @param array   $aclRoles aclRoles
  * @param string  $nsChar   nsChar
  *
  * @return string
  */
 public function createRoleNamespaceId(AclRole $aclRole, $aclRoles, $nsChar = '.')
 {
     $parentId = $aclRole->getParentRoleId();
     $ns = $aclRole->getRoleId();
     if (!empty($parentId)) {
         $parent = $aclRoles[$parentId];
         $newns = $this->createRoleNamespaceId($parent, $aclRoles, $nsChar);
         $ns = $newns . $nsChar . $ns;
     }
     return $ns;
 }