1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
parser.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Calendar\ICal\Parser;
5
6
7use Generator;
8
9class Parser
10{
14 private $content;
18 private $linesGenerator;
22 private $component;
23
28 public static function createInstance(string $content): Parser
29 {
30 return new self($content);
31 }
32
37 public function __construct(string $content)
38 {
39 $this->content = $content;
40 }
41
45 public function parse(): Parser
46 {
47 $this->linesGenerator = $this->getLinesGenerator();
48 $this->component = $this->handle();
49
50 return $this;
51 }
52
56 private function getLinesGenerator(): ?Generator
57 {
58 $tmp = explode("\r\n", $this->content);
59
60 for ($i = 0, $length = count($tmp); $i < $length; $i++)
61 {
62 $line = rtrim($tmp[$i]);
63
64 while (isset($tmp[$i + 1]) && mb_strlen($tmp[$i + 1]) > 0 && ($tmp[$i + 1][0] === ' ' || $tmp[$i + 1][0] === "\t" ))
65 {
66 $line .= rtrim(mb_substr($tmp[++$i],1));
67 }
68
69 yield $line;
70 }
71
72 return null;
73 }
74
78 private function handle(): ?ParserComponent
79 {
80 $componentName = '';
81 $properties = [];
82 $componentsCollection = new ComponentsCollection();
83
84 while ($str = $this->linesGenerator->current())
85 {
87 $line->parse();
88
89 if ($line->isBegin())
90 {
92 {
93 $componentsCollection->add($this->handle());
94 }
95 else
96 {
97 $componentName = mb_strtolower($line->getValue());
98 }
99 }
100 elseif ($line->isEnd())
101 {
103 ->createComponent($properties, $componentsCollection)
104 ->getComponent();
105 }
106 elseif (in_array($line->getName(), ['attendee', 'attach']))
107 {
108 $properties[$line->getName()][] = ParserPropertyType::createInstance($line->getName())
109 ->addParameters($line->getParams())
110 ->setValue($line->getValue());
111 }
112 else
113 {
114 $properties[$line->getName()] = ParserPropertyType::createInstance($line->getName())
115 ->addParameters($line->getParams())
116 ->setValue($line->getValue());
117 }
118
119 $this->linesGenerator->next();
120 }
121
122 return null;
123 }
124
128 public function getCalendarComponent(): ?Calendar
129 {
130 return ($this->component instanceof Calendar)
131 ? $this->component
132 : null
133 ;
134 }
135
136// private static function _ValidUtf8( $data ) {
137// $rx = '[\xC0-\xDF]([^\x80-\xBF]|$)';
138// $rx .= '|[\xE0-\xEF].{0,1}([^\x80-\xBF]|$)';
139// $rx .= '|[\xF0-\xF7].{0,2}([^\x80-\xBF]|$)';
140// $rx .= '|[\xF8-\xFB].{0,3}([^\x80-\xBF]|$)';
141// $rx .= '|[\xFC-\xFD].{0,4}([^\x80-\xBF]|$)';
142// $rx .= '|[\xFE-\xFE].{0,5}([^\x80-\xBF]|$)';
143// $rx .= '|[\x00-\x7F][\x80-\xBF]';
144// $rx .= '|[\xC0-\xDF].[\x80-\xBF]';
145// $rx .= '|[\xE0-\xEF]..[\x80-\xBF]';
146// $rx .= '|[\xF0-\xF7]...[\x80-\xBF]';
147// $rx .= '|[\xF8-\xFB]....[\x80-\xBF]';
148// $rx .= '|[\xFC-\xFD].....[\x80-\xBF]';
149// $rx .= '|[\xFE-\xFE]......[\x80-\xBF]';
150// $rx .= '|^[\x80-\xBF]';
151//
152// return ( ! (bool) preg_match('!'.$rx.'!', $data) );
153// }
154}
static createInstance(string $componentName)
Определения factorycomponents.php:22
static createInstance(string $line)
Определения line.php:21
__construct(string $content)
Определения parser.php:37
static createInstance(string $content)
Определения parser.php:28
static createInstance(string $name)
Определения parserpropertytype.php:26
$str
Определения commerceml2.php:63
$componentName
Определения component_props2.php:49
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936