From 26794585e7fc2e92108a5232ff01767b383b458a Mon Sep 17 00:00:00 2001 From: Florian Moser Date: Sun, 29 Dec 2024 12:38:49 +0100 Subject: [PATCH] feat: Add boolean token --- src/Backend/File/Token/BooleanToken.php | 32 ++++++++++++++++++++++ src/Backend/File/Token/DictionaryToken.php | 5 ++++ src/Backend/File/TokenVisitor.php | 5 ++++ 3 files changed, 42 insertions(+) create mode 100644 src/Backend/File/Token/BooleanToken.php diff --git a/src/Backend/File/Token/BooleanToken.php b/src/Backend/File/Token/BooleanToken.php new file mode 100644 index 00000000..d9c38ac4 --- /dev/null +++ b/src/Backend/File/Token/BooleanToken.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Famoser\PdfGenerator\Backend\File\Token; + +use Famoser\PdfGenerator\Backend\File\Token\Base\BaseToken; +use Famoser\PdfGenerator\Backend\File\TokenVisitor; + +class BooleanToken extends BaseToken +{ + public function __construct(private readonly bool $value) + { + } + + public function getValue(): bool + { + return $this->value; + } + + public function accept(TokenVisitor $visitor): string + { + return $visitor->visitBoolToken($this); + } +} diff --git a/src/Backend/File/Token/DictionaryToken.php b/src/Backend/File/Token/DictionaryToken.php index 23268aac..e441c1ae 100644 --- a/src/Backend/File/Token/DictionaryToken.php +++ b/src/Backend/File/Token/DictionaryToken.php @@ -30,6 +30,11 @@ public function setArrayEntry(string $key, array $tokens): void $this->setEntry($key, new ArrayToken($tokens)); } + public function setBooleanEntry(string $key, bool $value): void + { + $this->setEntry($key, new BooleanToken($value)); + } + public function setTextEntry(string $key, string $value): void { $this->setEntry($key, new TextToken($value)); diff --git a/src/Backend/File/TokenVisitor.php b/src/Backend/File/TokenVisitor.php index 19c5bfc2..2dc822ed 100644 --- a/src/Backend/File/TokenVisitor.php +++ b/src/Backend/File/TokenVisitor.php @@ -35,6 +35,11 @@ public function visitNumberToken(NumberToken $token): string return strval(NumberToken::format($token->getNumber())); } + public function visitBoolToken(Token\BooleanToken $param): string + { + return $param->getValue() ? 'true' : 'false'; + } + public function visitDictionaryToken(DictionaryToken $token): string { $entries = [];