1: <?php
2: /**
3: * The Horde_Mime_Viewer:: class provides an abstracted interface to render
4: * MIME data into various formats. It depends on both a set of
5: * Horde_Mime_Viewer_* drivers which handle the actual rendering, and a
6: * configuration file to map MIME types to drivers.
7: *
8: * Copyright 1999-2012 Horde LLC (http://www.horde.org/)
9: *
10: * See the enclosed file COPYING for license information (LGPL). If you
11: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
12: *
13: * @author Anil Madhavapeddy <anil@recoil.org>
14: * @author Michael Slusarz <slusarz@horde.org>
15: * @category Horde
16: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
17: * @package Mime_Viewer
18: */
19: class Horde_Mime_Viewer
20: {
21: /**
22: * Attempts to return a concrete Horde_Mime_Viewer_Base instance based on
23: * $driver.
24: *
25: * @param string $driver Either a driver name, or the full class
26: * name to use (class must extend
27: * Horde_Mime_Viewer_Base).
28: * @param Horde_Mime_Part $part The MIME part object to display.
29: * @param array $params A hash containing any additional
30: * configuration or parameters a subclass
31: * might need.
32: *
33: * @return Horde_Mime_Viewer_Base The newly created concrete instance.
34: * @throws Horde_Mime_Viewer_Exception
35: */
36: static public function factory($driver, $part, array $params = array())
37: {
38: $params['_driver'] = $driver;
39:
40: /* Base drivers (in Viewer/ directory). */
41: $class = __CLASS__ . '_' . $driver;
42: if (class_exists($class)) {
43: return new $class($part, $params);
44: }
45:
46: /* Explicit class name, */
47: if (class_exists($driver)) {
48: return new $driver($part, $params);
49: }
50:
51: throw new Horde_Mime_Viewer_Exception(__CLASS__ . ': Class definition of ' . $class . ' not found.');
52: }
53:
54: }
55: