mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
- 아래에 이미 author 언급이 있으므로 중복되는 저작권 표기는 제거 - 클래스 하단에 불필요한 end of file 표시 제거 (파일 하나에 클래스 하나씩이므로 파일이 중간에 끊겼다면 클래스가 닫히지 않아 쉽게 알 수 있음)
64 lines
1.2 KiB
PHP
64 lines
1.2 KiB
PHP
<?php
|
|
|
|
class XMLDisplayHandler
|
|
{
|
|
|
|
/**
|
|
* Produce XML compliant content given a module object.\n
|
|
* @param ModuleObject $oModule the module object
|
|
* @return string
|
|
*/
|
|
function toDoc(&$oModule)
|
|
{
|
|
$variables = $oModule->getVariables();
|
|
|
|
$xmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n";
|
|
$xmlDoc .= sprintf("<error>%s</error>\n", escape($oModule->getError()));
|
|
$xmlDoc .= sprintf("<message>%s</message>\n", escape($oModule->getMessage()));
|
|
|
|
$xmlDoc .= $this->_makeXmlDoc($variables);
|
|
|
|
$xmlDoc .= "</response>";
|
|
|
|
return $xmlDoc;
|
|
}
|
|
|
|
/**
|
|
* produce XML code given variable object\n
|
|
* @param object $obj
|
|
* @return string
|
|
*/
|
|
function _makeXmlDoc($obj)
|
|
{
|
|
if(!count($obj))
|
|
{
|
|
return;
|
|
}
|
|
|
|
$xmlDoc = '';
|
|
|
|
foreach($obj as $key => $val)
|
|
{
|
|
if(is_numeric($key))
|
|
{
|
|
$key = 'item';
|
|
}
|
|
|
|
if(is_string($val))
|
|
{
|
|
$xmlDoc .= sprintf('<%s>%s</%s>%s', $key, escape($val), $key, "\n");
|
|
}
|
|
else if(!is_array($val) && !is_object($val))
|
|
{
|
|
$xmlDoc .= sprintf('<%s>%s</%s>%s', $key, escape($val), $key, "\n");
|
|
}
|
|
else
|
|
{
|
|
$xmlDoc .= sprintf('<%s>%s%s</%s>%s', $key, "\n", $this->_makeXmlDoc($val), $key, "\n");
|
|
}
|
|
}
|
|
|
|
return $xmlDoc;
|
|
}
|
|
|
|
}
|