mirror of
https://github.com/unraid/api.git
synced 2026-03-07 08:50:06 -06:00
refactor: state class usage with getServerStateJson
This commit is contained in:
@@ -7,9 +7,8 @@ require_once "$docroot/webGui/include/Helpers.php";
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
require_once "$docroot/plugins/dynamix.my.servers/include/state.php";
|
||||
|
||||
$serverStateClass = new ServerState();
|
||||
$serverStateData = $serverStateClass->getServerState();
|
||||
$serverState = new ServerState();
|
||||
|
||||
header('Content-type: application/json');
|
||||
|
||||
echo json_encode($serverStateData);
|
||||
echo $serverState->getServerStateJson();
|
||||
|
||||
@@ -3,7 +3,7 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
|
||||
require_once("$docroot/plugins/dynamix.my.servers/include/state.php");
|
||||
require_once("$docroot/plugins/dynamix.my.servers/include/translations.php");
|
||||
|
||||
$serverStateClass = new ServerState();
|
||||
$serverState = new ServerState();
|
||||
$wCTranslations = new WebComponentTranslations();
|
||||
?>
|
||||
<script>
|
||||
@@ -24,5 +24,5 @@ if (!document.getElementsByTagName(modalsWebComponent).length) {
|
||||
<?
|
||||
echo "
|
||||
<unraid-i18n-host>
|
||||
<unraid-user-profile server='" . json_encode($serverStateClass->getServerState()) . "'></unraid-user-profile>
|
||||
<unraid-user-profile server='" . $serverState->getServerStateJson() . "'></unraid-user-profile>
|
||||
</unraid-i18n-host>";
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @todo refactor globals – currently if you try to use $GLOBALS the class will break.
|
||||
*/
|
||||
$webguiGlobals = $GLOBALS;
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
|
||||
@@ -9,7 +12,10 @@ require_once "$docroot/plugins/dynamix.my.servers/include/reboot-details.php";
|
||||
* Usage:
|
||||
* ```
|
||||
* $serverStateClass = new ServerState();
|
||||
* $serverStateData = $serverStateClass->getServerState();
|
||||
*
|
||||
* $serverStateClass->getServerState();
|
||||
* or
|
||||
* $serverStateClass->getServerStateJson();
|
||||
* ```
|
||||
*/
|
||||
class ServerState
|
||||
@@ -86,7 +92,7 @@ class ServerState
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the server information as an associative array.
|
||||
* Retrieve the server information as an associative array
|
||||
*
|
||||
* @return array An array containing server information.
|
||||
*/
|
||||
@@ -156,4 +162,12 @@ class ServerState
|
||||
return $serverState;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Retrieve the server information as a JSON string
|
||||
*
|
||||
* @return string A JSON string containing server information.
|
||||
*/
|
||||
public function getServerStateJson() {
|
||||
return json_encode($this->getServerState());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user