| author | Bashkim Isai |
|---|---|
| package | Core |
In file D:\oblib-core\php\oblib\data.abstract.php between lines 52 and 270.
<?php
/**
* The main class of the ObLib Architecture. Controls outputting
* objects (of differing types) to an XML format that can be parsed
* by the XSL Transformer.
*
* @author Bashkim Isai
* @package Core
* @see Class [DOMDocument]
* @see Class [DOMNode]
*/
abstract class data
{
/**
* Saves the Tag Name for the DOMNode
*
* @type String
* @see Class [DOMNode]
*/
private $_strNodeName;
/**
* Saves the Attributes for the DOMNode
*
* @type Array[String => String]
* @see Class [DOMNode]
* @see Property [data __getAttribute]
* @see Property [data __hasAttribute]
* @see Property [data __setAttribute]
* @see Property [data __removeAttribute]
*/
private $_arrAttributes = Array ();
/**
* Saves the Node Name for this object for sleeping
*
* @type String
* @see Method [data __sleep]
*/
public $slp_strNodeName;
/**
* Saves the Attributes for this object for sleeping
*
* @type Array [String => String]
* @see Method [data __sleep]
*/
public $slp_arrAttributes;
/**
* Saves the requested Tag Name for the DOMNode. Takes one parameter
* being the DOMNode tag name.
*
* @see Class [DOMNode]
* @see Property [data _strNodeName]
* @return Void
*/
function __construct ($strNodeName)
{
$this->_strNodeName = $strNodeName;
}
/**
* Returns the tag name for the DOMNode that will be outputted for
* this object
*
* @see Class [DOMNode]
* @see Property [data _strNodeName]
* @return String
*/
public function ___Name ()
{
if (!$this->_strNodeName)
{
throw new ExceptionCore ('This object was not instantiated properly, therefore the Tag Name can not be Retrieved');
}
return $this->_strNodeName;
}
/**
* Gets an attribute to be assigned to the outputted DOMNode
*
* @see Class [DOMNode]
* @see Property [data _arrAttributes]
* @return Mix
*/
protected function &___getAttribute ($strAttrName)
{
return $this->_arrAttributes [$strAttrName];
}
/**
* Checks to see if an attribute has been assigned by name
*
* @see Class [DOMNode]
* @see Property [data _arrAttributes]
* @return Boolean
*/
protected function ___hasAttribute ($strAttrName)
{
return isset ($this->_arrAttributes [$strAttrName]);
}
/**
* Sets the value of an attribute to be attached to a DOMNode outout
*
* @see Class [DOMNode]
* @see Property [data _arrAttributes]
* @return Mix
*/
protected function &___setAttribute ($strAttrName, $mixAttrValue)
{
$this->_arrAttributes [$strAttrName] = $mixAttrValue;
return $this->_arrAttributes [$strAttrName];
}
/**
* Removes an attribute that would have been attached to a DOMNode outout
*
* @see Class [DOMNode]
* @see Property [data _arrAttributes]
* @return Void
*/
protected function ___removeAttribute ($strAttrName)
{
unset ($this->_arrAttributes [$strAttrName]);
}
/**
* Outputs an ObLib object (data*) as an XML DOMNode. This method is the
* core for parent objects of data to setup the output of an object.
*
* @see Class [DOMNode]
* @see Class [DOMDocument]
* @return Class [DOMNode]
*/
public function &___Render (DOMNode $domParent=NULL)
{
if ($domParent === NULL)
{
$domDocument = new DOMDocument ('1.0', 'UTF-8');
$domDocument->formatOutput = TRUE;
$domDocument->preserveWhiteSpace = FALSE;
$domElement = $domDocument->appendChild (
$domDocument->createElement ($this->_strNodeName)
);
}
else
{
$domElement = $domParent->appendChild (
$domParent->ownerDocument->createElement ($this->_strNodeName)
);
}
foreach ($this->_arrAttributes as $strAttrName => $mixAttrValue)
{
if ($mixAttrValue !== NULL)
{
$domElement->setAttribute ($strAttrName, $mixAttrValue);
}
}
return $domElement;
}
/**
* Used for debugging purposes. Outputs the current object as a
* text-based representation of an XML object
*
* @see Method [data ___Render]
* @see Method [DOMDocument SaveXML]
* @return String
*/
function __toString ()
{
return '<pre>' . htmlentities ($this->___Render ()->ownerDocument->SaveXML ()) . '</pre>';
}
/**
* Converts private variables to public to allow the object to be put to sleep
*
* @see Property [data slp_strNodeName]
* @see Property [data slp_arrAttributes]
* @return Array [(int) => String]
*/
function __sleep ()
{
$this->slp_strNodeName = $this->_strNodeName;
$this->slp_arrAttributes = $this->_arrAttributes;
return Array (
'slp_strNodeName',
'slp_arrAttributes'
);
}
/**
* Converts public variables back to private variables to allow information
* to be managed after 'waking up'
*
* @see Property [data slp_strNodeName]
* @see Property [data slp_arrAttributes]
* @return Void
*/
function __wakeup ()
{
$this->_strNodeName = $this->slp_strNodeName;
$this->_arrAttributes = $this->slp_arrAttributes;
$this->slp_strNodeName = NULL;
$this->slp_arrAttributes = NULL;
}
}
?>