config.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="config",
  5. * description="Organizr Configuration Items"
  6. * )
  7. */
  8. $app->get('/config[/{item}[/{term}]]', function ($request, $response, $args) {
  9. /**
  10. * @OA\Get(
  11. * tags={"config"},
  12. * path="/api/v2/config",
  13. * summary="Get Organizr Coniguration Items",
  14. * @OA\Response(
  15. * response="200",
  16. * description="Success",
  17. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  18. * ),
  19. * @OA\Response(response="401",description="Unauthorized"),
  20. * security={{ "api_key":{} }}
  21. * )
  22. */
  23. /**
  24. * @OA\Get(
  25. * tags={"config"},
  26. * path="/api/v2/config/{item}",
  27. * summary="Get Organizr Coniguration Item",
  28. * @OA\Parameter(name="item",description="The key of the item you want to grab",@OA\Schema(type="string"),in="path",required=true,example="configVersion"),
  29. * @OA\Response(
  30. * response="200",
  31. * description="Success",
  32. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  33. * ),
  34. * @OA\Response(response="401",description="Unauthorized"),
  35. * security={{ "api_key":{} }}
  36. * )
  37. */
  38. /**
  39. * @OA\Get(
  40. * tags={"config"},
  41. * path="/api/v2/config/search/{term}",
  42. * summary="Search Organizr Coniguration Items",
  43. * @OA\Parameter(name="term",description="The term of the items you want to grab",@OA\Schema(type="string"),in="path",required=true,example="version"),
  44. * @OA\Response(
  45. * response="200",
  46. * description="Success",
  47. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  48. * ),
  49. * @OA\Response(response="401",description="Unauthorized"),
  50. * security={{ "api_key":{} }}
  51. * )
  52. */
  53. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  54. if ($Organizr->qualifyRequest(1, true)) {
  55. if (isset($args['item'])) {
  56. $search = ($args['term']) ?? null;
  57. $Organizr->getConfigItem($args['item'], $search);
  58. } else {
  59. $GLOBALS['api']['response']['data'] = $Organizr->getConfigItems();
  60. }
  61. }
  62. $response->getBody()->write(jsonE($GLOBALS['api']));
  63. return $response
  64. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  65. ->withStatus($GLOBALS['responseCode']);
  66. });
  67. $app->put('/config', function ($request, $response, $args) {
  68. /**
  69. * @OA\Put(
  70. * tags={"config"},
  71. * path="/api/v2/config",
  72. * summary="Update Organizr Coniguration Item(s)",
  73. * @OA\RequestBody(
  74. * description="Success",
  75. * required=true,
  76. * @OA\JsonContent(ref="#/components/schemas/config-items-example"),
  77. * ),
  78. * @OA\Response(
  79. * response="200",
  80. * description="Success",
  81. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  82. * ),
  83. * @OA\Response(response="401",description="Unauthorized"),
  84. * security={{ "api_key":{} }}
  85. * )
  86. */
  87. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  88. if ($Organizr->qualifyRequest(1, true)) {
  89. $Organizr->updateConfigItems($Organizr->apiData($request));
  90. }
  91. $response->getBody()->write(jsonE($GLOBALS['api']));
  92. return $response
  93. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  94. ->withStatus($GLOBALS['responseCode']);
  95. });