ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilRPCServerSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
26 {
27  private const RPC_SERVER_PATH = "/RPC2";
28 
29  private static ?ilRPCServerSettings $instance = null;
30 
31  public string $rpc_host = '';
32  public string $rpc_port = '';
33 
34  private ilLogger $log;
36 
37  private function __construct()
38  {
39  global $DIC;
40 
41  $this->log = $DIC->logger()->wsrv();
42  $this->settings = $DIC->settings();
43  }
44 
45  public static function getInstance(): ilRPCServerSettings
46  {
47  if (self::$instance) {
48  return self::$instance;
49  }
50  return self::$instance = new ilRPCServerSettings();
51  }
52 
56  public function isEnabled(): bool
57  {
58  return $this->getHost() !== '' && $this->getPort() !== '';
59  }
60 
61  public function getServerUrl(): string
62  {
63  return 'http://' . $this->getHost() . ':' . $this->getPort() . '/' . self::RPC_SERVER_PATH;
64  }
65 
66  public function getHost(): string
67  {
68  if ($this->rpc_host !== '') {
69  return $this->rpc_host;
70  }
71  return $this->rpc_host = (string) $this->settings->get('rpc_server_host');
72  }
73 
74  public function setHost($a_host): void
75  {
76  $this->rpc_host = $a_host;
77  }
78 
79  public function getPort(): string
80  {
81  if ($this->rpc_port !== '') {
82  return $this->rpc_port;
83  }
84  return $this->rpc_port = (string) $this->settings->get('rpc_server_port');
85  }
86 
87  public function setPort(string $a_port): void
88  {
89  $this->rpc_port = $a_port;
90  }
91 
92  public function getPath(): string
93  {
94  return self::RPC_SERVER_PATH;
95  }
96 
97  public function update(): void
98  {
99  $this->settings->set('rpc_server_host', $this->getHost());
100  $this->settings->set('rpc_server_port', $this->getPort());
101  }
102 
103  public function pingServer(): bool
104  {
105  try {
106  ilRpcClientFactory::factory('RPCebug')->ping();
107  return true;
108  } catch (Exception $e) {
109  $this->log->warning('Calling RPC server failed with message: ' . $e->getMessage());
110  return false;
111  }
112  }
113 }
static ilRPCServerSettings $instance
static factory(string $a_package, int $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isEnabled()
Returns true if server ip and port are set.
Class for storing all rpc communication settings.
global $DIC
Definition: shib_login.php:22