Page MenuHomeDevCentral

D1058.diff
No OneTemporary

D1058.diff

diff --git a/servers-log/Log.php b/servers-log/Log.php
new file mode 100644
--- /dev/null
+++ b/servers-log/Log.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Nasqueron\Api\ServersLog;
+
+class Log {
+
+ /**
+ * @var LogEntry[]
+ */
+ private $entries = [];
+
+ public function add (LogEntry $entry) {
+ $this->entries[] = $entry;
+ }
+
+ public function toJSON () {
+ return json_encode($this->entries, JSON_PRETTY_PRINT);
+ }
+
+ public function fromJSON (string $json) {
+ $this->entries = json_decode($json);
+ }
+
+ ///
+ /// Static helper methods
+ ///
+
+ public static function loadFromJSONFile (string $filename) {
+ $log = new Log;
+ $json = file_get_contents($filename);
+ $log->fromJSON($json);
+ return $log;
+ }
+
+ public static function addEntryToJSONFile (string $filename, LogEntry $entry) {
+ $log = self::loadFromJSONFile($filename);
+ $log->add($entry);
+ file_put_contents($filename, $log->toJSON());
+ }
+
+}
diff --git a/servers-log/LogEntry.php b/servers-log/LogEntry.php
new file mode 100644
--- /dev/null
+++ b/servers-log/LogEntry.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Nasqueron\Api\ServersLog;
+
+class LogEntry {
+
+ ///
+ /// Public properties
+ ///
+
+ public $date = "";
+
+ public $emitter = "";
+
+ public $source = "";
+
+ public $component = "";
+
+ public $entry = "";
+
+ ///
+ /// Constructor
+ ///
+
+ public function __construct () {
+ $this->date = self::get_current_timestamp();
+ }
+
+ ///
+ /// Helper methods
+ ///
+
+ // Helper methods
+ private static function get_current_timestamp () : string {
+ // Nasqueron log format: 2016-02-13T23:14:00Z (with a final Z for UTC)
+ return str_replace("+00:00", "Z", gmdate('c'));
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Thu, May 1, 04:02 (21 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2620481
Default Alt Text
D1058.diff (1 KB)

Event Timeline