1: <?php
2: /**
3: * A Horde_Injector:: based Horde_Mime_Viewer factory for IMP drivers.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package IMP
9: * @author Michael Slusarz <slusarz@horde.org>
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @link http://pear.horde.org/index.php?package=IMP
12: */
13:
14: /**
15: * A Horde_Injector:: based Horde_Mime_Viewer factory for IMP drivers.
16: *
17: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (GPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/gpl.
21: *
22: * @category Horde
23: * @package IMP
24: * @author Michael Slusarz <slusarz@horde.org>
25: * @license http://www.horde.org/licenses/gpl GPL
26: * @link http://pear.horde.org/index.php?package=IMP
27: */
28: class IMP_Factory_MimeViewer extends Horde_Core_Factory_Base
29: {
30: /**
31: * Attempts to return a concrete Horde_Mime_Viewer object based on the
32: * MIME type.
33: *
34: * @param Horde_Mime_Part $mime An object with the data to be rendered.
35: * @param IMP_Contents $contents The IMP_Contents object associated with
36: * $mime.
37: * @param string $type The MIME type to use for loading.
38: *
39: * @return Horde_Mime_Viewer_Base The newly created instance.
40: * @throws Horde_Mime_Viewer_Exception
41: */
42: public function create(Horde_Mime_Part $mime,
43: IMP_Contents $contents = null, $type = null)
44: {
45: list($driver, $params) = $this->_injector->getInstance('Horde_Core_Factory_MimeViewer')->getViewerConfig($type ? $type : $mime->getType(), 'imp');
46:
47: switch ($driver) {
48: case 'Report':
49: case 'Security':
50: $params['viewer_callback'] = array($this, 'createCallback');
51: break;
52: }
53:
54: $params['imp_contents'] = $contents;
55:
56: return Horde_Mime_Viewer::factory($driver, $mime, $params);
57: }
58:
59: /**
60: * Callback used to return a MIME Viewer object from within certain
61: * Viewer drivers.
62: *
63: * @param Horde_Mime_Viewer_Base $viewer The MIME Viewer driver
64: * requesting the new object.
65: * @param Horde_Mime_Part $mime An object with the data to be
66: * rendered.
67: * @param string $type The MIME type to use for
68: * rendering.
69: *
70: * @return Horde_Mime_Viewer_Base The newly created instance.
71: * @throws Horde_Mime_Viewer_Exception
72: */
73: public function createCallback(Horde_Mime_Viewer_Base $viewer,
74: Horde_Mime_Part $mime, $type)
75: {
76: return $this->create($mime, $viewer->getConfigParam('imp_contents'), $type);
77: }
78:
79: }
80: