本文整理匯總了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();
}
示例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);
}
示例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'));
}
示例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();
}
}
}