1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
line.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Calendar\ICal\Parser;
5
6
7class Line
8{
9 private const COMPONENT_PROPERTY_NAME_BEGIN = 'begin';
10 private const COMPONENT_PROPERTY_NAME_END = 'end';
11 private const FIELDS_LIST_PARSE_WITH_END = ['attendee', 'dtstart', 'dtend'];
12 private $name;
13 private $value;
14 private $params = [];
15 private $line;
16
21 public static function createInstance(string $line): Line
22 {
23 return new self($line);
24 }
25
30 public function __construct(string $line)
31 {
32 $this->line = $line;
33 }
34
35
39 public function parse(): Line
40 {
41 $line = $this->line;
42 $valuePos = (int) mb_strpos($line, ':');
43 $parts = explode(';', mb_substr($line, 0, $valuePos));
44 $name = mb_strtolower(array_shift($parts));
45 if (in_array($name, self::FIELDS_LIST_PARSE_WITH_END, true))
46 {
47 $valuePos = (int) mb_strrpos($this->line, ':');
48 }
49 $value = $this->getValueFromString($valuePos);
50
51 $params = [];
52 foreach($parts as $v)
53 {
54 if (!str_contains($v, '='))
55 {
56 continue;
57 }
58
59 [$k, $v] = explode('=', $v);
60 $params[mb_strtolower($k)] = trim($v, '"');
61 }
62
63 $this->value = $value;
64 $this->params = $params;
65 $this->name = $name;
66
67 return $this;
68 }
69
73 public function isBegin(): bool
74 {
75 return $this->name === self::COMPONENT_PROPERTY_NAME_BEGIN;
76 }
77
81 public function isEnd(): bool
82 {
83 return $this->name === self::COMPONENT_PROPERTY_NAME_END;
84 }
85
89 public function getValue(): string
90 {
91 return $this->value;
92 }
93
97 public function getName(): string
98 {
99 return $this->name;
100 }
101
105 public function getParams(): array
106 {
107 return $this->params;
108 }
109
113 public function getValueAsArray(): array
114 {
115 if (mb_strpos($this->value,",") !== false)
116 {
117 return explode(",",$this->value);
118 }
119
120 return [$this->value];
121 }
122
126 public function __toString(): string
127 {
128 return $this->getValue();
129 }
130
134 public function count(): int
135 {
136 return count($this->params);
137 }
138
143 private function getValueFromString(int $valuePos): string
144 {
145 $replacements = array('from'=>['\\,', '\\n', '\\;', '\\:', '\\"'], 'to'=>[',', "\n", ';', ':', '"']);
146 $tmp = trim(mb_substr($this->line, $valuePos+1));
147
148 return str_replace($replacements['from'], $replacements['to'], $tmp);
149 }
150}
__construct(string $line)
Определения line.php:30
getValueAsArray()
Определения line.php:113
static createInstance(string $line)
Определения line.php:21
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$k
Определения template_pdf.php:567