<?phprequire_once('Zend/View/Interface.php');/** * @author Davide Bellettini <davide dot bellettini at gmail dot com> * @copyright CopyLeft 2007 Davide Bellettini * @license GNU Lesser General Public License @link http://opensource.org/licenses/lgpl-license.php */class Zefrax_View_Smarty implements Zefrax_View_Interface{ /** * Template engine * * * @var Smarty */ private $_template; /** * Class constructor */ protected function __construct(Smarty $template = null) { if(is_null($template)) { $this->_template = new Smarty(); } else { $this->_template = $template; } } /** * Return the template engine object, if any * * If using a third-party template engine, such as Smarty, patTemplate, * phplib, etc, return the template engine object. Useful for calling * methods on these objects, such as for setting filters, modifiers, etc. * * @return mixed */ public function getEngine() { return $this->_template; } /** * Set the path to find the view script used by render() * * @param string|array The directory (-ies) to set as the path. Note that * the concrete view implentation may not necessarily support multiple * directories. * @return void */ public function setScriptPath($path) { if(is_array($path)) { $this->_template->compile_dir = $path[0]; } else { list($this->_template->compile_dir) = explode(PATH_SEPARATOR, $path, 2); } } /** * Assign a variable to the view * * @param string $key The variable name. * @param mixed $val The variable value. * @return void */ public function __set($key, $val) { $this->_template->assign($key, $val); } /** * Allows testing with empty() and isset() to work * * @param string $key * @return boolean */ public function __isset($key) { return $this->_template->get_template_vars($key) !== null; } /** * Allows unset() on object properties to work * * @param string $key * @return void */ public function __unset($key) { $this->_template->clear_assign($key); } /** * Assign variables to the view script via differing strategies. * * Suggested implementation is to allow setting a specific key to the * specified value, OR passing an array of key => value pairs to set en * masse. * * @see __set() * @param string|array $spec The assignment strategy to use (key or array of key * => value pairs) * @param mixed $value (Optional) If assigning a named variable, use this * as the value. * @return void */ public function assign($spec, $value = null) { $this->_template->assign($spec, $value); } /** * Clear all assigned variables * * Clears all variables assigned to Zend_View either via {@link assign()} or * property overloading ({@link __get()}/{@link __set()}). * * @return void */ public function clearVars() { $this->_template->clear_all_assign(); } /** * Processes a view script and returns the output. * * @param string $name The script script name to process. * @return string The script output. */ public function render($name) { $this->_template->display($name); } public function setCaching($caching = true) { $this->_template->caching = (boolean)$caching; } public function setCacheLifeTime($lifetime) { $this->_template->cache_lifetime = intval($lifetime); } /** * Factory * * @param Smarty $template * @return Zefrax_View_Smarty */ public static function factory(Smarty $template = null) { return new self($template); }}?>