From 381cdf93ab53b27db034453cc9144b6ab5707fec Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 1 Apr 2018 15:40:48 +0200 Subject: Add possibility to create instance with Attribute as first parameter --- core/namespace/Item.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'core/namespace/Item.php') diff --git a/core/namespace/Item.php b/core/namespace/Item.php index 60f7547..ba54579 100644 --- a/core/namespace/Item.php +++ b/core/namespace/Item.php @@ -10,7 +10,7 @@ abstract class Item implements ItemInterface { #=============================================================================== # Abstract item constructor #=============================================================================== - public final function __construct($itemID, \Database $Database) { + public final function __construct($param, \Database $Database) { $this->Database = $Database; $this->Reflection = new ReflectionObject($this); @@ -18,6 +18,17 @@ abstract class Item implements ItemInterface { $attribute = "{$this->Reflection->getNamespaceName()}\\Attribute"; $exception = "{$this->Reflection->getNamespaceName()}\\Exception"; + # If $param is an instance of Attribute, + # skip fetching attribute from database! + if($param instanceof Attribute) { + $this->Attribute = $param; + return; + } + + # If this gets executed, then $param + # is not an instance of Attribute! + $itemID = $param; + #=============================================================================== # Checking if item in database exists #=============================================================================== -- cgit v1.2.3