api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OpenApiDefinition.php 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Tqdev\PhpCrudApi\OpenApi;
  3. class OpenApiDefinition implements \JsonSerializable
  4. {
  5. private $root;
  6. public function __construct($base)
  7. {
  8. $this->root = $base;
  9. }
  10. public function set(string $path, $value) /*: void*/
  11. {
  12. $parts = explode('|', trim($path, '|'));
  13. $current = &$this->root;
  14. while (count($parts) > 0) {
  15. $part = array_shift($parts);
  16. if (!isset($current[$part])) {
  17. $current[$part] = [];
  18. }
  19. $current = &$current[$part];
  20. }
  21. $current = $value;
  22. }
  23. public function has(string $path): bool
  24. {
  25. $parts = explode('|', trim($path, '|'));
  26. $current = &$this->root;
  27. while (count($parts) > 0) {
  28. $part = array_shift($parts);
  29. if (!isset($current[$part])) {
  30. return false;
  31. }
  32. $current = &$current[$part];
  33. }
  34. return true;
  35. }
  36. public function jsonSerialize()
  37. {
  38. return $this->root;
  39. }
  40. }