Source for file Data.php
Documentation is available at Data.php
* dwoo data object, use it for complex data assignments or if you want to easily pass it
* around multiple functions to avoid passing an array by reference
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
class Dwoo_Data implements Dwoo_IDataProvider
protected $data =
array();
* clears a the entire data or only the given key
* @param array|string$name clears only one value if you give a name, multiple values if
* you give an array of names, or the entire data if left null
public function clear($name =
null)
foreach ($name as $index)
unset
($this->data[$index]);
unset
($this->data[$name]);
* overwrites the entire data with the given array
* @param array $data the new data array to use
public function setData(array $data)
* merges the given array(s) with the current data with array_merge
* @param array $data the array to merge
* @param array $data2 $data3 ... other arrays to merge, optional, etc.
public function mergeData(array $data)
while (list
(,$v) =
each($args)) {
$this->data =
array_merge($this->data, $v);
* assigns a value or an array of values to the data object
* @param array|string$name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
public function assign($name, $val =
null)
while (list
($k,$v) =
each($name))
$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)
* assigns a value by reference to the data object
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign by reference
$this->data[$name] =
& $val;
* appends values or an array of values to the data object
* @param array|string$name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
* @param bool $merge true to merge data or false to append, defaults to false
public function append($name, $val =
null, $merge =
false)
foreach ($name as $key=>
$val) {
if ($merge ===
true &&
is_array($val)) {
$this->data[$key] =
$val +
$this->data[$key];
$this->data[$key][] =
$val;
} elseif ($val !==
null) {
if ($merge ===
true &&
is_array($val)) {
$this->data[$name] =
$val +
$this->data[$name];
$this->data[$name][] =
$val;
* appends a value by reference to the data object
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to append by reference
* @param bool $merge true to merge data or false to append, defaults to false
public function appendByRef($name, &$val, $merge =
false)
if ($merge ===
true &&
is_array($val)) {
foreach ($val as $key =>
&$val) {
$this->data[$name][$key] =
& $val;
$this->data[$name][] =
& $val;
* returns true if the variable has been assigned already, false otherwise
* @param string $name the variable name
return isset
($this->data[$name]);
* supports calls to isset($dwooData->var)
* @param string $name the variable name
return isset
($this->data[$name]);
* unassigns/removes a variable
* @param string $name the variable name
unset
($this->data[$name]);
* supports unsetting variables using the object syntax
* @param string $name the variable name
unset
($this->data[$name]);
* returns a variable if it was assigned
* @param string $name the variable name
public function get($name)
return $this->__get($name);
* allows to read variables using the object syntax
* @param string $name the variable name
public function __get($name)
if (isset
($this->data[$name])) {
return $this->data[$name];
throw
new Dwoo_Exception('Tried to read a value that was not assigned yet : "'.
$name.
'"');
Documentation generated on Sat, 18 Jul 2009 21:04:49 +0200 by phpDocumentor 1.4.0