1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace StructType; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use WsdlToPhp\PackageBase\AbstractStructBase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This class stands for MessageXml StructType |
12
|
|
|
* @package Ews |
13
|
|
|
* @subpackage Structs |
14
|
|
|
* @author WsdlToPhp <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class EwsMessageXml extends AbstractStructBase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* The any |
20
|
|
|
* @var \DOMDocument|string|null |
21
|
|
|
*/ |
22
|
|
|
protected $any = null; |
23
|
|
|
/** |
24
|
|
|
* Constructor method for MessageXml |
25
|
|
|
* @uses EwsMessageXml::setAny() |
26
|
|
|
* @param \DOMDocument|string|null $any |
27
|
|
|
*/ |
28
|
|
|
public function __construct($any = null) |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
|
|
->setAny($any); |
32
|
|
|
} |
33
|
|
|
/** |
34
|
|
|
* Get any value |
35
|
|
|
* @uses \DOMDocument::loadXML() |
36
|
|
|
* @param bool $asString true: returns XML string, false: returns \DOMDocument |
37
|
|
|
* @return \DOMDocument|string|null |
38
|
|
|
*/ |
39
|
|
|
public function getAny(bool $asDomDocument = false) |
40
|
|
|
{ |
41
|
|
|
$domDocument = null; |
42
|
|
|
if (!empty($this->any) && $asDomDocument) { |
43
|
|
|
$domDocument = new \DOMDocument('1.0', 'UTF-8'); |
44
|
|
|
$domDocument->loadXML($this->any); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
return $asDomDocument ? $domDocument : $this->any; |
47
|
|
|
} |
48
|
|
|
/** |
49
|
|
|
* Set any value |
50
|
|
|
* @uses \DOMDocument::hasChildNodes() |
51
|
|
|
* @uses \DOMDocument::saveXML() |
52
|
|
|
* @uses \DOMNode::item() |
53
|
|
|
* @param \DOMDocument|string|null $any |
54
|
|
|
* @return \StructType\EwsMessageXml |
55
|
|
|
*/ |
56
|
|
|
public function setAny($any = null): self |
57
|
|
|
{ |
58
|
|
|
// validation for constraint: xml |
59
|
|
|
if (!is_null($any) && !$any instanceof \DOMDocument && (!is_string($any) || (is_string($any) && (empty($any) || (($anyDoc = new \DOMDocument()) && false === $anyDoc->loadXML($any)))))) { |
|
|
|
|
60
|
|
|
throw new InvalidArgumentException(sprintf('Invalid value %s, please provide a valid XML string', var_export($any, true)), __LINE__); |
61
|
|
|
} |
62
|
|
|
$this->any = ($any instanceof \DOMDocument) ? $any->saveXML($any->hasChildNodes() ? $any->childNodes->item(0) : null) : $any; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|