From e3aec30a7ccbe5774160cfb6399abb9d33900c98 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 1 Apr 2018 15:55:04 +0200 Subject: Add method "buildByAttribute" and use it in "buildBySlug" This commit adds the method "buildByAttribute" to the ItemFactory and is used from now within the method "buildBySlug" to create the Item instance. --- core/namespace/ItemFactory.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/namespace/ItemFactory.php b/core/namespace/ItemFactory.php index dec136f..d961028 100644 --- a/core/namespace/ItemFactory.php +++ b/core/namespace/ItemFactory.php @@ -18,7 +18,19 @@ abstract class ItemFactory extends Factory { #=========================================================================== public static function buildBySlug($slug): Item { $Item = (new ReflectionClass(get_called_class()))->getNamespaceName().'\\Item'; - return self::build($Item::getIDByField('slug', $slug, \Application::getDatabase())); + return self::buildByAttribute($Item::getByField('slug', $slug, \Application::getDatabase())); + } + + #=========================================================================== + # Build instance by Attribute + #=========================================================================== + public static function buildByAttribute(Attribute $Attribute) { + if(!$Instance = parent::fetchInstance($Attribute->get('id'))) { + $Item = (new ReflectionClass(get_called_class()))->getNamespaceName().'\\Item'; + $Instance = parent::storeInstance($Attribute->get('id'), new $Item($Attribute, \Application::getDatabase())); + } + + return $Instance; } } ?> \ No newline at end of file -- cgit v1.2.3