Skip to content

Commit 45ed065

Browse files
committed
add changes for php
1 parent 9b3b137 commit 45ed065

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/SDK/Language/PHP.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,11 @@ public function getParamExample(array $param): string
356356
switch ($type) {
357357
case self::TYPE_NUMBER:
358358
case self::TYPE_INTEGER:
359-
case self::TYPE_ARRAY:
360359
$output .= $example;
361360
break;
361+
case self::TYPE_ARRAY:
362+
$output .= $this->isPermissionString($example) ? $this->getPermissionExample($example) : $example;
363+
break;
362364
case self::TYPE_OBJECT:
363365
$output .= $this->jsonToAssoc(json_decode($example, true));
364366
break;
@@ -377,6 +379,15 @@ public function getParamExample(array $param): string
377379
return $output;
378380
}
379381

382+
public function getPermissionExample(string $example): string
383+
{
384+
$permissions = [];
385+
foreach ($this->extractPermissionParts($example) as $permission) {
386+
$permissions[] = 'Permission::' . $permission['action'] . '(Role::' . $permission['role'] . '())';
387+
}
388+
return '[' . implode(', ', $permissions) . ']';
389+
}
390+
380391
/**
381392
* Converts JSON Object To PHP Native Assoc Array
382393
*

templates/php/docs/example.md.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}};
2121
{% endif %}
2222
{% endif %}
2323
{% endfor %}
24+
{% if method.parameters.all | hasPermissionParam %}
25+
use {{ spec.title | caseUcfirst }}\Permission;
26+
use {{ spec.title | caseUcfirst }}\Role;
27+
{% endif %}
2428
2529
$client = (new Client())
2630
{%~ if method.auth|length > 0 %}

0 commit comments

Comments
 (0)