diff options
author | Thomas Lange <code@nerdmind.de> | 2021-07-19 17:50:21 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2021-07-19 17:58:54 +0200 |
commit | dd4b3d9ebb85c9bc8138212fd7cb207ab154f626 (patch) | |
tree | e005be07809b4644d6974eb59bcfdca7017f3234 /core/namespace/Parsers/ArgumentParser.php | |
parent | 489851d1e7b1d346ff316e7a6721de574322d7d6 (diff) | |
download | blog-dd4b3d9ebb85c9bc8138212fd7cb207ab154f626.tar.gz blog-dd4b3d9ebb85c9bc8138212fd7cb207ab154f626.tar.xz blog-dd4b3d9ebb85c9bc8138212fd7cb207ab154f626.zip |
Add and use new parser/transformer classes
Classes:
* Parsers\ArgumentParser
* Parsers\EmoticonParser
* Parsers\MarkdownParser
Interfaces:
* Parsers\ParserInterface
Diffstat (limited to 'core/namespace/Parsers/ArgumentParser.php')
-rw-r--r-- | core/namespace/Parsers/ArgumentParser.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/namespace/Parsers/ArgumentParser.php b/core/namespace/Parsers/ArgumentParser.php new file mode 100644 index 0000000..ab32fe1 --- /dev/null +++ b/core/namespace/Parsers/ArgumentParser.php @@ -0,0 +1,30 @@ +<?php +namespace Parsers; + +class ArgumentParser implements ParserInterface { + + #=========================================================================== + # Parse arguments (*without* duplicates) + #=========================================================================== + public function parse(string $text): array { + foreach(explode('|', $text) as $delimiter) { + $part = explode('=', $delimiter); + + $argumentK = $part[0] ?? NULL; + $argumentV = $part[1] ?? TRUE; + + if(preg_match('#^[[:word:]]+$#', $argumentK)) { + $arguments[strtoupper($argumentK)] = $argumentV; + } + } + + return $arguments ?? []; + } + + #=========================================================================== + # Transform arguments (not implemented) + #=========================================================================== + public function transform(string $text): string { + return ''; + } +} |