[eluser]wiredesignz[/eluser]
Code:
<?php
/**
* Data Storage Object PHP5
*
* This library can be used to store and retrieve sets of data.
*
* Use in views or anywhere where you may have an incomplete dataset
* it will prevent undefined variable errors. ie: Use in forms during insert.
*
* Example:
* $user = new DataStore($this->user_model->get('Admin'));
* $user->languages = $this->language_model->get($user->id);
*
* @version: 0.2 (c) Wiredesignz 2008-09-10
*/
class DataStore
{
private $datastore;
public function __construct($data = array())
{
$this->datastore = $data;
}
public function __set($key, $data = NULL)
{
if (is_array($this->datastore))
$this->datastore[$key] = $data;
if (is_object($this->datastore))
$this->datastore->$key = $data;
}
public function __get($key)
{
if (is_array($this->datastore) AND isset($this->datastore[$key]))
return $this->datastore[$key];
if (is_object($this->datastore) AND isset($this->datastore->$key))
return $this->datastore->$key;
return NULL;
}
}