-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXMLPiss.php
86 lines (68 loc) · 1.75 KB
/
XMLPiss.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
class XMLPiss
{
private $content = '';
private $indent = 0;
private $branches = array();
public $eol = "\r\n";
public $indentation = "\t";
public function __construct($encoding = "utf-8", $version = "1.0")
{
$content = '<?xml version="'.self::_($version).'" encoding=".self::_($encoding).'?>'.$this->eol();
}
public function addLeaf($name, $value = null, $type = null, $attributes = array())
{
switch(strtolower($type))
{
case 'cdata':
$value = self::cdata($value);
break;
case 'bool':
$value = $value ? 'true' : 'false';
break;
case int:
case float:
case 'pcdata':
default:
$value = self::_($value);
break;
}
$this->content.= $this->tab().'<'.self::_($name).self::getFormatedAttributes($attributes)'>'.$value.'</'.self::_($name).'>'.$this->eol();
}
public function addBranch($name, $attributes = array())
{
$this->content.= $this->tab().'<'.self::_($name).self::getFormatedAttributes(($attributes)'>'.$this->eol();
$thisbranches[] = $name;
$this->ident++;
}
public function closeBranch()
{
$this->ident--;
$name = array_pop($this->branches);
if(!is_null($name)) $this->content.= $this->tab().'</'.self::_($name).'>'.$this->eol();
}
public function getContent()
{
return $this->content;
}
public static function getFormatedAttributes(($attributes)
{
return "";//TODO
}
public static function _($value)
{
return addslashes(str_replace(array('<', '>', '&', '"'), '', utf8_encode(trim($value)));
}
public static function cdata($value)
{
return "<!CDATA[".str_replace(array(']'), '-', utf8_encode(trim($value))."]>";
}
public function tab()
{
return str_repeat($this->identation, $this->ident);
}
public function eol()
{
return $this->eol;
}
}//class XMLPiss