1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Skautis; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Třída pro uživatelské nastavení |
8
|
|
|
*/ |
9
|
|
|
class Config |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
public const CACHE_ENABLED = true; |
13
|
|
|
public const CACHE_DISABLED = false; |
14
|
|
|
|
15
|
|
|
public const TESTMODE_ENABLED = true; |
16
|
|
|
public const TESTMODE_DISABLED = false; |
17
|
|
|
|
18
|
|
|
public const COMPRESSION_ENABLED = true; |
19
|
|
|
public const COMPRESSION_DISABLED = false; |
20
|
|
|
|
21
|
|
|
private const URL_TEST = 'https://test-is.skaut.cz/'; |
22
|
|
|
private const URL_PRODUCTION = 'https://is.skaut.cz/'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $appId; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Používat testovací SkautIS? |
31
|
|
|
* |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
private $testMode; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Používat kompresi? |
38
|
|
|
* |
39
|
|
|
* @var bool |
40
|
|
|
*/ |
41
|
|
|
private $compression; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Cachovat WSDL? |
45
|
|
|
* |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
protected $cache; |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $appId Id aplikace od správce skautISu |
53
|
|
|
* @param bool $isTestMode používat testovací SkautIS? |
54
|
|
|
* @param bool $cache použít kompresi? |
55
|
|
|
* @param bool $compression cachovat WDSL? |
56
|
|
|
* @throws InvalidArgumentException |
57
|
|
|
*/ |
58
|
8 |
|
public function __construct( |
59
|
|
|
string $appId, |
|
|
|
|
60
|
|
|
bool $isTestMode = self::TESTMODE_DISABLED, |
|
|
|
|
61
|
|
|
bool $cache = self::CACHE_ENABLED, |
|
|
|
|
62
|
|
|
bool $compression = self::COMPRESSION_ENABLED |
|
|
|
|
63
|
|
|
) { |
64
|
8 |
|
if (empty($appId)) { |
65
|
|
|
throw new InvalidArgumentException('AppId cannot be empty.'); |
66
|
|
|
} |
67
|
8 |
|
$this->appId = $appId; |
68
|
8 |
|
$this->setTestMode($isTestMode); |
69
|
8 |
|
$this->setCache($cache); |
70
|
8 |
|
$this->setCompression($compression); |
71
|
8 |
|
} |
72
|
|
|
|
73
|
2 |
|
public function getAppId(): string |
74
|
|
|
{ |
75
|
2 |
|
return $this->appId; |
76
|
|
|
} |
77
|
|
|
|
78
|
4 |
|
public function isTestMode(): bool |
79
|
|
|
{ |
80
|
4 |
|
return $this->testMode; |
81
|
|
|
} |
82
|
|
|
|
83
|
8 |
|
public function setTestMode(bool $isTestMode = true): self |
84
|
|
|
{ |
85
|
8 |
|
$this->testMode = $isTestMode; |
86
|
8 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Zjistí, jestli je WSDL cachované |
91
|
|
|
*/ |
92
|
3 |
|
public function getCache(): bool |
93
|
|
|
{ |
94
|
3 |
|
return $this->cache; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Vypne/zapne cachovaní WSDL |
99
|
|
|
*/ |
100
|
8 |
|
public function setCache(bool $enabled): self |
101
|
|
|
{ |
102
|
8 |
|
$this->cache = $enabled; |
103
|
8 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Zjistí, jestli se používá komprese dotazů na WSDL |
108
|
|
|
*/ |
109
|
3 |
|
public function getCompression(): bool |
110
|
|
|
{ |
111
|
3 |
|
return $this->compression; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/**+ |
115
|
|
|
* Vypne/zapne kompresi dotazů na WSDL |
116
|
|
|
*/ |
117
|
8 |
|
public function setCompression(bool $enabled): self |
118
|
|
|
{ |
119
|
8 |
|
$this->compression = $enabled; |
120
|
8 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Vací začátek URL adresy |
125
|
|
|
*/ |
126
|
2 |
|
public function getBaseUrl(): string |
127
|
|
|
{ |
128
|
2 |
|
return $this->testMode ? self::URL_TEST : self::URL_PRODUCTION; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Na základě nastavení vrací argumenty pro SoapClient |
133
|
|
|
* |
134
|
|
|
* @see \SoapClient |
135
|
|
|
*/ |
136
|
1 |
|
public function getSoapOptions(): array |
137
|
|
|
{ |
138
|
|
|
$soapOptions = [ |
139
|
1 |
|
'ID_Application' => $this->appId, |
140
|
1 |
|
'soap_version' => SOAP_1_2, |
141
|
1 |
|
'encoding' => 'utf-8', |
142
|
|
|
]; |
143
|
|
|
|
144
|
1 |
|
if ($this->compression) { |
145
|
1 |
|
$soapOptions['compression'] = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP; |
146
|
|
|
} |
147
|
|
|
|
148
|
1 |
|
$soapOptions['cache_wsdl'] = $this->cache ? WSDL_CACHE_BOTH : WSDL_CACHE_NONE; |
149
|
|
|
|
150
|
1 |
|
return $soapOptions; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|