From 61ed60810c949f71128c50f4848fb9c9d7f5ceed Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 10 Nov 2008 15:12:22 -0700 Subject: [PATCH] Reworking Driver API some more. --- framework/Mime/lib/Horde/Mime/Viewer/Driver.php | 176 ++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 framework/Mime/lib/Horde/Mime/Viewer/Driver.php diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Driver.php b/framework/Mime/lib/Horde/Mime/Viewer/Driver.php new file mode 100644 index 000000000..fca7fb2f1 --- /dev/null +++ b/framework/Mime/lib/Horde/Mime/Viewer/Driver.php @@ -0,0 +1,176 @@ + + * @package Horde_Mime + */ +class Horde_Mime_Viewer_Driver +{ + /** + * Viewer configuration. + * + * @var array + */ + protected $_conf = array(); + + /** + * The Horde_Mime_Part object to render. + * + * @var Horde_Mime_Part + */ + protected $_mimepart = null; + + /** + * Viewer parameters. + * + * @var array + */ + protected $_params = array(); + + /** + * Can this driver render various views? + * + * @var boolean + */ + protected $_canrender = array( + 'full' => false, + 'info' => false, + 'inline' => false, + ); + + /** + * Constructor. + * + * @param array $conf Configuration specific to the driver. + */ + function __construct($conf = array()) + { + $this->_conf = $conf; + } + + /** + * Sets the Horde_Mime_Part object for the class. + * + * @param Horde_Mime_Part &$mime_part Reference to an object with the + * information to be rendered. + */ + public function setMIMEPart(&$mime_part) + { + $this->_mimepart = $mime_part; + } + + /** + * Set parameters for use with this object. + * + * @param array $params An array of params to add to the internal + * params list. + */ + public function setParams($params = array()) + { + $this->_params = array_merge($this->_params, $params); + } + + /** + * Return the rendered version of the Horde_Mime_Part object. + * + * @param string $mode The mode. Either 'full', 'inline', or 'info'. + * + * @return array An array with the following elements: + *
+     * 'data' - (string)
+     * 'status' - (array)
+     * 'type' - (string)
+     * 
+ */ + public function render($mode) + { + if (is_null($this->_mimepart) || !$this->canDisplay($mode)) { + $default = array('data' => '', 'status' => array(), 'type' => null); + if ($mode == 'full') { + $default['type'] => 'text/plain'; + } + return $default; + } + + switch ($mode) { + case 'full': + return $this->_render(); + + case 'inline': + return $this->_renderInline(); + + case 'info': + return $this->_renderInfo(); + } + } + + /** + * Return the rendered version of the Horde_Mime_Part object. + * + * @return string Rendered version of the Horde_Mime_Part object. + */ + protected function _render() + { + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return string Rendered version of the Horde_Mime_Part object. + */ + protected function _renderInline() + { + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return string Rendered information on the Horde_Mime_Part object. + */ + protected function _renderInfo() + { + } + + /** + * Can this driver render the the data? + * + * @param string $mode The mode. Either 'full', 'inline', or 'info'. + * + * @return boolean True if the driver can render the data for the given + * view. + */ + public function canRender($mode) + { + switch ($mode) { + case 'full': + case 'info': + return $this->_canrender[$mode]; + + case 'inline': + return $this->getConfigParam('inline') && $this->_canrender['inline']; + + default: + return false; + } + } + + /** + * Return a configuration parameter for the current viewer. + * + * @param string $param The parameter name. + * + * @return mixed The value of the parameter; returns null if the + * parameter doesn't exist. + */ + public function getConfigParam($param) + { + return isset($this->_conf[$param]) ? $this->_conf[$param] : null; + } +} -- 2.11.0