• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Role类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Role的典型用法代码示例。如果您正苦于以下问题:PHP Role类的具体用法?PHP Role怎么用?PHP Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Role类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: setupFoundorAndBaseRolsPermission

 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = User::create(['github_id' => 324764, 'github_url' => 'https://github.com/summerblue', 'name' => 'summerblue']);
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageTopics = new Permission();
     $manageTopics->name = 'manage_topics';
     $manageTopics->display_name = 'Manage Topics';
     $manageTopics->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageTopics->id, $manageUsers->id]);
     $admin->perms()->sync([$manageTopics->id]);
 }
开发者ID:bobken,项目名称:phphub,代码行数:26,代码来源:2014_08_13_130603_entrust_setup_tables.php


示例2: run

 public function run()
 {
     DB::table('roles')->truncate();
     $faker = Faker\Factory::create();
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->save();
     $moderatorRole = new Role();
     $moderatorRole->name = 'moderator';
     $moderatorRole->save();
     $authorRole = new Role();
     $authorRole->name = 'author';
     $authorRole->save();
     $user = User::where('username', '=', 'ad_user')->first();
     $user->attachRole($adminRole);
     //        $user = User::where('username','=','ad_user1')->first();
     //        $user->attachRole( $adminRole );
     $m = User::where('username', '=', 'moderator')->first();
     $m->attachRole($moderatorRole);
     //        $m = User::where('username','=','mo_user1')->first();
     //        $m->attachRole($moderatorRole);
     $a = User::where('username', '=', 'author')->first();
     $a->attachRole($authorRole);
     //        $a  = User::where('username','=','au_user1')->first();
     //        $a->attachRole($authorRole);
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:26,代码来源:RolesTableSeeder.php


示例3: getMostApplyingRule

 /**
  * Returns the rule, that applies most to $role and $resource
  *
  * @param \gatekeeper\Role $role Role to search for
  * @param \gatekeeper\Resource $resource Resource to search for
  * @return \gatekeeper\Rule
  * @throws \gatekeeper\ThereIsNoApplyingRuleException if the is no applying
  *		rule
  */
 public function getMostApplyingRule(Role $role, Resource $resource)
 {
     do {
         $roleId = $role->getRoleId();
         foreach ($this->getRules() as $rule) {
             if ($rule->getRoleId() !== $roleId) {
                 continue;
             }
             $tmpResource = $resource;
             do {
                 /// Perhaps breadth first search?!
                 $resourceId = $tmpResource->getResourceId();
                 if ($rule->getResourceId() === $resourceId) {
                     return $rule;
                 }
                 try {
                     $tmpResource = $tmpResource->getParentResource();
                 } catch (HasNoParentResourceException $e) {
                     $tmpResource = null;
                 }
             } while ($tmpResource !== null);
         }
         try {
             $role = $role->getParentRole();
         } catch (HasNoParentRoleException $e) {
             $role = null;
         }
     } while ($role !== null);
     throw new ThereIsNoApplyingRuleException();
 }
开发者ID:heho,项目名称:gatekeeper,代码行数:39,代码来源:RuleRepository.php


示例4: run

 public function run()
 {
     $adminEmail = Config::get('madison.seeder.admin_email');
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $independent_sponsor = new Role();
     $independent_sponsor->name = 'Independent Sponsor';
     $independent_sponsor->save();
     $permIds = array();
     foreach ($this->adminPermissions as $permClass => $data) {
         $perm = new Permission();
         foreach ($data as $key => $val) {
             $perm->{$key} = $val;
         }
         $perm->save();
         $permIds[] = $perm->id;
     }
     $admin->perms()->sync($permIds);
     $user = User::where('email', '=', $adminEmail)->first();
     $user->attachRole($admin);
     $createDocPerm = new Permission();
     $createDocPerm->name = "independent_sponsor_create_doc";
     $createDocPerm->display_name = "Independent Sponsoring";
     $createDocPerm->save();
     $independent_sponsor->perms()->sync(array($createDocPerm->id));
 }
开发者ID:krues8dr,项目名称:madison,代码行数:27,代码来源:RbacSeeder.php


示例5: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if ($this->argument('name')) {
         $name = trim($this->argument('name'));
         $role = Role::where('name', '=', $name)->first();
         if ($role) {
             $this->info("Role '{$name}' already exists.");
             exit;
         }
         $role = new Role();
         $role->name = $name;
         $role->save();
         $this->info('Role saved successfully.');
     } else {
         $roles = Role::all();
         $this->info('Existing Roles:');
         foreach ($roles as $role) {
             $this->info($role->name);
         }
         $continue = $this->ask("Would you still like to add a new role? (yes/no)");
         if ('yes' === trim(strtolower($continue))) {
             $name = $this->ask("What's the new role's name?");
             $role = new Role();
             $role->name = trim($name);
             $role->save();
             $this->info('Role saved successfully.');
         }
     }
 }
