Files
This commit is contained in:
43
common/Controller/Configs.php
Normal file
43
common/Controller/Configs.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Incoviba\API\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Incoviba\API\Common\Factory\Model as Factory;
|
||||
use Incoviba\API\Common\Define\Controller\Json;
|
||||
use Incoviba\Admin\Config;
|
||||
|
||||
class Configs {
|
||||
use Json;
|
||||
|
||||
public function get(Request $request, Response $response, Factory $factory, $config_name): Response {
|
||||
$config = $factory->find(Config::class)->where((['name', $config_name]))->one();
|
||||
$output = [
|
||||
'name' => $config_name,
|
||||
'valid' => $config !== false,
|
||||
'value' => $config->value
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function set(Request $request, Response $response, Factory $factory): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$config = $factory->find(Config::class)->where([['name', $post['name']]])->one();
|
||||
if (!$config) {
|
||||
$config = Config::add($factory, $post);
|
||||
} else {
|
||||
$config->edit($post);
|
||||
}
|
||||
$output = [
|
||||
'input' => $post,
|
||||
'config' => null
|
||||
];
|
||||
if ($config !== false) {
|
||||
$config->save();
|
||||
$output['config'] = [
|
||||
'name' => $config->name,
|
||||
'value' => $config->value
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user