use Friendica\App\Arguments;
use Friendica\Core\L10n;
-use Friendica\Core\System;
-use Friendica\Object\Api\Mastodon\Error;
use Friendica\Util\Arrays;
use Friendica\Util\HTTPInputData;
use Friendica\Util\XML;
$this->logger = $logger;
}
+ /**
+ * Sets header directly
+ * mainly used to override it for tests
+ *
+ * @param string $header
+ */
+ protected function setHeader(string $header)
+ {
+ header($header);
+ }
+
+ /**
+ * Prints output directly to the caller
+ * mainly used to override it for tests
+ *
+ * @param string $output
+ */
+ protected function printOutput(string $output)
+ {
+ echo $output;
+ exit;
+ }
+
/**
* Creates the XML from a JSON style array
*
case 'atom':
case 'rss':
case 'xml':
- $ret = $this->createXML($data, $root_element);
- break;
+ return $this->createXML($data, $root_element);
case 'json':
default:
- $ret = $data;
- break;
+ return $data;
}
- return $ret;
}
/**
'request' => $this->args->getQueryString()
];
- header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description);
+ $this->setHeader(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description);
$this->exit('status', ['status' => $error], $format);
}
switch ($format) {
case 'xml':
- header('Content-Type: text/xml');
+ $this->setHeader('Content-Type: text/xml');
break;
case 'json':
- header('Content-Type: application/json');
+ $this->setHeader('Content-Type: application/json');
if (!empty($return)) {
$json = json_encode(end($return));
if (!empty($_GET['callback'])) {
}
break;
case 'rss':
- header('Content-Type: application/rss+xml');
- $return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
+ $this->setHeader('Content-Type: application/rss+xml');
break;
case 'atom':
- header('Content-Type: application/atom+xml');
- $return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
+ $this->setHeader('Content-Type: application/atom+xml');
break;
}
- echo $return;
- exit;
+ $this->printOutput($return);
}
/**
]);
$error = $this->l10n->t('API endpoint %s %s is not implemented', strtoupper($method), $path);
$error_description = $this->l10n->t('The API endpoint is currently not implemented but might be in the future.');
- $errorobj = new Error($error, $error_description);
- System::jsonError(501, $errorobj->toArray());
+
+ $this->exit('error', ['error' => ['error' => $error, 'error_description' => $error_description]]);
}
}