38 const ACTION_ADD =
'add';
39 const ACTION_UPDATE =
'update';
40 const ACTION_DELETE =
'delete';
42 const SCOPE_OBJECT =
'object';
43 const SCOPE_RIGHT =
'right';
49 public $descriptorFile;
86 string $descriptorFile,
91 ?
int $rightKey =
null,
92 ?
string $rightLabel =
null,
93 ?
string $rightCrud =
null
96 throw new \InvalidArgumentException(
'RightsSyncCommand requires a module name');
98 if ($descriptorFile ===
'') {
99 throw new \InvalidArgumentException(
'RightsSyncCommand requires a descriptor file path');
101 if (!in_array($scope, array(self::SCOPE_OBJECT, self::SCOPE_RIGHT),
true)) {
102 throw new \InvalidArgumentException(
'RightsSyncCommand got an unknown scope: '.$scope);
104 if (!in_array($actionType, array(self::ACTION_ADD, self::ACTION_UPDATE, self::ACTION_DELETE),
true)) {
105 throw new \InvalidArgumentException(
'RightsSyncCommand got an unknown action: '.$actionType);
107 if ($scope === self::SCOPE_OBJECT) {
108 if ($objectName ===
'') {
109 throw new \InvalidArgumentException(
'An object-scoped RightsSyncCommand requires an object name');
111 if ($actionType === self::ACTION_UPDATE) {
112 throw new \InvalidArgumentException(
'There is no object-scoped update in ModuleBuilder');
115 if ($scope === self::SCOPE_RIGHT && $actionType !== self::ACTION_ADD && $rightKey ===
null) {
116 throw new \InvalidArgumentException(
'A right-scoped '.$actionType.
' requires a right key');
118 if ($scope === self::SCOPE_RIGHT && $actionType !== self::ACTION_DELETE && ($rightLabel ===
null || $rightCrud ===
null)) {
119 throw new \InvalidArgumentException(
'A right-scoped '.$actionType.
' requires a label and a crud code');
123 $this->descriptorFile = $descriptorFile;
124 $this->permissions = $permissions;
125 $this->objectName = $objectName;
126 $this->scope = $scope;
127 $this->actionType = $actionType;
128 $this->rightKey = $rightKey;
129 $this->rightLabel = $rightLabel;
130 $this->rightCrud = $rightCrud;
142 public static function forObjectCreation(
string $module,
string $descriptorFile, array $permissions,
string $objectName): self
144 return new self(
$module, $descriptorFile, $permissions, $objectName, self::SCOPE_OBJECT, self::ACTION_ADD);
156 public static function forObjectDeletion(
string $module,
string $descriptorFile, array $permissions,
string $objectName): self
158 return new self(
$module, $descriptorFile, $permissions, $objectName, self::SCOPE_OBJECT, self::ACTION_DELETE);
172 public static function forRightAddition(
string $module,
string $descriptorFile, array $permissions,
string $objectName,
string $label,
string $crud): self
174 return new self(
$module, $descriptorFile, $permissions, $objectName, self::SCOPE_RIGHT, self::ACTION_ADD,
null, $label, $crud);
189 public static function forRightUpdate(
string $module,
string $descriptorFile, array $permissions,
int $rightKey,
string $objectName,
string $label,
string $crud): self
191 return new self(
$module, $descriptorFile, $permissions, $objectName, self::SCOPE_RIGHT, self::ACTION_UPDATE, $rightKey, $label, $crud);
203 public static function forRightDeletion(
string $module,
string $descriptorFile, array $permissions,
int $rightKey): self
205 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)
if(! $sortfield) if(! $sortorder) $module