简体   繁体   中英

Check if a role is granted using a regular expression in Symfony2?

My roles are something like SEND_SMS_100 , SEND_SMS_200 or more in general SEND_SMS_X where X is an integer. It's the maximum number of small text message that an user can send over a month. An user should have at max one of this role. I'm looking for:

  • ensure SEND_SMS_X is granted
  • extract X integer

AFAIK this will not support regular expression based search:

$this->get('security.context')->isGranted($roleName);

I think this is bad design - this shouldn't be something that is controlled by roles.

You should probably have a $smsPerMonth property on your user entity so you can call getSmsPerMonth() instead of using many different roles to figure out how many SMS messages a user can send.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM