| author | Bashkim Isai |
|---|---|
| package | Output |
In file D:\oblib-core\php\oblib\dataContent\dataController.controller.php between lines 52 and 210.
<?php
/**
* A dataController class is where all the processing for one single page
* will typically occur. It also handles any XSL styling information for
* outputting information to the browser.
*
* @author Bashkim Isai
* @package Output
* @see Class [dataSection]
* @see Class [dataObject]
*/
class dataController extends dataObject
{
/**
* An instance of the Section to be used for this Controller
*
* @type Object [typeOf dataSection]
* @see Class [DOMNode]
*/
private $_secSection;
/**
* Defines the default Section for a dataController
*
* @return String
*/
public function ___Section ()
{
return 'dataSection';
}
/**
* Constructs the basics for the dataController and the dataSection
*
* @see Class [data]
* @see Class [dataSection]
* @return Void
*/
final function __construct ()
{
parent::__construct ('Controller');
// Set the Type to the Class Type
$this->___setAttribute ('type', get_class ($this));
// Instantiate the Section
$strSection = $this->___Section ();
if (!class_exists ($strSection))
{
throw new ExceptionCore ('Section class not found: ' . $this->_strSection);
}
$this->_secSection = new $strSection ($this);
// Run the custom constructor
if (method_exists ($this, '___construct'))
{
$arrParam = func_get_args ();
call_user_func_array (
Array ($this, '___construct'),
$arrParam
);
}
// If this is a POST, run any post functions
if ($_SERVER ['REQUEST_METHOD'] == 'POST')
{
if (method_exists ($this, '___post'))
{
$this->___post ();
}
}
// Always run a GET function (unless POST redirects you)
if (method_exists ($this, '___get'))
{
$this->___get ();
}
}
/**
* Transforms the Controller into an XML Document, then generates the output from
* the XSL document
*
* @see Class [DOMDocument]
* @see Class [XSLTProcessor]
* @return Class [DOMDocument]
*/
final public function ___Transform ($strStyleSheet)
{
if (!file_exists ($strStyleSheet))
{
throw new ExceptionCore ('The XSL stylesheet does not exist: ' . $strStyleSheet);
}
$domStyleSheet = new DOMDocument ('1.0', 'UTF-8');
$domStyleSheet->Load ($strStyleSheet);
$xslStyleSheet = new XSLTProcessor ();
$xslStyleSheet->importStyleSheet ($domStyleSheet);
$domTransformation = $xslStyleSheet->transformToDoc (
$this->_secSection->___Render ()->ownerDocument
);
if (defined ('LANGUAGE'))
{
$domTransformation->documentElement->removeAttribute ('lang');
$dxpTransformation = new DOMXPath ($domTransformation);
$dnlLanguage = $dxpTransformation->Query ('//*[@lang]');
foreach ($dnlLanguage as $dnoLanguage)
{
if ($dnoLanguage->getAttribute ('lang') == LANGUAGE)
{
$dnoLanguage->removeAttribute ('lang');
}
else
{
$dnoLanguage->parentNode->removeChild ($dnoLanguage);
}
}
$domTransformation->documentElement->setAttribute ('lang', LANGUAGE);
}
return $domTransformation;
}
/**
* Runs a transformation, renders the output to XML/HTML and outputs to the browser
*
* @see Class [DOMDocument]
* @see Class [XSLTProcessor]
* @see Method [dataController Transform]
* @return String
*/
final public function ___Output ($strStyleSheet)
{
header ('X-PHP-Architecture: ObLib [http://www.phpoblib.com/]');
$domTransformation = $this->___Transform ($strStyleSheet);
$domTransformation->formatOutput = TRUE;
$domTransformation->preserveWhiteSpace = FALSE;
echo $domTransformation->saveXML ();
}
/**
* Outputs the Section/Controller to the Browser as an XML document without being Transformed by XSL
*
* @see Class [DOMDocument]
* @return String
*/
final function __toString ()
{
return '<pre>' . htmlentities ($this->_secSection->___Render ()->ownerDocument->SaveXML ()) . '</pre>';
}
}
?>