Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/calendar/lib/core/event/tools/ |
Upload File : |
<?php namespace Bitrix\Calendar\Core\Event\Tools; use Bitrix\Calendar\Core\Base\Date; use Bitrix\Calendar\Util; class UidGenerator { public const DATE_PART_FORMAT = 'Ymd\THis\Z'; public const MAX_UID_LENGTH = 255; private const CORRECT_LENGTH = 2; /** * @var Date */ private Date $date; /** * @var string */ private string $portalName; /** * @var int */ private int $userId; /** * @return UidGenerator */ public static function createInstance(): UidGenerator { return new self(); } /** * @param Date $date * @param string $portalName * @param Date|null $originalDate * @return string */ public function getUidWithDate(): string { $portalName = $this->portalName ?? ''; $datePart = $this->date ->setTimezone(Util::prepareTimezone()) ->format(self::DATE_PART_FORMAT) ; $postfix = md5((string)time(). $this->userId); $datePartLength = mb_strlen($datePart); $portalNameLength = mb_strlen($portalName); $hashLength = mb_strlen($postfix); if (($datePartLength + $portalNameLength + $hashLength) > self::MAX_UID_LENGTH) { $allowableLength = self::MAX_UID_LENGTH - $datePartLength - $hashLength - self::CORRECT_LENGTH; $portalName = substr($this->portalName, 0, $allowableLength); } return $datePart . '-' . $postfix . "@" . $portalName; } /** * @param Date $date * @return $this */ public function setDate(Date $date): UidGenerator { $this->date = $date; return $this; } /** * @param string $portalName * @return $this */ public function setPortalName(string $portalName): UidGenerator { $this->portalName = $portalName; return $this; } /** * @param int $userId * @return $this */ public function setUserId(int $userId): UidGenerator { $this->userId = $userId; return $this; } }