ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilRPCServerSettings.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
34define("RPC_SERVER_PATH", "/RPC2");
35define("RPC_SERVER_ALIVE", true);
36
38{
39 private static $instance = null;
40
41
42 public $rpc_host = '';
43 public $rpc_port = '';
44
45 public $log = null;
46 public $db = null;
47
48 public $settings_obj = null;
49
50
55 private function __construct()
56 {
57 global $DIC;
58
59 $ilDB = $DIC['ilDB'];
60 $ilias = $DIC['ilias'];
61
62 $this->log = $DIC->logger()->wsrv();
63 $this->db = $ilDB;
64 $this->ilias = $ilias;
65 }
66
71 public static function getInstance()
72 {
73 if (self::$instance) {
74 return self::$instance;
75 }
76 return self::$instance = new ilRPCServerSettings();
77 }
78
83 public function isEnabled()
84 {
85 return strlen($this->getHost()) and strlen($this->getPort());
86 }
87
88 public function getServerUrl()
89 {
90 return 'http://' . $this->getHost() . ':' . $this->getPort() . '/' . RPC_SERVER_PATH;
91 }
92
93
94 public function getHost()
95 {
96 if (strlen($this->rpc_host)) {
97 return $this->rpc_host;
98 }
99 return $this->rpc_host = $this->ilias->getSetting('rpc_server_host');
100 }
101 public function setHost($a_host)
102 {
103 $this->rpc_host = $a_host;
104 }
105 public function getPort()
106 {
107 if (strlen($this->rpc_port)) {
108 return $this->rpc_port;
109 }
110 return $this->rpc_port = $this->ilias->getSetting('rpc_server_port');
111 }
112 public function setPort($a_port)
113 {
114 $this->rpc_port = $a_port;
115 }
116 public function getPath()
117 {
118 return RPC_SERVER_PATH;
119 }
120
121 public function update()
122 {
123 $this->ilias->setSetting('rpc_server_host', $this->getHost());
124 $this->ilias->setSetting('rpc_server_port', $this->getPort());
125
126 return true;
127 }
128
132 public function pingServer()
133 {
134 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
135
136 try {
137 ilRpcClientFactory::factory('RPCebug')->ping();
138 return true;
139 } catch (Exception $e) {
140 $this->log->warning('Calling RPC server failed with message: ' . $e->getMessage());
141 return false;
142 }
143 }
144}
An exception for terminatinating execution or to throw for unit testing.
const RPC_SERVER_PATH
isEnabled()
Returns true if server ip and port are set.
static getInstance()
Get singelton instance.
__construct()
Singleton contructor.
static factory($a_package, $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
global $DIC
Definition: goto.php:24
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB