I'm building a symfony project and at some point I've come up with a switch case to manage the acl rights. I would prefer using a dynamic access to the constant but havn't find a good solution. I've seen reflection but that doesn't seem to be the proper solution to me.
$mask = null;
switch ($participant->getRight()) {
case 'VIEW':
$mask = MaskBuilder::MASK_VIEW;
break;
case 'EDIT':
$mask = MaskBuilder::MASK_EDIT;
break;
case 'OPERATOR':
$mask = MaskBuilder::MASK_OPERATOR;
break;
default:
break;
}
$this->aclManager->addObjectPermission($project, $mask, $user);
So, this switch is in a foreach
, that gets the $user
entity, then with the result of the list box from the view, I get the rights of the user which can be (for now) EDIT VIEW or OPERATOR. These right were chosen because they are directly related to the MaskBuilder masks.
The thing is, if there is a refactor to be done, I will need to modify this switch AND the part where the form is defined. I would like to do something like
$mask = 'MASK_' . $participant->getRight();
$this->aclManager->addObjectPermissions($project, MaskBuilder::$mask, $user);
But havn't find a way to do it.
Is my switch a good way to do it ? Or is there a proper php way to do the same, that would reduce refactor cost?