aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2018-04-01 15:55:04 +0200
committerThomas Lange <code@nerdmind.de>2018-04-01 15:55:04 +0200
commite3aec30a7ccbe5774160cfb6399abb9d33900c98 (patch)
treeafa0219e3ff1eb4b4a36304a24653795ed09a57b /core
parent381cdf93ab53b27db034453cc9144b6ab5707fec (diff)
downloadblog-e3aec30a7ccbe5774160cfb6399abb9d33900c98.tar.gz
blog-e3aec30a7ccbe5774160cfb6399abb9d33900c98.tar.xz
blog-e3aec30a7ccbe5774160cfb6399abb9d33900c98.zip
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.
Diffstat (limited to 'core')
-rw-r--r--core/namespace/ItemFactory.php14
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