mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
little changes in http api internals
This commit is contained in:
parent
d71400ea63
commit
02ac0655b0
3 changed files with 20 additions and 7 deletions
|
|
@ -67,7 +67,7 @@ foreach (MTTExtensionLoader::loadedExtensions() as $instance) {
|
|||
foreach ($newRoutes as $endpoint => $methods) {
|
||||
$endpoint = '/ext/'. $instance::bundleId. $endpoint;
|
||||
foreach ($methods as $k => &$v) {
|
||||
$v[2] = true; // Mark extension method
|
||||
$v[3] = true; // Mark extension method
|
||||
}
|
||||
$endpoints[$endpoint] = $methods;
|
||||
}
|
||||
|
|
@ -93,9 +93,11 @@ foreach ($endpoints as $search => $methods) {
|
|||
// check if class method exists
|
||||
$class = $classDescr[0];
|
||||
$classMethod = $classDescr[1];
|
||||
$isExt = $classDescr[2] ?? false;
|
||||
$isExt = $classDescr[3] ?? false;
|
||||
if ($isExt) {
|
||||
checkWriteAccess();
|
||||
if (false == ($classDescr[2] ?? false)) {
|
||||
checkWriteAccess();
|
||||
}
|
||||
}
|
||||
$param = null;
|
||||
if (count($m) >= 2) {
|
||||
|
|
|
|||
|
|
@ -46,14 +46,24 @@ class ApiResponse
|
|||
public $contentType = 'application/json';
|
||||
public $code = null;
|
||||
|
||||
function htmlContent(string $content, int $code = 200): ApiResponse
|
||||
function content(string $contentType, string $content, int $code = 200)
|
||||
{
|
||||
$this->contentType = 'text/html';
|
||||
$this->contentType = $contentType;
|
||||
$this->data = $content;
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
function htmlContent(string $content, int $code = 200): ApiResponse
|
||||
{
|
||||
return $this->content('text/html', $content, $code);
|
||||
}
|
||||
|
||||
function cssContent(string $content, int $code = 200): ApiResponse
|
||||
{
|
||||
return $this->content('text/css', $content, $code);
|
||||
}
|
||||
|
||||
function exit()
|
||||
{
|
||||
if (is_null($this->data) && is_null($this->code)) {
|
||||
|
|
@ -62,7 +72,8 @@ class ApiResponse
|
|||
if (!is_null($this->code)) {
|
||||
http_response_code($this->code);
|
||||
}
|
||||
if ($this->contentType == 'text/html') {
|
||||
if ($this->contentType != 'application/json') {
|
||||
header('Content-type: '. $this->contentType);
|
||||
print $this->data;
|
||||
exit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ function get_unsafe_mttinfo($v)
|
|||
/* URL for API, like http://localhost/mytinytodo/api/. No need to set by default. */
|
||||
$_mttinfo['api_url'] = Config::getUrl('api_url'); // need to have a trailing slash
|
||||
if ($_mttinfo['api_url'] == '') {
|
||||
$_mttinfo['api_url'] = get_unsafe_mttinfo('mtt_url'). 'api/';
|
||||
$_mttinfo['api_url'] = get_unsafe_mttinfo('mtt_url'). 'api.php/';
|
||||
}
|
||||
return $_mttinfo['api_url'];
|
||||
case 'title':
|
||||
|
|
|
|||
Loading…
Reference in a new issue