Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ReincarnationRequestBuilder.php
1<?php
2
4
8
10{
11 private Request $request;
12 private Coupon $coupon;
13
14 public function __construct(Coupon $coupon)
15 {
16 $this->coupon = $coupon;
17 $this->request = new Request;
18 }
19
20 public function setHeaders(): self
21 {
22 $headers = new HttpHeaders();
23 $headers->add('User-Agent', 'BitrixSMUpdater');
24 $headers->add('Content-type', 'application/x-www-form-urlencoded');
25
26 $this->request->setHeaders($headers);
27
28 return $this;
29 }
30
31 public function setUrl(): self
32 {
33 $host = \COption::GetOptionString("main", "update_site", 'mysql.smn');
34 $url = new Uri("http://".$host."/bitrix/updates/us_updater_actions.php");
35 $this->request->setUrl($url);
36
37 return $this;
38 }
39
40 public function setProxy(): self
41 {
42 $proxyData = [
43 'host' => \COption::GetOptionString("main", "update_site_proxy_addr", ""),
44 'port' => \COption::GetOptionString("main", "update_site_proxy_port", ""),
45 'user' => \COption::GetOptionString("main", "update_site_proxy_user", ""),
46 'password' => \COption::GetOptionString("main", "update_site_proxy_pass", ""),
47 ];
48
49 $this->request->setProxy($proxyData);
50
51 return $this;
52 }
53
57 public function setBody(): self
58 {
59 $portalInfo = new PortalInfo();
60 $common = $portalInfo->common();
61 $modules = $this->addPrefixToKey($portalInfo->getModules(), 'bitm_');
62 $languages = $this->addPrefixToKey($portalInfo->getLanguages(), 'bitl_');
63 $parameters = array_merge(
64 $common,
65 $modules,
66 $languages,
67 [
68 'coupon' => $this->coupon->getKey(),
69 'query_type' => 'reincarnate',
70 'NS' => \COption::GetOptionString("main", "update_site_ns", ""),
71 'KDS' => \COption::GetOptionString("main", "update_devsrv", ""),
72 ]
73 );
74
75 $this->request->setBody($parameters);
76
77 return $this;
78 }
79
80 public function build(): Request
81 {
82 return $this->request;
83 }
84
85 private function addPrefixToKey(array $array, string $prefix): array
86 {
87 $result = [];
88 foreach ($array as $key => $value)
89 {
90 $result[$prefix.$key] = $value;
91 }
92
93 return $result;
94 }
95}