Skip to content

Commit

Permalink
feat: Add boolean token
Browse files Browse the repository at this point in the history
  • Loading branch information
famoser committed Dec 29, 2024
1 parent 1fb4cc5 commit 2679458
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Backend/File/Token/BooleanToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the famoser/pdf-generator project.
*
* (c) Florian Moser <[email protected]>
*
* 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);
}
}
5 changes: 5 additions & 0 deletions src/Backend/File/Token/DictionaryToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions src/Backend/File/TokenVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 2679458

Please sign in to comment.