fleshing out json output feature

This commit is contained in:
Andreas 2019-09-18 18:03:21 +02:00
parent 91e0333e19
commit 94881f499b
4 changed files with 12 additions and 7 deletions

View File

@ -67,8 +67,11 @@ class MVCController{
//check if testaction is valid
if(file_exists($this->testaction)){
echo('"output": [');
//execute testaction
include_once($this->testaction);
echo("]");
}
}

View File

@ -4,11 +4,16 @@
class TestUtils{
public static $log = [];
public static $status;
public static function log($output, $status = "OK"){
public static function log($output, $status = "OK",$addComma = false){
$loginput = [];
$loginput['message'] = $output;
$loginput['status'] = $status;
echo(json_encode($loginput));
if($addComma){
echo(',');
}
echo("\n");
return;
}
public static function returnLog(){
echo(json_encode(self::$log));

View File

@ -1,8 +1,5 @@
<?php
function echol($output)
{
echo $output."\n";
}
require_once('./controller/TestUtils.php');
//date_default_timezone_set('Europe/Amsterdam');
require_once('./controller/MVCController.php');
@ -13,4 +10,5 @@ $mvcController->executeModel();
if(!isset($_POST['testaction'])){
include_once("./view/content_pagetemplate.php");
}
?>

View File

@ -1,5 +1,5 @@
<?php
require_once('./controller/TestUtils.php');
@ -10,7 +10,6 @@ if(isset($_POST['auth'])){
}else{
TestUtils::log('you have no authorization to do that', 'FAILURE');
}
TestUtils::returnLog();