1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2013-2016 |
4
|
|
|
* Piotr Olaszewski <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
14
|
|
|
* all copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
namespace WSDL\XML; |
25
|
|
|
|
26
|
|
|
use DOMAttr; |
27
|
|
|
use DOMDocument; |
28
|
|
|
use DOMElement; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* XMLAttributeHelper |
32
|
|
|
* |
33
|
|
|
* @author Piotr Olaszewski <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class XMLAttributeHelper |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var DOMDocument |
39
|
|
|
*/ |
40
|
|
|
private $DOMDocument; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param DOMDocument $DOMDocument |
44
|
|
|
*/ |
45
|
11 |
|
public function __construct(DOMDocument $DOMDocument) |
46
|
|
|
{ |
47
|
11 |
|
$this->DOMDocument = $DOMDocument; |
48
|
11 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $elementName |
52
|
|
|
* @param array $attributes |
53
|
|
|
* @param string $value |
54
|
|
|
* @return DOMElement |
55
|
|
|
*/ |
56
|
11 |
|
public function createElementWithAttributes($elementName, array $attributes, $value = '') |
57
|
|
|
{ |
58
|
11 |
|
$element = $this->createElement($elementName, $value); |
59
|
11 |
|
foreach ($attributes as $attributeName => $attributeValue) { |
60
|
11 |
|
$tmpAttr = $this->createAttributeWithValue($attributeName, $attributeValue); |
61
|
11 |
|
$element->appendChild($tmpAttr); |
62
|
11 |
|
} |
63
|
11 |
|
return $element; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $attributeName |
68
|
|
|
* @param string $value |
69
|
|
|
* @return DOMAttr |
70
|
|
|
*/ |
71
|
11 |
|
public function createAttributeWithValue($attributeName, $value) |
72
|
|
|
{ |
73
|
11 |
|
$attribute = $this->DOMDocument->createAttribute($attributeName); |
74
|
11 |
|
$attribute->value = $value; |
75
|
11 |
|
return $attribute; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $elementName |
80
|
|
|
* @param string $value |
81
|
|
|
* @return DOMElement |
82
|
|
|
*/ |
83
|
11 |
|
public function createElement($elementName, $value = '') |
84
|
|
|
{ |
85
|
11 |
|
return $this->DOMDocument->createElement($elementName, $value); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param DOMDocument $DOMDocument |
90
|
|
|
* @return XMLAttributeHelper |
91
|
|
|
*/ |
92
|
11 |
|
public static function forDOM(DOMDocument $DOMDocument) |
93
|
|
|
{ |
94
|
11 |
|
return new self($DOMDocument); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|