1: <?php
2: 3: 4:
5: class Horde_Date_Parser
6: {
7: public static function parse($text, $args = array())
8: {
9: $factoryArgs = $args;
10: unset($args['locale']);
11:
12: return self::factory($factoryArgs)->parse($text, $args);
13: }
14:
15: public static function factory($args = array())
16: {
17: $locale = isset($args['locale']) ? $args['locale'] : null;
18: if ($locale && strtolower($locale) != 'base') {
19: $locale = str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($locale))));
20: $class = 'Horde_Date_Parser_Locale_' . $locale;
21: if (class_exists($class)) {
22: return new $class($args);
23: }
24:
25: $language = array_shift(explode('_', $locale));
26: if ($language != $locale) {
27: $class = 'Horde_Date_Parser_Locale_' . $language;
28: if (class_exists($class)) {
29: return new $class($args);
30: }
31: }
32: }
33:
34: return new Horde_Date_Parser_Locale_Base($args);
35: }
36:
37: 38: 39:
40: public static function getLocales()
41: {
42: $dir = dirname(__FILE__) . '/Parser/Locale';
43: $locales = array();
44: foreach (new DirectoryIterator($dir) as $f) {
45: if ($f->isFile()) {
46: $locale = str_replace('.php', '', $f->getFilename());
47: $locale = preg_replace_callback('/([A-Z][a-z]*)([A-Z].*)?/', create_function('$m', 'if (!isset($m[2])) { return strtolower($m[1]); } else { return strtolower($m[1]) . "_" . strtoupper($m[2]); }'), $locale);
48: $locales[] = $locale;
49: }
50: }
51:
52: return $locales;
53: }
54:
55: }
56: