config.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="config",
  5. * description="Organizr Configuration Items"
  6. * )
  7. */
  8. $app->get('/config[/{item}]', function ($request, $response, $args) {
  9. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  10. if ($Organizr->qualifyRequest(1, true)) {
  11. if (isset($args['item'])) {
  12. $Organizr->getConfigItem($args['item']);
  13. } else {
  14. $GLOBALS['api']['response']['data'] = $Organizr->config;
  15. }
  16. }
  17. $response->getBody()->write(jsonE($GLOBALS['api']));
  18. return $response
  19. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  20. ->withStatus($GLOBALS['responseCode']);
  21. });
  22. $app->put('/config', function ($request, $response, $args) {
  23. /**
  24. * @OA\Put(
  25. * tags={"config"},
  26. * path="/api/v2/config",
  27. * summary="Update Organizr Coniguration Item(s)",
  28. * @OA\RequestBody(
  29. * description="Success",
  30. * required=true,
  31. * @OA\JsonContent(ref="#/components/schemas/config-items-example"),
  32. * ),
  33. * @OA\Response(
  34. * response="200",
  35. * description="Success",
  36. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  37. * ),
  38. * @OA\Response(response="401",description="Unauthorized"),
  39. * security={{ "api_key":{} }}
  40. * )
  41. */
  42. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  43. if ($Organizr->qualifyRequest(1, true)) {
  44. $Organizr->updateConfigItems($Organizr->apiData($request));
  45. }
  46. $response->getBody()->write(jsonE($GLOBALS['api']));
  47. return $response
  48. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  49. ->withStatus($GLOBALS['responseCode']);
  50. });