private $_throwOnHelperCollision = false;
/**
+ * Protected properties
+ * @var array
+ */
+ private $_protectedProperties;
+
+ /**
* Constructor.
*
* @param array $config Configuration key-value pairs.
if (!empty($config['templatePath'])) {
$this->addTemplatePath($config['templatePath']);
}
- }
- /**
- * Return an empty string if a variable does not exist.
- *
- * @param string $name Variable name to retrieve
- */
- public function __get($name)
- {
- return '';
+ $this->_protectedProperties = get_class_vars(__CLASS__);
}
/**
- * Assign a single view variable
+ * Undefined variables return null.
*
- * @param string $name Variable name to set
- * @param mixed $value The value of $name
+ * @return null
*/
- public function __set($name, $value)
+ public function __get($name)
{
- $this->$name = $value;
+ return null;
}
/**
public function assign($array)
{
foreach ($array as $key => $val) {
+ if (isset($this->_protectedProperties[$key])) {
+ throw new Horde_View_Exception("Can't overwrite internal variables in assign()");
+ }
$this->$key = $val;
}
}
interface Horde_View_Interface
{
/**
- * Return a view variable
+ * Undefined variables return null.
*
- * @param string $name Variable name to retrieve
+ * @return null
*/
public function __get($name);
/**
- * Assign a single view variable
- *
- * @param string $name Variable name to set
- * @param mixed $value The value of $name
- */
- public function __set($name, $value);
-
- /**
* Accesses a helper object from within a template.
*
* @param string $name The helper name.
$this->assertEquals('test', $this->_view->publicVar);
}
+ public function testAssign()
+ {
+ $this->_view->assign(array('publicVar' => 'test'));
+ $this->assertEquals('test', $this->_view->publicVar);
+ }
+
+ public function testAssignDoesntOverridePrivateVariables()
+ {
+ try {
+ $this->_view->assign(array('_templatePath' => 'test'));
+ } catch (Exception $e) {
+ return;
+ }
+ $this->fail('Overwriting a private/protected variable should fail');
+ }
+
+ public function testAssignAllowsUnderscoreVariables()
+ {
+ $this->_view->assign(array('_private' => 'test'));
+ $this->assertEquals('test', $this->_view->_private);
+ }
+
// test accessing variable
public function testAccessVar()
{