From: Chuck Hagenbuch Date: Tue, 16 Dec 2008 05:25:35 +0000 (-0500) Subject: add factory method for subcomponents that will bubble up the locale chain properly X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6b755230b00a88c6057688be608281f1f4f0a40e;p=horde.git add factory method for subcomponents that will bubble up the locale chain properly --- diff --git a/framework/Horde_Date_Parser/lib/Horde/Date/Parser.php b/framework/Horde_Date_Parser/lib/Horde/Date/Parser.php index 75777a2bd..6406ce56d 100644 --- a/framework/Horde_Date_Parser/lib/Horde/Date/Parser.php +++ b/framework/Horde_Date_Parser/lib/Horde/Date/Parser.php @@ -26,4 +26,27 @@ class Horde_Date_Parser return new Horde_Date_Parser_Locale_Base($args); } + public static function componentFactory($component, $args = array()) + { + $locale = isset($args['locale']) ? $args['locale'] : null; + if ($locale && strtolower($locale) != 'base') { + $locale = str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($locale)))); + $class = 'Horde_Date_Parser_Locale_' . $locale . '_' . $component; + if (class_exists($class)) { + return new $class($args); + } + + $language = array_shift(explode('_', $locale)); + if ($language != $locale) { + $class = 'Horde_Date_Parser_Locale_' . $language . '_' . $component; + if (class_exists($class)) { + return new $class($args); + } + } + } + + $class = 'Horde_Date_Parser_Locale_Base_' . $component; + return new $class($args); + } + }