diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/View/Helper/DeclareVars.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/View/Helper/DeclareVars.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,95 @@ + + * $this->declareVars( + * 'varName1', + * 'varName2', + * array('varName3' => 'defaultValue', + * 'varName4' => array() + * ) + * ); + * + * + * @param string|array variable number of arguments, all string names of variables to test + * @return void + */ + public function declareVars() + { + $args = func_get_args(); + foreach($args as $key) { + if (is_array($key)) { + foreach ($key as $name => $value) { + $this->_declareVar($name, $value); + } + } else if (!isset($view->$key)) { + $this->_declareVar($key); + } + } + } + + /** + * Set a view variable + * + * Checks to see if a $key is set in the view object; if not, sets it to $value. + * + * @param string $key + * @param string $value Defaults to an empty string + * @return void + */ + protected function _declareVar($key, $value = '') + { + if (!isset($this->view->$key)) { + $this->view->$key = $value; + } + } +}