mirror of
https://github.com/e107inc/e107.git
synced 2025-08-17 20:01:47 +02:00
e_vars (simple parser object) now inherits e_object, magic getters/setters moved to e_object, convenient toSc method added (will be used more wisely from model based classes in the future)
This commit is contained in:
@@ -128,6 +128,15 @@ class e_object
|
||||
return (isset($this->_data[$key]) ? $this->_data[$key] : $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object data
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite data in the object for a single field.
|
||||
*
|
||||
@@ -140,6 +149,53 @@ class e_object
|
||||
$this->_data[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set object data
|
||||
* @return e_object
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update object data
|
||||
* @return e_object
|
||||
*/
|
||||
public function addData($data)
|
||||
{
|
||||
foreach($data as $key => $val)
|
||||
{
|
||||
$this->set($key, $val);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove object data key
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return e_object
|
||||
*/
|
||||
public function remove($key, $value)
|
||||
{
|
||||
unset($this->_data[$key]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset object data key
|
||||
*
|
||||
* @return e_object
|
||||
*/
|
||||
public function removeData()
|
||||
{
|
||||
$this->_data = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if key is set
|
||||
@@ -161,6 +217,15 @@ class e_object
|
||||
return (isset($this->_data[$key]) && !empty($this->_data[$key]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object has data
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasData()
|
||||
{
|
||||
return !empty($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parameter array
|
||||
* @param array $params
|
||||
@@ -226,6 +291,15 @@ class e_object
|
||||
return (isset($this->_params[$key]) ? $this->_params[$key] : $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert object data to simple shortcodes (e_vars object)
|
||||
* @return string
|
||||
*/
|
||||
public function toSc()
|
||||
{
|
||||
return new e_vars($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert object data to array
|
||||
* @return string
|
||||
@@ -278,6 +352,61 @@ class e_object
|
||||
{
|
||||
return $this->toString(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic setter
|
||||
* Triggered on e.g. <code><?php $e_object->myKey = 'someValue'; </code>
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
// Unset workaround - PHP < 5.1.0
|
||||
if(null === $value) $this->remove($key);
|
||||
else $this->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter
|
||||
* Triggered on e.g. <code><?php print($e_object->myKey); </code>
|
||||
* @param string $key
|
||||
* @return mixed value or null if key not found
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
if($this->is($key))
|
||||
{
|
||||
return $this->get($key);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to check if given data key is set.
|
||||
* Triggered on <code><?php isset($e_object->myKey); </code>
|
||||
* NOTE: works on PHP 5.1.0+
|
||||
*
|
||||
* @param string $key
|
||||
* @return boolean
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
return $this->is($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to unset given data key.
|
||||
* Triggered on <code><?php unset($e_object->myKey); </code>
|
||||
* NOTE: works on PHP 5.1.0+
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
$this->remove($key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user