當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Role::getNewInstance方法代碼示例

本文整理匯總了PHP中Role::getNewInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Role::getNewInstance方法的具體用法?PHP Role::getNewInstance怎麽用?PHP Role::getNewInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Role的用法示例。


在下文中一共展示了Role::getNewInstance方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 public function setUp()
 {
     parent::setUp();
     $this->role = Role::getNewInstance('__testrole__');
     $this->role->save();
     $this->userGroup = UserGroup::getNewInstance('Any random group name');
     $this->userGroup->save();
 }
開發者ID:saiber,項目名稱:livecart,代碼行數:8,代碼來源:AccessControlAssociationTest.php

示例2: testGetRoleByName

 public function testGetRoleByName()
 {
     $newRole = Role::getNewInstance('testing');
     $newRole->save();
     $role = Role::getInstanceByName('testing');
     $this->assertSame($role, $newRole);
     $role = Role::getInstanceByName('unknown');
     $this->assertNull($role, null);
 }
開發者ID:saiber,項目名稱:livecart,代碼行數:9,代碼來源:RoleTest.php

示例3: testHasConcreteAccess

 public function testHasConcreteAccess()
 {
     $group = UserGroup::getNewInstance('testing1337', 'testing1337');
     $group->save();
     $role = Role::getNewInstance('testing1337.update');
     $role->save();
     $group->applyRole($role);
     $group->save();
     $this->assertFalse($group->hasAccess('testing1337'));
     $this->assertTrue($group->hasAccess('testing1337.update'));
     $this->assertFalse($group->hasAccess('testing1337.create'));
 }
開發者ID:saiber,項目名稱:livecart,代碼行數:12,代碼來源:UserGroupTest.php

示例4: addNewRolesNames

 public static function addNewRolesNames($roleNames, $deleteOther = false)
 {
     // unset meta- roles
     if ($i = array_search('login', $roleNames)) {
         unset($roleNames[$i]);
     }
     if (!is_array($roleNames) || empty($roleNames)) {
         return;
     }
     $filter = new ARSelectFilter();
     $deleteFilter = new ARDeleteFilter();
     $condition = new EqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleNames[0]);
     $deleteCondition = new NotEqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleNames[0]);
     foreach ($roleNames as $roleName) {
         $condition->addOR(new EqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleName));
         $deleteCondition->addAnd(new NotEqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleName));
     }
     $filter->setCondition($condition);
     $deleteFilter->setCondition($deleteCondition);
     if ($deleteOther) {
         self::deleteRecordSet(__CLASS__, $deleteFilter);
     }
     // Find new roles
     $invertedRoleNames = array_flip($roleNames);
     foreach (self::getRecordSet($filter) as $role) {
         if (isset($invertedRoleNames[$role->name->get()])) {
             unset($invertedRoleNames[$role->name->get()]);
         }
     }
     // Add new roles to database
     foreach ($invertedRoleNames as $role => $value) {
         if (!empty($role)) {
             $newRole = Role::getNewInstance($role);
             $newRole->save();
         }
     }
 }
開發者ID:saiber,項目名稱:livecart,代碼行數:37,代碼來源:Role.php


注:本文中的Role::getNewInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。