. */ namespace GnuBoat; /** * @brief Base class to handle provides Services */ abstract class Service { function __construct($debug = 0) { $this->setDebug($debug); } public function setDebug($debug) { $this->_debug = $debug; } public function debug() { return $this->_debug; } public function processRequest($debug) { $this->setDebug($debug); $this->process(); } public static function errorStatic($message, $additionalContent = array(), $debug) { error_log($message); if($debug > 0) print $message ."\n"; $result = ["error" => 1, "errormessage" => $message]; Service::outputStatic(array_merge($result, $additionalContent), $debug); } public static function outputStatic($content, $debug) { header('Content-Type: application/json'); if($debug > 0){ echo json_encode($content, JSON_PRETTY_PRINT) ."\n"; } else{ echo json_encode($content) ."\n"; } } protected function error($message, $additionalContent = array()) { Service::errorStatic($message, $additionalContent, $this->debug()); } protected function output($content) { Service::outputStatic($content, $this->debug()); } /** * @brief Function used to process and generate the needed output */ abstract protected function process(); private $_debug; } ?>