Skip to content

Commit

Permalink
make template factory settings readable
Browse files Browse the repository at this point in the history
  • Loading branch information
cappuc committed Mar 30, 2024
1 parent 7c89d07 commit a9f7e9c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
use Keepsuit\Liquid\Support\FilterRegistry;
use Keepsuit\Liquid\Support\TagRegistry;

/**
* @property-read bool $profile
* @property-read bool $rethrowExceptions
* @property-read bool $strictVariables
*/
final class TemplateFactory
{
protected TagRegistry $tagRegistry;
Expand Down Expand Up @@ -97,7 +102,7 @@ public function strictVariables(bool $strictVariables = true): TemplateFactory
}

/**
* Enable/disabled lineNumber, rethrowExceptions and strictVariables.
* Enable/disabled rethrowExceptions and strictVariables.
*/
public function debugMode(bool $debugMode = true): TemplateFactory
{
Expand Down Expand Up @@ -214,4 +219,19 @@ protected function buildFilterRegistry(): FilterRegistry
return (new FilterRegistry())
->register(StandardFilters::class);
}

public function __get(string $name): mixed
{
$publicProperties = [
'profile',
'rethrowExceptions',
'strictVariables',
];

if (in_array($name, $publicProperties)) {
return $this->{$name};
}

throw new \InvalidArgumentException("Property {$name} does not exist");
}
}
12 changes: 12 additions & 0 deletions tests/Unit/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@
expect($factory->getTagRegistry()->all())->toHaveKey('testblock');
expect($factory->getTagRegistry()->all()['testblock'])->toBe(\Keepsuit\Liquid\Tests\Stubs\TestTagBlockTag::class);
});

test('template factory settings', function () {
$factory = TemplateFactory::new()
->rethrowExceptions()
->strictVariables()
->profile();

expect($factory)
->rethrowExceptions->toBeTrue()
->strictVariables->toBeTrue()
->profile->toBeTrue();
});

0 comments on commit a9f7e9c

Please sign in to comment.