Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F7643366
D1058.id2706.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D1058.id2706.diff
View Options
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());
+ }
+
+}
\ No newline at end of file
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'));
+ }
+}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, May 1, 07:14 (18 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2620838
Default Alt Text
D1058.id2706.diff (1 KB)
Attached To
Mode
D1058: Provide base classes for servers log
Attached
Detach File
Event Timeline
Log In to Comment