source: src/webapp/webservice/inc/GnuBoat/Service.php@ 1e7f556

debian/bullseye
Last change on this file since 1e7f556 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
RevLine 
[c455d7b]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
[1ba85cf]41 public function processRequest($debug)
42 {
43 $this->setDebug($debug);
44 $this->process();
45 }
[008bce9]46
[0662b2d]47 public static function errorStatic($message, $additionalContent = array(), $debug)
[008bce9]48 {
[0662b2d]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);
[008bce9]54 }
55
[0662b2d]56 public static function outputStatic($content, $debug)
[008bce9]57 {
58 header('Content-Type: application/json');
[0662b2d]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());
[008bce9]75 }
[1ba85cf]76
[c455d7b]77 /**
78 * @brief Function used to process and generate the needed output
79 */
[1ba85cf]80 abstract protected function process();
[c455d7b]81
82 private $_debug;
83}
84
85?>
Note: See TracBrowser for help on using the repository browser.