-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXml.php
More file actions
90 lines (69 loc) · 1.74 KB
/
Xml.php
File metadata and controls
90 lines (69 loc) · 1.74 KB
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
87
88
89
90
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/main/blob/master/LICENSE
*/
namespace Quid\Main;
use Quid\Base;
// xml
// class that provides basic methods to make an XML sitemap
class Xml extends Root
{
// config
protected static array $config = [];
// dynamique
protected \SimpleXMLElement $xml; // garde une copie de l'objet simpleXml
// construct
// construit l'objet xml, le urlset doit être fourni en argument
final public function __construct(string $urlset)
{
$urlset = Base\Xml::urlset($urlset) ?? $urlset;
$this->xml = new \SimpleXMLElement($urlset);
}
// toString
// retourne le output du xml
final public function __toString():string
{
return $this->output();
}
// clone
// clone est permis
final public function __clone()
{
return;
}
// cast
// retourne le output du xml
final public function _cast()
{
return $this->output();
}
// xml
// retourne l'objet simpleXml
final public function xml():\SimpleXMLElement
{
return $this->xml;
}
// output
// output le xml en string
final public function output():string
{
return $this->xml->asXML();
}
// sitemap
// ajoute des uris dans le document xml
// utilisé pour générer un sitemap
final public function sitemap(string ...$values):self
{
$xml = $this->xml();
foreach ($values as $value)
{
$child = $xml->addChild('url');
$child->addChild('loc',$value);
}
return $this;
}
}
?>