开发者ID:krues8dr,项目名称:madison,代码行数:34,代码来源:CreateRole.php


示例6: setupDatabases

 public function setupDatabases()
 {
     $name = $this->call('migrate', array('--path' => 'app/database/migrations/setup/'));
     $name = $this->call('migrate');
     // create the roles
     $roles = ['Admin', 'Writer', 'Reader'];
     foreach ($roles as $r) {
         $role = Role::whereName($r)->first();
         if ($role == null) {
             $role = new Role();
             $role->name = $r;
             $role->display_name = $r;
             $role->save();
             $this->info("{$role->id} Creating Role:{$r}");
         }
     }
     foreach (User::all() as $u) {
         $this->info("{$u->id} : user: {$u->username}");
     }
     // add core assets
     $m = Asset::findFromTag('missing-user-image');
     if ($m == NULL) {
         $m = new Asset();
         $m->path = "assets/content/uploads";
         $m->saveLocalFile(public_path('assets/content/common/missing/profile-default.png'), 'profile-default.png');
         $m->tag = 'missing-user-image';
         $m->shared = 1;
         $m->type = Asset::ASSET_TYPE_IMAGE;
         $m->save();
     }
     $this->comment("****\tAll Databases for Halp have been setup :-) \t****");
     return;
 }
开发者ID:vanderlin,项目名称:halp,代码行数:33,代码来源:CreateDatabases.php


示例7: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //1.  Create Independent Sponsor role
     $sponsorRole = Role::where('name', '=', 'Independent Sponsor')->first();
     if (!$sponsorRole) {
         $sponsorRole = new Role();
         $sponsorRole->name = "Independent Sponsor";
         $sponsorRole->save();
         $this->info("Independent Sponsor role created.");
     } else {
         $this->info("Independent Sponsor role exists.");
     }
     //2. Add Independent Sponsor role to all Admins
     $adminRole = Role::where('name', 'Admin')->first();
     $admins = $adminRole->users()->get();
     foreach ($admins as $admin) {
         $this->info('--------------------------------------------------');
         if ($admin->hasRole($sponsorRole->name)) {
             $this->info($admin->email . " already set as Independent Sponsor");
         } else {
             $admin->attachRole($sponsorRole);
             $this->info($admin->email . " set as " . $sponsorRole->name);
         }
         //3.  Remove Admin role from non-admin users
         $stayAdmin = strtolower(trim($this->ask("Keep " . $admin->email . " as an Admin? (yes/no)")));
         if ($stayAdmin != 'yes') {
             $admin->detachRole($adminRole);
             $this->info("Removed Admin role from " . $admin->email);
         } else {
             $this->info($admin->email . " still set as an Admin.");
         }
     }
 }
开发者ID:DCgov,项目名称:dc-madison,代码行数:38,代码来源:dbUpdateGroups.php


