本文整理汇总了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();
}
}
}