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 RobRichards\WsePhp\WSSESoap; |
17
|
|
|
|
18
|
|
|
class TerytSoapClient extends \SoapClient |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $username; |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $password; |
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
private $digest; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $username |
35
|
|
|
* @param string $password |
36
|
|
|
* @param bool $digest |
37
|
|
|
*/ |
38
|
11 |
|
public function addUserToken(string $username, string $password, bool $digest = false): void |
39
|
|
|
{ |
40
|
11 |
|
$this->username = $username; |
41
|
11 |
|
$this->password = $password; |
42
|
11 |
|
$this->digest = $digest; |
43
|
11 |
|
} |
44
|
|
|
|
45
|
|
|
/** @noinspection MagicMethodsValidityInspection */ |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $request |
49
|
|
|
* @param string $location |
50
|
|
|
* @param string $action |
51
|
|
|
* @param int $version |
52
|
|
|
* @param int $oneWay |
53
|
|
|
* |
54
|
|
|
* @throws \Exception |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
11 |
|
public function __doRequest($request, $location, $action, $version, $oneWay = 0) |
59
|
|
|
{ |
60
|
11 |
|
$doc = new \DOMDocument('1.0'); |
61
|
11 |
|
$doc->loadXML($request); |
62
|
11 |
|
$wsa = new WSASoap($doc); |
63
|
11 |
|
$wsa->addAction($action); |
64
|
11 |
|
$doc = $wsa->getDoc(); |
65
|
11 |
|
$wsse = new WSSESoap($doc, false); |
66
|
11 |
|
$wsse->signAllHeaders = false; |
67
|
11 |
|
$wsse->addUserToken($this->username, $this->password, $this->digest); |
68
|
11 |
|
$request = $wsse->saveXML(); |
69
|
|
|
|
70
|
11 |
|
return parent::__doRequest($request, $location, $action, $version, $oneWay); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|