1: <?php
2: /**
3: * Abstract class to handle different kinds of Data formats and to
4: * help data exchange between Horde applications and external sources.
5: *
6: * Copyright 1999-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Jan Schneider <jan@horde.org>
12: * @author Chuck Hagenbuch <chuck@horde.org>
13: * @category Horde
14: * @package Data
15: */
16: class Horde_Data
17: {
18: /* Import already mapped csv data. */
19: const IMPORT_MAPPED = 1;
20: /* Map date and time entries of csv data. */
21: const IMPORT_DATETIME = 2;
22: /* Import generic CSV data. */
23: const IMPORT_CSV = 3;
24: /* Import MS Outlook data. */
25: const IMPORT_OUTLOOK = 4;
26: /* Import vCalendar/iCalendar data. */
27: const IMPORT_ICALENDAR = 5;
28: /* Import vCards. */
29: const IMPORT_VCARD = 6;
30: /* Import generic tsv data. */
31: const IMPORT_TSV = 7;
32: /* Import Mulberry address book data. */
33: const IMPORT_MULBERRY = 8;
34: /* Import Pine address book data. */
35: const IMPORT_PINE = 9;
36: /* Import file. */
37: const IMPORT_FILE = 11;
38: /* Import data. */
39: const IMPORT_DATA = 12;
40:
41: /* Export generic CSV data. */
42: const EXPORT_CSV = 100;
43: /* Export iCalendar data. */
44: const EXPORT_ICALENDAR = 101;
45: /* Export vCards. */
46: const EXPORT_VCARD = 102;
47: /* Export TSV data. */
48: const EXPORT_TSV = 103;
49: /* Export Outlook CSV data. */
50: const EXPORT_OUTLOOKCSV = 104;
51:
52: /**
53: * Attempts to return a concrete instance based on $format.
54: *
55: * @param string $format The type of concrete subclass to return.
56: * @param array $params Parameters to pass to the format driver.
57: *
58: * @return Horde_Data_Driver The newly created concrete instance.
59: * @throws Horde_Data_Exception
60: */
61: static public function factory($format, array $params = array())
62: {
63: if (is_array($format)) {
64: $app = ucfirst($format[0]);
65: $format = ucfirst(strtolower(basename($format[1])));
66: $class = $app . '_Data_' . $format;
67: } else {
68: $format = ucfirst(strtolower(basename($format)));
69: $class = __CLASS__ . '_' . $format;
70: }
71:
72: if (class_exists($class)) {
73: return new $class($params);
74: }
75:
76: throw new Horde_Data_Exception('Driver not found: ' . $class);
77: }
78:
79: }
80: