From 1e49615c8c433c1f9c2f2ade1762411f2f3eb091 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sat, 4 Mar 2017 22:19:02 +0100 Subject: Factory method "buildBySlug" is now defined in the "ItemFactory" class. --- core/namespace/ItemFactory.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/namespace/ItemFactory.php') diff --git a/core/namespace/ItemFactory.php b/core/namespace/ItemFactory.php index e5793d4..35182f1 100644 --- a/core/namespace/ItemFactory.php +++ b/core/namespace/ItemFactory.php @@ -1,5 +1,9 @@ getNamespaceName().'\\Item'; @@ -8,5 +12,13 @@ abstract class ItemFactory extends Factory implements FactoryInterface { return $Instance; } + + #=========================================================================== + # Build instance by slug + #=========================================================================== + public static function buildBySlug($slug): \Item { + $Item = (new ReflectionClass(get_called_class()))->getNamespaceName().'\\Item'; + return self::build($Item::getIDByField('slug', $slug, \Application::getDatabase())); + } } ?> \ No newline at end of file -- cgit v1.2.3