示例8: become

 /**
  * Become a given role.
  */
 function become($args)
 {
     parent::validate(true, true);
     $user =& Request::getUser();
     if (!$user) {
         Request::redirect(null, null, 'index');
     }
     switch (array_shift($args)) {
         case 'submitter':
             $roleId = ROLE_ID_SUBMITTER;
             $setting = 'enableSubmit';
             $deniedKey = 'user.noRoles.enableSubmitClosed';
             break;
         default:
             Request::redirect('index');
     }
     $site =& Request::getSite();
     if ($site->getSetting($setting)) {
         $role = new Role();
         $role->setRoleId($roleId);
         $role->setUserId($user->getId());
         $roleDao =& DAORegistry::getDAO('RoleDAO');
         $roleDao->insertRole($role);
         Request::redirectUrl(Request::getUserVar('source'));
     } else {
         $templateMgr =& TemplateManager::getManager();
         $templateMgr->assign('message', $deniedKey);
         return $templateMgr->display('common/message.tpl');
     }
 }
开发者ID:jalperin,项目名称:harvester,代码行数:33,代码来源:UserHandler.inc.php


示例9: run

 public function run()
 {
     // create default user asset
     $asset = Asset::where('filename', '=', 'default.png')->first();
     if ($asset == NULL) {
         $asset = new Asset();
         $asset->filename = 'default.png';
         $asset->path = 'assets/content/users';
         $asset->save();
     }
     $admin = Role::where('name', '=', 'Admin')->first();
     // create default roles
     if ($admin == NULL) {
         $admin = new Role();
         $admin->name = 'Admin';
         $admin->save();
     }
     $adminUser = User::where('username', '=', 'admin')->first();
     if ($adminUser != NULL) {
         echo "Admin User Already Exsit";
     } else {
         $adminUser = new User();
         $adminUser->username = 'admin';
         $adminUser->email = '[email protected]';
         $adminUser->password = 'admin';
         $adminUser->password_confirmation = 'admin';
         $adminUser->confirmation_code = md5(uniqid(mt_rand(), true));
         if ($adminUser->save()) {
             $adminUser->attachRole($admin);
             echo "Admin User Created";
         }
     }
 }
开发者ID:vanderlin,项目名称:Gear2,代码行数:33,代码来源:UserTableSeeder.php


示例10: run

 public function run()
 {
     if (file_exists(app_path() . '/config/creds.yml')) {
         $creds = yaml_parse_file(app_path() . '/config/creds.yml');
     } else {
         $creds = array('admin_email' => '[email protected]');
     }
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $independent_sponsor = new Role();
     $independent_sponsor->name = 'Independent Sponsor';
     $independent_sponsor->save();
     $permIds = array();
     foreach ($this->adminPermissions as $permClass => $data) {
         $perm = new Permission();
         foreach ($data as $key => $val) {
             $perm->{$key} = $val;
         }
         $perm->save();
         $permIds[] = $perm->id;
     }
     $admin->perms()->sync($permIds);
     $user = User::where('email', '=', $creds['admin_email'])->first();
     $user->attachRole($admin);
     $createDocPerm = new Permission();
     $createDocPerm->name = "independent_sponsor_create_doc";
     $createDocPerm->display_name = "Independent Sponsoring";
     $createDocPerm->save();
     $independent_sponsor->perms()->sync(array($createDocPerm->id));
 }
开发者ID:iaincollins,项目名称:madison,代码行数:31,代码来源:RbacSeeder.php


示例11: setupFoundorAndBaseRolsPermission

 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = User::create(['id' => 1, 'username' => 'zhanglei', 'password' => Hash::make('zhanglei'), 'email' => '[email protected]']);
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageTopics = new Permission();
     $manageTopics->name = 'manage_topics';
     $manageTopics->display_name = 'Manage Topics';
     $manageTopics->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageTopics->id, $manageUsers->id]);
     $admin->perms()->sync([$manageTopics->id]);
 }
开发者ID:xiao-hu00,项目名称:phphub,代码行数:26,代码来源:2014_08_13_130603_entrust_setup_tables.php


