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