Skip to content

Commit 928137c

Browse files
committed
fix: add permission and role helper class to node
1 parent 3ea8de6 commit 928137c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/SDK/Language/Node.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ public function getParamExample(array $param): string
140140
}
141141

142142
return match ($type) {
143-
self::TYPE_ARRAY, self::TYPE_FILE, self::TYPE_INTEGER, self::TYPE_NUMBER => $example,
143+
self::TYPE_ARRAY => $this->isPermissionString($example) ? $this->getPermissionExample($example) : $example,
144+
self::TYPE_FILE, self::TYPE_INTEGER, self::TYPE_NUMBER => $example,
144145
self::TYPE_BOOLEAN => ($example) ? 'true' : 'false',
145146
self::TYPE_OBJECT => ($example === '{}')
146147
? '{}'
@@ -151,6 +152,23 @@ public function getParamExample(array $param): string
151152
};
152153
}
153154

155+
public function getPermissionExample(string $example): string
156+
{
157+
$permissions = [];
158+
foreach ($this->extractPermissionParts($example) as $permission) {
159+
$args = [];
160+
if ($permission['id'] !== null) {
161+
$args[] = "'" . $permission['id'] . "'";
162+
}
163+
if ($permission['innerRole'] !== null) {
164+
$args[] = "'" . $permission['innerRole'] . "'";
165+
}
166+
$argsString = implode(', ', $args);
167+
$permissions[] = 'sdk.Permission.' . $permission['action'] . '(sdk.Role.' . $permission['role'] . '(' . $argsString . '))';
168+
}
169+
return '[' . implode(', ', $permissions) . ']';
170+
}
171+
154172
/**
155173
* @return array
156174
*/

0 commit comments

Comments
 (0)