@@ -32,6 +32,25 @@ abstract public function getKeywords(): array;
3232 */
3333 abstract public function getIdentifierOverrides (): array ;
3434
35+ /**
36+ * Get the static access operator for the language (e.g. '::' for PHP, '.' for JS)
37+ * @return string
38+ */
39+ abstract public function getStaticAccessOperator (): string ;
40+
41+ /**
42+ * Get the string quote character for the language (e.g. '"' for PHP, "'" for JS)
43+ * @return string
44+ */
45+ abstract public function getStringQuote (): string ;
46+
47+ /**
48+ * Wrap elements in an array syntax for the language
49+ * @param string $elements Comma-separated elements
50+ * @return string
51+ */
52+ abstract public function getArrayOf (string $ elements ): string ;
53+
3554 /**
3655 * @return array<array>
3756 */
@@ -193,4 +212,68 @@ public function hasPermissionParam(array $parameters): bool
193212 }
194213 return false ;
195214 }
215+
216+ /**
217+ * Get the prefix for Permission and Role classes (e.g., 'sdk.' for Node)
218+ * @return string
219+ */
220+ protected function getPermissionPrefix (): string
221+ {
222+ return '' ;
223+ }
224+
225+ /**
226+ * Transform permission action name for language-specific casing
227+ * Override in child classes if needed (e.g., DotNet uses ucfirst)
228+ * @param string $action
229+ * @return string
230+ */
231+ protected function transformPermissionAction (string $ action ): string
232+ {
233+ return $ action ;
234+ }
235+
236+ /**
237+ * Transform permission role name for language-specific casing
238+ * Override in child classes if needed (e.g., DotNet uses ucfirst)
239+ * @param string $role
240+ * @return string
241+ */
242+ protected function transformPermissionRole (string $ role ): string
243+ {
244+ return $ role ;
245+ }
246+
247+ /**
248+ * Generate permission example code for the language
249+ * @param string $example Permission string example
250+ * @return string
251+ */
252+ public function getPermissionExample (string $ example ): string
253+ {
254+ $ permissions = [];
255+ $ staticOp = $ this ->getStaticAccessOperator ();
256+ $ quote = $ this ->getStringQuote ();
257+ $ prefix = $ this ->getPermissionPrefix ();
258+
259+ foreach ($ this ->extractPermissionParts ($ example ) as $ permission ) {
260+ $ args = [];
261+ if ($ permission ['id ' ] !== null ) {
262+ $ args [] = $ quote . $ permission ['id ' ] . $ quote ;
263+ }
264+ if ($ permission ['innerRole ' ] !== null ) {
265+ $ args [] = $ quote . $ permission ['innerRole ' ] . $ quote ;
266+ }
267+ $ argsString = implode (', ' , $ args );
268+
269+ $ action = $ permission ['action ' ];
270+ $ role = $ permission ['role ' ];
271+ $ action = $ this ->transformPermissionAction ($ action );
272+ $ role = $ this ->transformPermissionRole ($ role );
273+
274+ $ permissions [] = $ prefix . 'Permission ' . $ staticOp . $ action . '( ' . $ prefix . 'Role ' . $ staticOp . $ role . '( ' . $ argsString . ')) ' ;
275+ }
276+
277+ return $ this ->getArrayOf (implode (', ' , $ permissions ));
278+ }
196279}
0 commit comments