source: src/webapp/webservice/inc/GnuBoat/Service.php@ 186affa

debian/bullseye
Last change on this file since 186affa was 0662b2d, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago

Improved webservice class to use TrackItem in ServiceData.php and added some tests

  • Property mode set to 100644
File size: 2.0 KB
Line 
1<?php
2/*
3 Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19namespace GnuBoat;
20
21/**
22 * @brief Base class to handle provides Services
23 */
24abstract class Service
25{
26 function __construct($debug = 0)
27 {
28 $this->setDebug($debug);
29 }
30
31 public function setDebug($debug)
32 {
33 $this->_debug = $debug;
34 }
35
36 public function debug()
37 {
38 return $this->_debug;
39 }
40
41 public function processRequest($debug)
42 {
43 $this->setDebug($debug);
44 $this->process();
45 }
46
47 public static function errorStatic($message, $additionalContent = array(), $debug)
48 {
49 error_log($message);
50 if($debug > 0)
51 print $message ."\n";
52 $result = ["error" => 1, "errormessage" => $message];
53 Service::outputStatic(array_merge($result, $additionalContent), $debug);
54 }
55
56 public static function outputStatic($content, $debug)
57 {
58 header('Content-Type: application/json');
59 if($debug > 0){
60 echo json_encode($content, JSON_PRETTY_PRINT) ."\n";
61 }
62 else{
63 echo json_encode($content) ."\n";
64 }
65 }
66
67 protected function error($message, $additionalContent = array())
68 {
69 Service::errorStatic($message, $additionalContent, $this->debug());
70 }
71
72 protected function output($content)
73 {
74 Service::outputStatic($content, $this->debug());
75 }
76
77 /**
78 * @brief Function used to process and generate the needed output
79 */
80 abstract protected function process();
81
82 private $_debug;
83}
84
85?>
Note: See TracBrowser for help on using the repository browser.