diff options
Diffstat (limited to 'core/namespace/ItemFactory.php')
-rw-r--r-- | core/namespace/ItemFactory.php | 14 |
1 files changed, 13 insertions, 1 deletions
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 |