示例12: run

 public function run()
 {
     /**
      *  $userModel = User::find(1);
      *  $userModel->detachRoles($userModel->roles);
      */
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('roles')->truncate();
     DB::table('roles')->delete();
     DB::table('assigned_roles')->truncate();
     DB::table('assigned_roles')->delete();
     DB::table('users')->truncate();
     DB::table('users')->delete();
     User::create(array('firstname' => 'Администратор', 'email' => '[email protected]', 'password' => Hash::make('123456')));
     User::create(array('firstname' => 'Богдан', 'email' => '[email protected]', 'password' => Hash::make('123456')));
     $role = new Role();
     $role->name = 'Customer';
     $role->save();
     $role = new Role();
     $role->name = 'Admin';
     $role->save();
     $admin = User::where('firstname', '=', 'Администратор')->first();
     $admin->attachRole($role);
     $user = User::where('firstname', '=', 'Богдан')->first();
     $user->attachRole($role);
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
开发者ID:Rotron,项目名称:shop,代码行数:27,代码来源:UserTableSeeder.php


示例13: OnPageLoad

    function OnPageLoad()
    {
        if (is_object($this->data_object)) {
            echo new XhtmlElement('h1', Html::Encode('Delete role: ' . $this->data_object->getRoleName()));
        } else {
            echo new XhtmlElement('h1', 'Delete role');
            $this->deleted = true;
        }
        if ($this->deleted) {
            ?>
			<p>The role has been deleted.</p>
			<p><a href="roles.php">View all roles</a></p>
			<?php 
        } else {
            ?>
				<p>Deleting a role cannot be undone.</p>
				<p>Are you sure you want to delete this role?</p>
				<form method="post" class="deleteButtons">
				<div>
				<input type="submit" value="Delete role" name="delete" />
				<input type="submit" value="Cancel" name="cancel" />
				</div>
				</form>
				<?php 
            $this->AddSeparator();
            require_once 'stoolball/user-edit-panel.class.php';
            $panel = new UserEditPanel($this->GetSettings(), 'this role');
            $panel->AddLink('edit this role', "role.php?item=" . $this->data_object->getRoleId());
            echo $panel;
        }
    }
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:31,代码来源:roledelete.php


示例14: display

 public function display()
 {
     $rolelist = new Template();
     $rolelist->load("role_list");
     $actions = ActionList::get("rolelist");
     if (isset($_POST['insert'])) {
         $role = new Role();
         $role->name = $_POST['insert'];
         $role->insert();
     }
     if (isset($_GET['delete'])) {
         $role = new Role();
         $role->ID = $_GET['delete'];
         $role->delete();
     }
     $table = new Table();
     $id = new TableColumn("id", Language::DirectTranslate("ID"));
     $id->autoWidth = true;
     $name = new TableColumn("name", Language::DirectTranslate("NAME"));
     $table->columns->add($id);
     $table->columns->add($name);
     $table->name = "{'dbprefix'}roles";
     $table->actions = "rolelist";
     $table->orderBy = "name";
     $table->cacheName = "rolelist";
     $rolelist->assign_var("TABLE", $table->getCode());
     $rolelist->output();
 }
开发者ID:srueegger,项目名称:1zu12bB,代码行数:28,代码来源:rolelist.php


示例15: run

 public function run()
 {
     $user = new User();
     $user->email = '[email protected]';
     $user->username = 'danny-admin';
     $user->password = Hash::make('secret');
     $user->password_confirmation = $user->password;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->email . '" <' . $user->email . '>');
     }
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $user = new User();
     $user->email = '[email protected]';
     $user->username = 'ivan-admin';
     $user->password = Hash::make('secret');
     $user->password_confirmation = $user->password;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->email . '" <' . $user->email . '>');
     }
     $user = User::where('username', $user->username)->firstOrFail();
     $user->attachRole($admin);
 }
开发者ID:VerticalHorizon,项目名称:Bumagi,代码行数:32,代码来源:UsersTableSeeder.php


示例16: run

 public function run()
 {
     //DB::table('roles')->delete();
     DB::statement('ALTER TABLE permissions AUTO_INCREMENT = 1');
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->save();
     $user = User::where('username', '=', 'admin')->first();
     $user->attachRole($adminRole);
     $BrokerRole = new Role();
     $BrokerRole->name = 'broker';
     $BrokerRole->save();
     $user = User::where('username', '=', 'broker')->first();
     $user->attachRole($BrokerRole);
     $campusRole = new Role();
     $campusRole->name = 'campus';
     $campusRole->save();
     $user = User::where('username', '=', 'campus')->first();
     $user->attachRole($campusRole);
     $communityRole = new Role();
     $communityRole->name = 'community';
     $communityRole->save();
     $user = User::where('username', '=', 'community')->first();
     $user->attachRole($communityRole);
 }
