Server IP : 85.193.89.191 / Your IP : 3.144.118.103 Web Server : Apache System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64 User : bitrix ( 600) PHP Version : 8.1.27 Disable Function : NONE MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/bitrix/www/bitrix/modules/calendar/lib/ical/parser/ |
Upload File : |
<?php namespace Bitrix\Calendar\ICal\Parser; class Line { private const COMPONENT_PROPERTY_NAME_BEGIN = 'begin'; private const COMPONENT_PROPERTY_NAME_END = 'end'; private $name; private $value; private $params = []; private $line; /** * @param string $line * @return Line */ public static function createInstance(string $line): Line { return new self($line); } /** * Line constructor. * @param string $line */ public function __construct(string $line) { $this->line = $line; } /** * @return $this */ public function parse(): Line { $line = $this->line; $valuePos = (int) mb_strpos($line, ':'); $parts = explode(';', mb_substr($line, 0, $valuePos)); $name = mb_strtolower(array_shift($parts)); if ($name === 'attendee') { $valuePos = (int) mb_strrpos($this->line, ':'); } $value = $this->getValueFromString($valuePos); $params = []; foreach($parts as $v) { [$k, $v] = explode('=', $v); $params[mb_strtolower($k)] = trim($v, '"'); } $this->value = $value; $this->params = $params; $this->name = $name; return $this; } /** * @return bool */ public function isBegin(): bool { return $this->name === self::COMPONENT_PROPERTY_NAME_BEGIN; } /** * @return bool */ public function isEnd(): bool { return $this->name === self::COMPONENT_PROPERTY_NAME_END; } /** * @return string */ public function getValue(): string { return $this->value; } /** * @return string */ public function getName(): string { return $this->name; } /** * @return array */ public function getParams(): array { return $this->params; } /** * @return array */ public function getValueAsArray(): array { if (mb_strpos($this->value,",") !== false) { return explode(",",$this->value); } return [$this->value]; } /** * @return string */ public function __toString(): string { return $this->getValue(); } /** * @return int */ public function count(): int { return count($this->params); } /** * @param int $valuePos * @return string */ private function getValueFromString(int $valuePos): string { $replacements = array('from'=>['\\,', '\\n', '\\;', '\\:', '\\"'], 'to'=>[',', "\n", ';', ':', '"']); $tmp = trim(mb_substr($this->line, $valuePos+1)); return str_replace($replacements['from'], $replacements['to'], $tmp); } }