54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?PHP
|
|
/**
|
|
* Provides the API.
|
|
*/
|
|
declare(strict_types = 1);
|
|
|
|
require_once __DIR__ . '/../provideEnv.php';
|
|
|
|
$verb = MD_STD_IN::get_http_input_text("verb");
|
|
$subject = MD_STD_IN::get_http_input_text("subject");
|
|
|
|
if (empty($verb) && empty($subject)) {
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
readfile(__DIR__ . '/../static/json/openapi.json');
|
|
return;
|
|
}
|
|
|
|
$availableLangs = MD_STD::scandir(__DIR__ . '/../l10n/musdb/');
|
|
$lang = MD_STD_IN::get_http_input_text("lang", "en", $availableLangs);
|
|
|
|
$parser = MD_STD_IN::get_http_input_text("parser");
|
|
$data = trim(filter_input(INPUT_POST, "data"));
|
|
|
|
if ($verb === 'evaluate' && in_array($subject, ['object', 'minimaldatensatz', 'count_vocabulary_entries_to_be_added'], true)) {
|
|
|
|
$limitMode = match($subject) {
|
|
'object' => QARunnerLimitMode::main,
|
|
'minimaldatensatz' => QARunnerLimitMode::minimaldatensatz,
|
|
'count_vocabulary_entries_to_be_added' => QARunnerLimitMode::count_new_vocab_entries,
|
|
};
|
|
|
|
$runner = new QARunner($lang, $parser, $data, $limitMode);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode([
|
|
'results' => match($subject) {
|
|
'object' => $runner->evaluateObjects(),
|
|
'minimaldatensatz' => $runner->evaluateObjectsForMinimaldatensatz(),
|
|
'count_vocabulary_entries_to_be_added' => $runner->countNewlyRequestedVocabularyEntries(),
|
|
},
|
|
]);
|
|
|
|
}
|
|
else if ($verb === 'convert_to_xml' && in_array($subject, QaConvertToXml::listAvailableOutputFormats(), true)) {
|
|
|
|
$institution_name = MD_STD_IN::get_http_input_text("institution_name");
|
|
$institution_identifier = MD_STD_IN::get_http_input_text("institution_identifier");
|
|
|
|
$runner = new QARunner($lang, $parser, $data, null); // TODO: Add limit modes per format
|
|
header('Content-Type: text/xml; charset=utf-8');
|
|
echo $runner->convertToXml($subject, $institution_name, $institution_identifier);
|
|
|
|
}
|