开发者ID:bktz,项目名称:cup,代码行数:25,代码来源:RolesTableSeeder.php


示例17: run

 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     // DB::table('departments')->truncate();
     //    $department = new Department;
     //    $department->department_desc = 'ADMIN';
     //    $department->save();
     DB::table('roles')->truncate();
     $role = new Role();
     $role->name = 'ADMINISTRATOR';
     $role->save();
     DB::table('users')->truncate();
     DB::table('assigned_roles')->truncate();
     $user = new User();
     $user->username = 'admin';
     $user->email = '[email protected]';
     $user->password = '031988';
     $user->password_confirmation = '031988';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     // $user->confirmed = 1;
     // $user->active = 1;
     // $user->department_id = $department->id;
     $user->save();
     $user->roles()->attach($role->id);
     // id only
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
开发者ID:jcyanga28,项目名称:project-reference,代码行数:27,代码来源:UserTableSeeder.php


示例18: run

 public function run()
 {
     $user = new User();
     $user->username = '[email protected]';
     $user->email = '[email protected]';
     $user->password = '@Password1';
     $user->password_confirmation = '@Password1';
     $user->confirmed = 1;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->save();
     $profile = new Profile();
     $profile->user_id = $user->id;
     $profile->firstname = 'David';
     $profile->lastname = 'Hernandez';
     $profile->mobile = '(916)952-5736';
     $profile->dob = '09/24/1986';
     $profile->avatar = '/img/coach-avatar.jpg';
     $profile->save();
     if (!$user->id) {
         Log::info('Unable to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
     }
     $user1 = new User();
     $user1->username = '[email protected]';
     $user1->email = '[email protected]';
     $user1->password = '@Password1';
     $user1->password_confirmation = '@Password1';
     $user1->confirmed = 1;
     $user1->confirmation_code = md5(uniqid(mt_rand(), true));
     $user1->save();
     $profile1 = new Profile();
     $profile1->user_id = $user1->id;
     $profile1->firstname = 'David';
     $profile1->lastname = 'Hernandez';
     $profile1->mobile = '(916)952-5736';
     $profile->dob = '09/24/1986';
     $profile1->avatar = '/img/coach-avatar.jpg';
     $profile1->save();
     if (!$user1->id) {
         Log::info('Unable to create user ' . $user1->username, (array) $user1->errors());
     } else {
         Log::info('Created user "' . $user1->username . '" <' . $user1->email . '>');
     }
     $admin = new Role();
     $admin->name = 'administrator';
     $admin->save();
     $club = new Role();
     $club->name = 'club owner';
     $club->save();
     $club2 = new Role();
     $club2->name = 'club administrator';
     $club2->save();
     $default = new Role();
     $default->name = 'default';
     $default->save();
     $user->attachRole($club);
     $user1->attachRole($default);
 }
开发者ID:illuminate3,项目名称:league-production,代码行数:59,代码来源:UsersTableSeeder.php


示例19: OnPrePageLoad

 function OnPrePageLoad()
 {
     if (is_object($this->role)) {
         $this->SetPageTitle($this->role->getRoleName() . ': Edit role');
     } else {
         $this->SetPageTitle('New role');
     }
 }
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:8,代码来源:role.php


示例20: testGetParent

 public function testGetParent()
 {
     $parent = new Role('user');
     $role = new Role('admin', $parent);
     $this->assertSame($parent, $role->getParent());
     $anotherRole = new Role('root');
     $this->assertNull($anotherRole->getParent());
 }
开发者ID:hbarcelos,项目名称:spice-acl,代码行数:8,代码来源:RoleTest.php



注:本文中的Role类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP RoleModel类代码示例发布时间:2022-05-23
下一篇:
PHP RokCommon_Service类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap