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/ical/builder/ |
Upload File : |
<?php namespace Bitrix\Calendar\ICal\Builder; use Bitrix\Calendar\ICal\Basic\Content; use Bitrix\Calendar\ICal\Basic\PropertyCreator; class ComponentCreator { private $content; public function __construct(Content $content) { $this->content = $content; } public function build(): string { $lines = []; foreach ($this->buildComponent() as $line) { $lines = array_merge($lines, $this->chipLine($line)); } return implode("\r\n", $lines)."\r\n"; } public function buildComponent(): array { $lines[] = "BEGIN:{$this->content->getType()}"; $lines = array_merge( $lines, $this->buildProperties(), $this->buildSubComponents() ); $lines[] = "END:{$this->content->getType()}"; return $lines; } private function buildProperties(): array { $lines = []; foreach ($this->content->getProperties() as $key => $property) { $builder = new PropertyCreator($property); $lines = array_merge( $lines, $builder->build() ); } return $lines; } private function buildSubComponents(): array { $lines = []; foreach ($this->content->getSubComponents() as $component) { $builder = new ComponentCreator($component->accessContent()); $lines = array_merge( $lines, $builder->buildComponent() ); } return $lines; } private function chipLine(string $line): array { $chippedLines = []; while (strlen($line) > 0) { if (strlen($line) > 75) { $chippedLines[] = mb_strcut($line, 0, 75, 'utf-8'); $line = ' '.mb_strcut($line, 75, strlen($line), 'utf-8'); } else { $chippedLines[] = $line; break; } } return $chippedLines; } }