1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TERYT-API |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* @author Marcin Pudełek <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace mrcnpdlk\Teryt; |
15
|
|
|
|
16
|
|
|
use DOMDocument; |
17
|
|
|
use DOMXPath; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see https://github.com/robrichards/wse-php/issues/31 |
21
|
|
|
*/ |
22
|
|
|
class WSASoap |
23
|
|
|
{ |
24
|
|
|
const WSANS = 'http://www.w3.org/2005/08/addressing'; |
25
|
|
|
const WSAPFX = 'wsa'; |
26
|
|
|
/** |
27
|
|
|
* @var string|null |
28
|
|
|
*/ |
29
|
|
|
private $soapNS; |
30
|
|
|
/** |
31
|
|
|
* @var string|null |
32
|
|
|
*/ |
33
|
|
|
private $soapPFX; |
34
|
|
|
/** |
35
|
|
|
* @var \DOMDocument|null |
36
|
|
|
*/ |
37
|
|
|
private $soapDoc = null; |
38
|
|
|
/** |
39
|
|
|
* @var \DOMElement|null |
40
|
|
|
*/ |
41
|
|
|
private $envelope = null; |
42
|
|
|
/** |
43
|
|
|
* @var \DOMXPath|null |
44
|
|
|
*/ |
45
|
|
|
private $SOAPXPath = null; |
46
|
|
|
/** |
47
|
|
|
* @var \DOMElement|\DOMNode|null |
48
|
|
|
*/ |
49
|
|
|
private $header = null; |
50
|
|
|
|
51
|
11 |
|
public function __construct(DOMDocument $doc) |
52
|
|
|
{ |
53
|
11 |
|
$this->soapDoc = $doc; |
54
|
11 |
|
$this->envelope = $doc->documentElement; |
55
|
11 |
|
$this->soapNS = $this->envelope->namespaceURI; |
56
|
11 |
|
$this->soapPFX = $this->envelope->prefix; |
57
|
11 |
|
$this->SOAPXPath = new DOMXPath($doc); |
58
|
11 |
|
$this->SOAPXPath->registerNamespace('wssoap', $this->soapNS); |
59
|
11 |
|
$this->SOAPXPath->registerNamespace('wswsa', static::WSANS); |
60
|
11 |
|
$this->envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . self::WSAPFX, static::WSANS); |
61
|
11 |
|
$this->locateHeader(); |
62
|
11 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $action |
66
|
|
|
*/ |
67
|
11 |
|
public function addAction($action): void |
68
|
|
|
{ |
69
|
|
|
/* Add the WSA Action */ |
70
|
11 |
|
$header = $this->locateHeader(); |
71
|
11 |
|
$nodeAction = $this->soapDoc->createElementNS(static::WSANS, self::WSAPFX . ':Action', $action); |
|
|
|
|
72
|
11 |
|
$header->appendChild($nodeAction); |
73
|
11 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return \DOMDocument |
77
|
|
|
*/ |
78
|
11 |
|
public function getDoc(): DOMDocument |
79
|
|
|
{ |
80
|
11 |
|
return $this->soapDoc; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return \DOMElement|\DOMNode |
85
|
|
|
*/ |
86
|
11 |
|
private function locateHeader() |
87
|
|
|
{ |
88
|
11 |
|
if (null === $this->header) { |
89
|
11 |
|
$headers = $this->SOAPXPath->query('//wssoap:Envelope/wssoap:Header'); |
|
|
|
|
90
|
11 |
|
$header = $headers->item(0); |
91
|
11 |
|
if (!$header) { |
92
|
11 |
|
$header = $this->soapDoc->createElementNS($this->soapNS, $this->soapPFX . ':Header'); |
93
|
11 |
|
$this->envelope->insertBefore($header, $this->envelope->firstChild); |
|
|
|
|
94
|
|
|
} |
95
|
11 |
|
$this->header = $header; |
96
|
|
|
} |
97
|
|
|
|
98
|
11 |
|
return $this->header; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.