当前位置: 首页>>代码示例>>PHP>>正文


PHP Acl::addrole方法代码示例

本文整理汇总了PHP中Zend\Permissions\Acl\Acl::addrole方法的典型用法代码示例。如果您正苦于以下问题:PHP Acl::addrole方法的具体用法?PHP Acl::addrole怎么用?PHP Acl::addrole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Permissions\Acl\Acl的用法示例。


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

示例1: getServiceConfig

 /**
  * Get service configuration.
  *
  * @return array Service configuration
  */
 public function getServiceConfig()
 {
     return ['aliases' => ['Zend\\Authentication\\AuthenticationService' => 'user_auth_service'], 'invokables' => ['user_auth_storage' => 'Zend\\Authentication\\Storage\\Session', 'user_service_user' => 'User\\Service\\User', 'user_service_apiuser' => 'User\\Service\\ApiUser', 'user_service_email' => 'User\\Service\\Email'], 'factories' => ['user_bcrypt' => function ($sm) {
         $bcrypt = new \Zend\Crypt\Password\Bcrypt();
         $config = $sm->get('config');
         $bcrypt->setCost($config['bcrypt_cost']);
         return $bcrypt;
     }, 'user_hydrator' => function ($sm) {
         return new \DoctrineModule\Stdlib\Hydrator\DoctrineObject($sm->get('user_doctrine_em'));
     }, 'user_form_activate' => function ($sm) {
         return new \User\Form\Activate($sm->get('translator'));
     }, 'user_form_register' => function ($sm) {
         return new \User\Form\Register($sm->get('translator'));
     }, 'user_form_login' => function ($sm) {
         return new \User\Form\Login($sm->get('translator'));
     }, 'user_form_password' => function ($sm) {
         return new \User\Form\Password($sm->get('translator'));
     }, 'user_form_passwordreset' => function ($sm) {
         return new \User\Form\Register($sm->get('translator'));
     }, 'user_form_passwordactivate' => function ($sm) {
         return new \User\Form\Activate($sm->get('translator'));
     }, 'user_form_apitoken' => function ($sm) {
         $form = new \User\Form\ApiToken($sm->get('translator'));
         $form->setHydrator($sm->get('user_hydrator'));
         return $form;
     }, 'user_mapper_user' => function ($sm) {
         return new \User\Mapper\User($sm->get('user_doctrine_em'));
     }, 'user_mapper_newuser' => function ($sm) {
         return new \User\Mapper\NewUser($sm->get('user_doctrine_em'));
     }, 'user_mapper_apiuser' => function ($sm) {
         return new \User\Mapper\ApiUser($sm->get('user_doctrine_em'));
     }, 'user_mail_transport' => function ($sm) {
         $config = $sm->get('config');
         $config = $config['email'];
         $class = '\\Zend\\Mail\\Transport\\' . $config['transport'];
         $optionsClass = '\\Zend\\Mail\\Transport\\' . $config['transport'] . 'Options';
         $transport = new $class();
         $transport->setOptions(new $optionsClass($config['options']));
         return $transport;
     }, 'user_auth_adapter' => function ($sm) {
         $adapter = new \User\Authentication\Adapter\Mapper($sm->get('user_bcrypt'), $sm->get('application_service_legacy'));
         $adapter->setMapper($sm->get('user_mapper_user'));
         return $adapter;
     }, 'user_pin_auth_adapter' => function ($sm) {
         $adapter = new \User\Authentication\Adapter\PinMapper($sm->get('application_service_legacy'));
         $adapter->setMapper($sm->get('user_mapper_user'));
         return $adapter;
     }, 'user_auth_service' => function ($sm) {
         return new \Zend\Authentication\AuthenticationService($sm->get('user_auth_storage'), $sm->get('user_auth_adapter'));
     }, 'user_pin_auth_service' => function ($sm) {
         return new \Zend\Authentication\AuthenticationService($sm->get('user_auth_storage'), $sm->get('user_pin_auth_adapter'));
     }, 'user_remoteaddress' => function ($sm) {
         $remote = new \Zend\Http\PhpEnvironment\RemoteAddress();
         return $remote->getIpAddress();
     }, 'user_role' => function ($sm) {
         $authService = $sm->get('user_auth_service');
         if ($authService->hasIdentity()) {
             return $authService->getIdentity();
         }
         $apiService = $sm->get('user_service_apiuser');
         if ($apiService->hasIdentity()) {
             return 'apiuser';
         }
         $range = $sm->get('config')['tue_range'];
         if (strpos($sm->get('user_remoteaddress'), $range) === 0) {
             return 'tueguest';
         }
         return 'guest';
     }, 'acl' => function ($sm) {
         // initialize the ACL
         $acl = new Acl();
         /**
          * Define all basic roles.
          *
          * - guest: everyone gets at least this access level
          * - tueguest: guest from the TU/e
          * - user: GEWIS-member
          * - apiuser: Automated tool given access by an admin
          * - admin: Defined administrators
          */
         $acl->addRole(new Role('guest'));
         $acl->addRole(new Role('tueguest'), 'guest');
         $acl->addRole(new Role('user'), 'tueguest');
         $acl->addrole(new Role('apiuser'), 'guest');
         $acl->addrole(new Role('sosuser'), 'apiuser');
         $acl->addrole(new Role('active_member'), 'user');
         $acl->addRole(new Role('admin'));
         $user = $sm->get('user_role');
         // add user to registry
         if ($user instanceof User) {
             $roles = $user->getRoleNames();
             // if the user has no roles, add the 'user' role by default
             if (empty($roles)) {
                 $roles = ['user'];
             }
//.........这里部分代码省略.........
开发者ID:wsinnema,项目名称:gewisweb,代码行数:101,代码来源:Module.php


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