FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Xml.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class Xml extends \Rsi\Fred\Controller\View{
6 
7  public function xmlEncode($parent,$data){
8  $array = false;
9  foreach($data as $key => $value)
10  if($array = !\Rsi\Xml::validTag($key)){
11  $parent['type'] = 'array';
12  break;
13  }
14  foreach($data as $key => $value){
15  $name = $array ? 'item' : $key;
16  if(is_array($value)){
17  $child = $parent->addChild($name ?: 'null');
18  if(!$name) $child['null'] = 'true';
19  $this->xmlEncode($child,$value);
20  }
21  else{
22  $type = null;
23  if($value === null) $type = null;
24  elseif(is_bool($value)){
25  $type = 'bool';
26  $value = \Rsi\Str::bool($value);
27  }
28  elseif(is_int($value)) $type = 'int';
29  elseif(is_float($value)) $type = 'float';
30  else $value = htmlspecialchars($value);
31  $child = $parent->addChild($name ?: 'null',$value);
32  if(!$name) $child['null'] = 'true';
33  if($type) $child['type'] = $type;
34  }
35  if($array) $child['key'] = $key;
36  }
37  }
38 
39  public function render(){
40  if(!headers_sent()) header('Content-type: application/xml; charset=utf-8');
41  $this->xmlEncode($root = new \SimpleXmlElement('<config />'),$this->data);
42  print($root->asXML());
43  }
44 
45 }
xmlEncode($parent, $data)
Definition: Xml.php:7