Browse Source

add get config item to api

CauseFX 4 years ago
parent
commit
1ed096919c
2 changed files with 18 additions and 3 deletions
  1. 11 1
      api/functions/config-functions.php
  2. 7 2
      api/v2/routes/config.php

+ 11 - 1
api/functions/config-functions.php

@@ -2,5 +2,15 @@
 
 trait ConfigFunctions
 {
-
+	public function getConfigItem($item)
+	{
+		if ($this->config[$item]) {
+			$this->setAPIResponse('success', null, 200, $this->config[$item]);
+			return $this->config[$item];
+		} else {
+			$this->setAPIResponse('error', '${$this->config[$item]} is not defined', 404);
+			return false;
+		}
+		
+	}
 }

+ 7 - 2
api/v2/routes/config.php

@@ -5,10 +5,15 @@
  *     description="Organizr Configuration Items"
  * )
  */
-$app->get('/config', function ($request, $response, $args) {
+$app->get('/config[/{item}]', function ($request, $response, $args) {
 	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
 	if ($Organizr->qualifyRequest(1, true)) {
-		$GLOBALS['api']['response']['data'] = $Organizr->config;
+		if (isset($args['item'])) {
+			$Organizr->getConfigItem($args['item']);
+		} else {
+			$GLOBALS['api']['response']['data'] = $Organizr->config;
+		}
+		
 	}
 	$response->getBody()->write(jsonE($GLOBALS['api']));
 	return $response