Commit f24d504d by Seldaek

+ Added magic object-access methods to Dwoo_Data, so you can assign values by

doing $data->var = $val; instead of $data->assign('var', $val); + Added get()/unassign()/isAssigned() methods to read, remove and check for the presence of a var inside a Dwoo_Data object git-svn-id: svn://dwoo.org/dwoo/trunk@98 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent d0cce28f
...@@ -101,6 +101,17 @@ class Dwoo_Data implements Dwoo_IDataProvider ...@@ -101,6 +101,17 @@ class Dwoo_Data implements Dwoo_IDataProvider
$this->data[$name] = $val; $this->data[$name] = $val;
} }
} }
/**
* allows to assign variables using the object syntax
*
* @param string $name the variable name
* @param string $value the value to assign to it
*/
public function __set($name, $value)
{
$this->assign($name, $value);
}
/** /**
* assigns a value by reference to the data object * assigns a value by reference to the data object
...@@ -172,4 +183,71 @@ class Dwoo_Data implements Dwoo_IDataProvider ...@@ -172,4 +183,71 @@ class Dwoo_Data implements Dwoo_IDataProvider
$this->data[$name][] =& $val; $this->data[$name][] =& $val;
} }
} }
/**
* returns true if the variable has been assigned already, false otherwise
*
* @param string $name the variable name
* @return bool
*/
public function isAssigned($name)
{
return isset($this->data[$name]);
}
/**
* supports calls to isset($dwooData->var)
*
* @param string $name the variable name
*/
public function __isset($name)
{
return isset($this->data[$name]);
}
/**
* unassigns/removes a variable
*
* @param string $name the variable name
*/
public function unassign($name)
{
unset($this->data[$name]);
}
/**
* supports unsetting variables using the object syntax
*
* @param string $name the variable name
*/
public function __unset($name)
{
unset($this->data[$name]);
}
/**
* returns a variable if it was assigned
*
* @param string $name the variable name
* @return mixed
*/
public function get($name)
{
return $this->__get($name);
}
/**
* allows to read variables using the object syntax
*
* @param string $name the variable name
* @return mixed
*/
public function __get($name)
{
if (isset($this->data[$name])) {
return $this->data[$name];
} else {
throw new Dwoo_Exception('Tried to read a value that was not assigned yet : "'.$name.'"');
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment