From 7f830f41bc83f3211751690c97f947f816ae4b2a Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 24 Jun 2024 03:28:54 +0300 Subject: [PATCH] implement Listing support --- src/Document.php | 11 +++++++++++ src/Entity/Listing.php | 44 ++++++++++++++++++++++++++++++++++++++++++ src/Parser/Listing.php | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/Entity/Listing.php create mode 100644 src/Parser/Listing.php diff --git a/src/Document.php b/src/Document.php index 547c7bc..0fdf23b 100644 --- a/src/Document.php +++ b/src/Document.php @@ -49,6 +49,17 @@ class Document break; + // Listing + case Parser\Listing::match($line): + + $this->_entities[] = new Entity\Listing( + Parser\Listing::getItem( + $line + ) + ); + + break; + // Plain default: diff --git a/src/Entity/Listing.php b/src/Entity/Listing.php new file mode 100644 index 0000000..fa1c8f8 --- /dev/null +++ b/src/Entity/Listing.php @@ -0,0 +1,44 @@ +setItem( + $item + ); + } + + public function setItem( + ?string $item + ): void + { + if ($item) + { + $item = trim( + $item + ); + } + + $this->_item = $item; + } + + public function Item(): ?string + { + return $this->_item; + } + + public function toString(): string + { + return self::TAG . ' ' . $this->_item; + } +} \ No newline at end of file diff --git a/src/Parser/Listing.php b/src/Parser/Listing.php new file mode 100644 index 0000000..f0d2c05 --- /dev/null +++ b/src/Parser/Listing.php @@ -0,0 +1,44 @@ +.*)$/m', + $line, + $matches + ); + } + + public static function getItem( + string $line + ): ?string + { + $matches = []; + + if (self::match($line, $matches)) + { + if (isset($matches['item'])) + { + $item = trim( + $matches['item'] + ); + + if ($item) + { + return $item; + } + } + } + + return null; + } +} \ No newline at end of file