1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AttachedVoteResultUrlService.php
См. документацию.
1<?php
2
3namespace Bitrix\Vote\Service;
4
5use Bitrix\Main\ArgumentTypeException;
6use Bitrix\Main\Config\Option;
7use Bitrix\Main\Context;
8use Bitrix\Main\ObjectNotFoundException;
9use Bitrix\Main\Security\Sign\BadSignatureException;
10use Bitrix\Main\Web\Uri;
11use Bitrix\Vote\Attach;
12use Bitrix\Vote\AttachTable;
13
15{
16 private const SIGN_SEPARATOR = '.';
17
18 private AttachedVoteSigner $signer;
19
20 public function __construct()
21 {
22 $this->signer = new AttachedVoteSigner();
23 }
24
25 public function getResultUrl(string $signedAttachId, ?string $uid): string
26 {
27 $id = $uid ?? $signedAttachId;
28
29 return "/vote-result/$id";
30 }
31
40 public function getAttachByUrlId(string $id): Attach
41 {
42 return str_contains($id, self::SIGN_SEPARATOR) ? $this->getAttachBySignedId($id) : $this->getAttachByUID($id);
43 }
44
52 private function getAttachBySignedId(string $signedId): Attach
53 {
54 $attachId = $this->signer->unsign($signedId);
55
56 return new Attach($attachId);
57 }
58
65 private function getAttachByUID(string $uid): Attach
66 {
67 $attachId = AttachTable::getIdByUid($uid);
68 if ($attachId)
69 {
70 return new Attach($attachId);
71 }
72
73 throw new ObjectNotFoundException();
74 }
75
76 public function getAbsoluteResultUrl(string $signedAttachId, ?string $uid = null): ?string
77 {
78 $host = $this->getHost();
79 if (!$host)
80 {
81 return null;
82 }
83
84 $request = Context::getCurrent()?->getRequest();
85 $protocol = $request?->isHttps() ? 'https' : 'http';
86 $port = (int)$request?->getServerPort();
87
88 $portSuffix = $port && !in_array($port, [443, 80], true) ? ":$port" : '';
89 $parsedUri = new Uri($protocol . '://' . $host . $portSuffix);
90 $parsedUri->setPath($this->getResultUrl($signedAttachId, $uid));
91
92 return rtrim($parsedUri->getLocator(), '/');
93 }
94
95 private function getHost(): ?string
96 {
97 $fromRequest = Context::getCurrent()?->getRequest()?->getHttpHost();
98 if ($fromRequest)
99 {
100 return $fromRequest;
101 }
102
103 if (defined('BX24_HOST_NAME') && BX24_HOST_NAME)
104 {
105 return BX24_HOST_NAME;
106 }
107
108 if (defined('SITE_SERVER_NAME') && SITE_SERVER_NAME)
109 {
110 return SITE_SERVER_NAME;
111 }
112
113 return Option::get('main', 'server_name', null);
114 }
115}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
Определения uri.php:17
Определения attach.php:180
static getIdByUid(string $uid)
Определения attach.php:165
getAbsoluteResultUrl(string $signedAttachId, ?string $uid=null)
getResultUrl(string $signedAttachId, ?string $uid)
$protocol
Определения .description.php:9
$uid
Определения hot_keys_act.php:8
$host
Определения mysql_to_pgsql.php:32