2010-06-06 16:05:46 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License (either version 2 or
|
|
|
|
* version 3) as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
* For more information on the GPL, please go to:
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
2010-07-20 11:58:39 +02:00
|
|
|
namespace Volkszaehler\View\Xml;
|
2010-07-18 17:12:00 +02:00
|
|
|
|
2010-07-20 19:10:45 +02:00
|
|
|
use Volkszaehler\Util;
|
|
|
|
|
2010-07-20 12:06:04 +02:00
|
|
|
abstract class Xml extends \Volkszaehler\View\View {
|
2010-07-20 11:58:39 +02:00
|
|
|
protected $xmlDoc;
|
2010-06-11 23:17:05 +02:00
|
|
|
|
2010-07-20 11:58:39 +02:00
|
|
|
public function __construct(\Volkszaehler\View\Http\Request $request, \Volkszaehler\View\Http\Response $response) {
|
|
|
|
parent::__construct($request, $response);
|
|
|
|
|
|
|
|
$this->xmlDoc = new \DOMDocument('1.0', 'UTF-8');
|
|
|
|
|
|
|
|
$this->xmlRoot = $this->xmlDoc->createElement('volkszaehler');
|
|
|
|
$this->xmlRoot->setAttribute('version', \Volkszaehler\VERSION);
|
2010-06-08 15:39:31 +02:00
|
|
|
|
2010-07-20 11:58:39 +02:00
|
|
|
$this->xmlRoot->appendChild($this->xmlDoc->createElement('source', 'volkszaehler.org'));
|
|
|
|
|
|
|
|
$this->response->setHeader('Content-type', 'application/xml; charset=UTF-8');
|
2010-06-08 15:39:31 +02:00
|
|
|
}
|
|
|
|
|
2010-06-11 23:17:05 +02:00
|
|
|
public function render() {
|
2010-07-20 11:58:39 +02:00
|
|
|
$this->xmlDoc->appendChild($this->xmlRoot);
|
2010-06-11 23:17:05 +02:00
|
|
|
echo $this->xmlDoc->saveXML();
|
2010-07-20 12:06:04 +02:00
|
|
|
|
|
|
|
parent::render();
|
2010-06-11 23:17:05 +02:00
|
|
|
}
|
2010-06-08 15:39:31 +02:00
|
|
|
|
2010-07-20 11:58:39 +02:00
|
|
|
public function addException(\Exception $exception) {
|
2010-06-11 23:17:05 +02:00
|
|
|
$xmlException = $this->xmlDoc->createElement('exception');
|
2010-06-08 15:39:31 +02:00
|
|
|
$xmlException->setAttribute('code', $exception->getCode());
|
2010-06-11 23:17:05 +02:00
|
|
|
$xmlException->appendChild($this->xmlDoc->createElement('message', $exception->getMessage()));
|
|
|
|
$xmlException->appendChild($this->xmlDoc->createElement('line', $exception->getLine()));
|
|
|
|
$xmlException->appendChild($this->xmlDoc->createElement('file', $exception->getFile()));
|
|
|
|
$xmlException->appendChild($this->fromTrace($exception->getTrace()));
|
2010-06-08 15:39:31 +02:00
|
|
|
|
2010-07-20 11:58:39 +02:00
|
|
|
$this->xmlRoot->appendChild($xmlException);
|
|
|
|
}
|
|
|
|
|
2010-07-20 22:43:08 +02:00
|
|
|
public function addDebug(Util\Debug $debug) {
|
2010-07-20 11:58:39 +02:00
|
|
|
$xmlDebug = $this->xmlDoc->createElement('debug');
|
|
|
|
|
2010-07-20 22:43:08 +02:00
|
|
|
$xmlDebug->appendChild($this->xmlDoc->createElement('time', $debug->getExecutionTime()));
|
2010-07-20 19:10:45 +02:00
|
|
|
$xmlDebug->appendChild($this->xmlDoc->createElement('database', Util\Configuration::read('db.driver')));
|
2010-07-20 11:58:39 +02:00
|
|
|
|
2010-07-20 22:43:08 +02:00
|
|
|
// TODO add queries to xml debug
|
|
|
|
// TODO add messages to xml output
|
2010-07-20 11:58:39 +02:00
|
|
|
|
|
|
|
$this->xmlRoot->appendChild($xmlDebug);
|
2010-06-08 15:39:31 +02:00
|
|
|
}
|
|
|
|
|
2010-06-11 23:17:05 +02:00
|
|
|
private function fromTrace($traces) {
|
|
|
|
$xmlTraces = $this->xmlDoc->createElement('backtrace');
|
2010-06-06 16:05:46 +02:00
|
|
|
|
2010-06-08 15:39:31 +02:00
|
|
|
foreach ($traces as $step => $trace) {
|
2010-06-11 23:17:05 +02:00
|
|
|
$xmlTrace = $this->xmlDoc->createElement('trace');
|
2010-06-08 15:39:31 +02:00
|
|
|
$xmlTraces->appendChild($xmlTrace);
|
|
|
|
$xmlTrace->setAttribute('step', $step);
|
2010-06-06 16:05:46 +02:00
|
|
|
|
2010-06-08 15:39:31 +02:00
|
|
|
foreach ($trace as $key => $value) {
|
|
|
|
switch ($key) {
|
|
|
|
case 'args':
|
2010-06-11 23:17:05 +02:00
|
|
|
$xmlArgs = $this->xmlDoc->createElement($key);
|
2010-06-08 15:39:31 +02:00
|
|
|
$xmlTrace->appendChild($xmlArgs);
|
|
|
|
foreach ($value as $arg) {
|
2010-07-20 22:43:08 +02:00
|
|
|
$xmlArgs->appendChild($this->xmlDoc->createElement('arg', (is_scalar($value)) ? $value : print_r($value, TRUE)));
|
2010-06-08 15:39:31 +02:00
|
|
|
}
|
|
|
|
break;
|
2010-06-11 23:17:05 +02:00
|
|
|
|
|
|
|
case 'type':
|
|
|
|
case 'function':
|
|
|
|
case 'line':
|
|
|
|
case 'file':
|
|
|
|
case 'class':
|
|
|
|
default:
|
|
|
|
$xmlTrace->appendChild($this->xmlDoc->createElement($key, $value));
|
2010-06-08 15:39:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-06 16:05:46 +02:00
|
|
|
|
2010-06-08 15:39:31 +02:00
|
|
|
return $xmlTraces;
|
2010-06-06 16:05:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|