2010-06-06 16:05:46 +02:00
|
|
|
<?php
|
2010-07-21 12:44:01 +02:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2010, The volkszaehler.org project
|
2010-07-22 10:32:51 +02:00
|
|
|
* @package default
|
2010-07-21 12:44:01 +02:00
|
|
|
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
|
2010-06-06 16:05:46 +02:00
|
|
|
*
|
2010-07-21 12:44:01 +02:00
|
|
|
* This file is part of volkzaehler.org
|
|
|
|
*
|
|
|
|
* volkzaehler.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* volkzaehler.org is distributed in the hope that it will be useful,
|
2010-06-06 16:05:46 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-07-21 12:44:01 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-06-06 16:05:46 +02:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2010-07-21 12:44:01 +02:00
|
|
|
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
2010-06-06 16:05:46 +02:00
|
|
|
*/
|
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
namespace Volkszaehler\View\XML;
|
2010-07-18 17:12:00 +02:00
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
use Volkszaehler\View\HTTP;
|
|
|
|
use Volkszaehler\View;
|
2010-07-20 19:10:45 +02:00
|
|
|
use Volkszaehler\Util;
|
|
|
|
|
2010-07-22 10:32:51 +02:00
|
|
|
/**
|
|
|
|
* XML view
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <info@steffenvogel.de>
|
|
|
|
* @package default
|
|
|
|
*/
|
2010-07-22 16:10:08 +02:00
|
|
|
abstract class XMLView extends View\View {
|
2010-07-20 11:58:39 +02:00
|
|
|
protected $xmlDoc;
|
2010-06-11 23:17:05 +02:00
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
public function __construct(HTTP\Request $request, HTTP\Response $response) {
|
2010-07-20 11:58:39 +02:00
|
|
|
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-21 12:44:01 +02:00
|
|
|
|
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-21 12:44:01 +02:00
|
|
|
|
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-21 12:44:01 +02:00
|
|
|
|
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-21 12:44:01 +02:00
|
|
|
|
2010-07-20 22:43:08 +02:00
|
|
|
// TODO add queries to xml debug
|
|
|
|
// TODO add messages to xml output
|
2010-07-21 12:44:01 +02:00
|
|
|
|
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-07-21 12:44:01 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-22 10:32:51 +02:00
|
|
|
?>
|