|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* KNUT7 K7F (https://marciozebedeu.com/) |
|
5
|
|
|
* KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/) |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under The MIT License |
|
8
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
10
|
|
|
* |
|
11
|
|
|
* @link https://github.com/knut7/framework/ for the canonical source repository |
|
12
|
|
|
* @copyright (c) 2015. KNUT7 Software Technologies AO Inc. (https://marciozebedeu.com/) |
|
13
|
|
|
* @license https://marciozebedeu.com/license/new-bsd New BSD License |
|
14
|
|
|
* @author Marcio Zebedeu - [email protected] |
|
15
|
|
|
* @version 1.0.2 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Ballybran\Core\Http; |
|
19
|
|
|
|
|
20
|
|
|
class Encodes extends EncodeText |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
public static function parse($arr) |
|
25
|
|
|
{ |
|
26
|
|
|
$dom = new \DOMDocument(self::$version); |
|
27
|
|
|
self::recursiveParser($dom, $arr, $dom); |
|
28
|
|
|
return $dom->saveXML(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
private static function recursiveParser(&$root, $arr, &$dom) |
|
32
|
|
|
{ |
|
33
|
|
|
foreach ($arr as $key => $item) { |
|
34
|
|
|
if (is_array($item) && !is_numeric($key)) { |
|
35
|
|
|
$node = $dom->createElement($key); |
|
36
|
|
|
self::recursiveParser($node, $item, $dom); |
|
37
|
|
|
return $root->appendChild($node); |
|
38
|
|
|
} elseif (is_array($item) && is_numeric($key)) { |
|
39
|
|
|
return self::recursiveParser($root, $item, $dom); |
|
40
|
|
|
} else { |
|
41
|
|
|
$node = $dom->createElement($key, $item); |
|
42
|
|
|
return $root->appendChild($node); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
} |