forked from jstack-eu/newyse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.php
70 lines (55 loc) · 1.84 KB
/
Client.php
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
<?php
namespace Jstack\Newyse;
use BeSimple\SoapClient\SoapClient;
use BeSimple\SoapCommon\Cache;
class Client extends SoapClient
{
private $sessionKey;
protected $url;
protected $username;
protected $password;
protected $distributionChannel;
protected $languageCode = 'nl';
public function __construct($username, $password, $distributionChannel, $url, $cacheDir, $languageCode = 'nl')
{
$this->url = $url;
$this->username = $username;
$this->password = $password;
$this->distributionChannel = $distributionChannel;
$this->languageCode = $languageCode;
Cache::setDirectory($cacheDir);
Cache::setEnabled(1);
parent::__construct($url, [
'cache_wsdl' => Cache::TYPE_MEMORY,
'trace' => true
]);
}
public function connect()
{
$sessionCriteria = new \stdClass();
$sessionCriteria->Type = 'normal';
$sessionCriteria->Username = $this->username;
$sessionCriteria->Password = $this->password;
$sessionCriteria->LanguageCode = $this->languageCode;
$sessionCriteria->DistributionchannelCode = $this->distributionChannel;
$sessionCriteria = new \SoapVar($sessionCriteria, SOAP_ENC_OBJECT, "SessionCriteria");
$sessionKey = $this->createSession($sessionCriteria);
$this->setSessionKey($sessionKey);
return $this;
}
public function getSessionKey()
{
if ($this->sessionKey == null) {
$this->connect();
}
if (!empty($_SESSION['newyse.sessionkey'])) {
$this->sessionKey = $_SESSION['newyse.sessionkey'];
}
return $this->sessionKey;
}
public function setSessionKey($sessionKey)
{
$this->sessionKey = $sessionKey;
$_SESSION['newyse.sessionkey'] = $sessionKey;
}
}