37 const ACTION_ADD =
'add';
38 const ACTION_UPDATE =
'update';
39 const ACTION_DELETE =
'delete';
41 const SCOPE_OBJECT =
'object';
42 const SCOPE_RIGHT =
'right';
48 public $descriptorFile;
85 string $descriptorFile,
90 ?
int $rightKey =
null,
91 ?
string $rightLabel =
null,
92 ?
string $rightCrud =
null
95 throw new \InvalidArgumentException(
'RightsSyncCommand requires a module name');
97 if ($descriptorFile ===
'') {
98 throw new \InvalidArgumentException(
'RightsSyncCommand requires a descriptor file path');
100 if (!in_array($scope, array(self::SCOPE_OBJECT, self::SCOPE_RIGHT),
true)) {
101 throw new \InvalidArgumentException(
'RightsSyncCommand got an unknown scope: '.$scope);
103 if (!in_array($actionType, array(self::ACTION_ADD, self::ACTION_UPDATE, self::ACTION_DELETE),
true)) {
104 throw new \InvalidArgumentException(
'RightsSyncCommand got an unknown action: '.$actionType);
106 if ($scope === self::SCOPE_OBJECT) {
107 if ($objectName ===
'') {
108 throw new \InvalidArgumentException(
'An object-scoped RightsSyncCommand requires an object name');
110 if ($actionType === self::ACTION_UPDATE) {
111 throw new \InvalidArgumentException(
'There is no object-scoped update in ModuleBuilder');
114 if ($scope === self::SCOPE_RIGHT && $actionType !== self::ACTION_ADD && $rightKey ===
null) {
115 throw new \InvalidArgumentException(
'A right-scoped '.$actionType.
' requires a right key');
117 if ($scope === self::SCOPE_RIGHT && $actionType !== self::ACTION_DELETE && ($rightLabel ===
null || $rightCrud ===
null)) {
118 throw new \InvalidArgumentException(
'A right-scoped '.$actionType.
' requires a label and a crud code');
121 $this->module = $module;
122 $this->descriptorFile = $descriptorFile;
123 $this->permissions = $permissions;
124 $this->objectName = $objectName;
125 $this->scope = $scope;
126 $this->actionType = $actionType;
127 $this->rightKey = $rightKey;
128 $this->rightLabel = $rightLabel;
129 $this->rightCrud = $rightCrud;
141 public static function forObjectCreation(
string $module,
string $descriptorFile, array $permissions,
string $objectName): self
143 return new self($module, $descriptorFile, $permissions, $objectName, self::SCOPE_OBJECT, self::ACTION_ADD);
155 public static function forObjectDeletion(
string $module,
string $descriptorFile, array $permissions,
string $objectName): self
157 return new self($module, $descriptorFile, $permissions, $objectName, self::SCOPE_OBJECT, self::ACTION_DELETE);
171 public static function forRightAddition(
string $module,
string $descriptorFile, array $permissions,
string $objectName,
string $label,
string $crud): self
173 return new self($module, $descriptorFile, $permissions, $objectName, self::SCOPE_RIGHT, self::ACTION_ADD,
null, $label, $crud);
188 public static function forRightUpdate(
string $module,
string $descriptorFile, array $permissions,
int $rightKey,
string $objectName,
string $label,
string $crud): self
190 return new self($module, $descriptorFile, $permissions, $objectName, self::SCOPE_RIGHT, self::ACTION_UPDATE, $rightKey, $label, $crud);
202 public static function forRightDeletion(
string $module,
string $descriptorFile, array $permissions,
int $rightKey): self
204 return new self($module, $descriptorFile, $permissions,
'', self::SCOPE_RIGHT, self::ACTION_DELETE, $rightKey);
Immutable request describing one permissions sync to perform on a module descriptor.
static forObjectDeletion(string $module, string $descriptorFile, array $permissions, string $objectName)
Drop every right attached to an object being deleted.
static forRightDeletion(string $module, string $descriptorFile, array $permissions, int $rightKey)
Remove one right, addressed by its index in the rights array.
static forRightUpdate(string $module, string $descriptorFile, array $permissions, int $rightKey, string $objectName, string $label, string $crud)
Replace one right, addressed by its index in the rights array.
static forRightAddition(string $module, string $descriptorFile, array $permissions, string $objectName, string $label, string $crud)
Append one right to the descriptor.
static forObjectCreation(string $module, string $descriptorFile, array $permissions, string $objectName)
Declare the three CRUD rights of a newly generated object.
__construct(string $module, string $descriptorFile, array $permissions, string $objectName, string $scope, string $actionType, ?int $rightKey=null, ?string $rightLabel=null, ?string $rightCrud=null)