|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Nexendrie\Rss; |
|
5
|
|
|
|
|
6
|
|
|
use Nexendrie\Utils\Numbers; |
|
7
|
|
|
use Nette\Utils\Strings; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Cloud |
|
11
|
|
|
* |
|
12
|
|
|
* @author Jakub Konečný |
|
13
|
|
|
* @property string $domain |
|
14
|
|
|
* @property int $port |
|
15
|
|
|
* @property string $path |
|
16
|
|
|
* @property string $registerProcedure |
|
17
|
|
|
* @property string $protocol |
|
18
|
|
|
*/ |
|
19
|
1 |
|
final class Cloud implements IXmlConvertible { |
|
20
|
1 |
|
use \Nette\SmartObject; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $domain; |
|
24
|
|
|
/** @var int */ |
|
25
|
|
|
protected $port; |
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $path; |
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $registerProcedure; |
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
protected $protocol; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(string $domain, int $port, string $path, string $registerProcedure, string $protocol) { |
|
34
|
1 |
|
$this->setDomain($domain); |
|
35
|
1 |
|
$this->setPort($port); |
|
36
|
1 |
|
$this->setPath($path); |
|
37
|
1 |
|
$this->setRegisterProcedure($registerProcedure); |
|
38
|
1 |
|
$this->setProtocol($protocol); |
|
39
|
1 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getDomain(): string { |
|
42
|
1 |
|
return $this->domain; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function setDomain(string $domain): void { |
|
46
|
1 |
|
$this->domain = $domain; |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getPort(): int { |
|
50
|
1 |
|
return $this->port; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function setPort(int $port): void { |
|
54
|
1 |
|
$this->port = Numbers::range($port, 0, 65535); |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getPath(): string { |
|
58
|
1 |
|
return $this->path; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @throws \InvalidArgumentException |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setPath(string $path): void { |
|
65
|
1 |
|
if(!Strings::startsWith($path, "/")) { |
|
66
|
1 |
|
throw new \InvalidArgumentException("Path has to start with /."); |
|
67
|
|
|
} |
|
68
|
1 |
|
$this->path = $path; |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getRegisterProcedure(): string { |
|
72
|
1 |
|
return $this->registerProcedure; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function setRegisterProcedure(string $registerProcedure): void { |
|
76
|
1 |
|
$this->registerProcedure = $registerProcedure; |
|
77
|
1 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getProtocol(): string { |
|
80
|
1 |
|
return $this->protocol; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @throws \InvalidArgumentException |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setProtocol(string $protocol): void { |
|
87
|
1 |
|
if(!in_array($protocol, ["xml-rpc", "soap", "http-post", ], true)) { |
|
88
|
1 |
|
throw new \InvalidArgumentException("Invalid value for protocol. Expected xml-rpc, soap or http-post, $protocol given."); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
1 |
|
$this->protocol = $protocol; |
|
91
|
1 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function appendToXml(\SimpleXMLElement &$parent): void { |
|
94
|
1 |
|
$element = $parent->addChild("cloud"); |
|
95
|
1 |
|
$element->addAttribute("domain", $this->domain); |
|
96
|
1 |
|
$element->addAttribute("port", (string) $this->port); |
|
97
|
1 |
|
$element->addAttribute("path", $this->path); |
|
98
|
1 |
|
$element->addAttribute("registerProcedure", $this->registerProcedure); |
|
99
|
1 |
|
$element->addAttribute("protocol", $this->protocol); |
|
100
|
1 |
|
} |
|
101
|
|
|
} |
|
102
|
|
|
?> |