From a86bdc6b5bab78b4026f44161413f4e482df42e4 Mon Sep 17 00:00:00 2001
From: Thomas Lange <code@nerdmind.de>
Date: Fri, 25 Jun 2021 22:13:59 +0200
Subject: Reorganize namespaces

---
 core/namespace/ORM/Entity.php | 49 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 core/namespace/ORM/Entity.php

(limited to 'core/namespace/ORM/Entity.php')

diff --git a/core/namespace/ORM/Entity.php b/core/namespace/ORM/Entity.php
new file mode 100644
index 0000000..9cc7755
--- /dev/null
+++ b/core/namespace/ORM/Entity.php
@@ -0,0 +1,49 @@
+<?php
+namespace ORM;
+
+abstract class Entity implements EntityInterface {
+	protected $id;
+	protected $time_insert;
+	protected $time_update;
+
+	#===============================================================================
+	# Get attribute
+	#===============================================================================
+	public function get(string $attribute) {
+		return $this->{$attribute} ?? NULL;
+	}
+
+	#===============================================================================
+	# Set attribute
+	#===============================================================================
+	public function set(string $attribute, $value) {
+		return $this->{$attribute} = $value;
+	}
+
+	#===============================================================================
+	# Return ID
+	#===============================================================================
+	final public function getID(): int {
+		return $this->id;
+	}
+
+	#===============================================================================
+	# Get all attributes
+	#===============================================================================
+	public function getAll(array $exclude = []): array {
+		$attributes = get_object_vars($this);
+
+		return array_filter($attributes, function($attribute) use($exclude) {
+			return !in_array($attribute, $exclude);
+		}, ARRAY_FILTER_USE_KEY);
+	}
+
+	#===============================================================================
+	# Get array with all non-false attributes
+	#===============================================================================
+	public function getFilteredAttributes(): array {
+		return array_filter(get_object_vars($this), function($value) {
+			return $value !== FALSE;
+		});
+	}
+}
-- 
cgit v1.2.3