config.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="config",
  5. * description="Organizr Configuration Items"
  6. * )
  7. */
  8. $app->get('/config', function ($request, $response, $args) {
  9. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  10. if ($Organizr->qualifyRequest(1, true)) {
  11. $GLOBALS['api']['response']['data'] = $Organizr->config;
  12. }
  13. $response->getBody()->write(jsonE($GLOBALS['api']));
  14. return $response
  15. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  16. ->withStatus($GLOBALS['responseCode']);
  17. });
  18. $app->put('/config', function ($request, $response, $args) {
  19. /**
  20. * @OA\Put(
  21. * tags={"config"},
  22. * path="/api/v2/config",
  23. * summary="Update Organizr Coniguration Item(s)",
  24. * @OA\RequestBody(
  25. * description="Success",
  26. * required=true,
  27. * @OA\JsonContent(ref="#/components/schemas/config-items-example"),
  28. * ),
  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. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  39. if ($Organizr->qualifyRequest(1, true)) {
  40. $Organizr->updateConfigItems($Organizr->apiData($request));
  41. }
  42. $response->getBody()->write(jsonE($GLOBALS['api']));
  43. return $response
  44. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  45. ->withStatus($GLOBALS['responseCode']);
  46. });