mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
chore: pint
This commit is contained in:
parent
25f36eaf54
commit
4c66761baa
12 changed files with 142 additions and 121 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Liquid\FileSystems;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Keepsuit\Liquid\Contracts\LiquidFileSystem;
|
||||
|
||||
/**
|
||||
|
|
@ -52,10 +53,10 @@ class InlineTemplatesFileSystem implements LiquidFileSystem
|
|||
|
||||
public function readTemplateFile(string $templateName): string
|
||||
{
|
||||
if (!isset($this->templates[$templateName])) {
|
||||
throw new \InvalidArgumentException("Template '{$templateName}' not found in inline templates");
|
||||
if (! isset($this->templates[$templateName])) {
|
||||
throw new InvalidArgumentException("Template '{$templateName}' not found in inline templates");
|
||||
}
|
||||
|
||||
return $this->templates[$templateName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Keepsuit\Liquid\TagBlock;
|
|||
class TemplateTag extends TagBlock
|
||||
{
|
||||
protected string $templateName;
|
||||
|
||||
protected Raw $body;
|
||||
|
||||
public static function tagName(): string
|
||||
|
|
@ -36,16 +37,16 @@ class TemplateTag extends TagBlock
|
|||
{
|
||||
// Get the template name from the tag parameters
|
||||
$templateNameExpression = $context->params->expression();
|
||||
|
||||
|
||||
$this->templateName = match (true) {
|
||||
is_string($templateNameExpression) => trim($templateNameExpression),
|
||||
is_numeric($templateNameExpression) => (string) $templateNameExpression,
|
||||
$templateNameExpression instanceof VariableLookup => (string) $templateNameExpression,
|
||||
default => throw new SyntaxException("Template name must be a string, number, or variable"),
|
||||
default => throw new SyntaxException('Template name must be a string, number, or variable'),
|
||||
};
|
||||
|
||||
// Validate template name (letters, numbers, underscores, and slashes only)
|
||||
if (!preg_match('/^[a-zA-Z0-9_\/]+$/', $this->templateName)) {
|
||||
if (! preg_match('/^[a-zA-Z0-9_\/]+$/', $this->templateName)) {
|
||||
throw new SyntaxException("Invalid template name '{$this->templateName}' - template names must contain only letters, numbers, underscores, and slashes");
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ class TemplateTag extends TagBlock
|
|||
// Get the file system from the environment
|
||||
$fileSystem = $context->environment->fileSystem;
|
||||
|
||||
if (!$fileSystem instanceof InlineTemplatesFileSystem) {
|
||||
if (! $fileSystem instanceof InlineTemplatesFileSystem) {
|
||||
// If no inline file system is available, just return empty string
|
||||
// This allows the template to be used in contexts where inline templates aren't supported
|
||||
return '';
|
||||
|
|
@ -96,4 +97,4 @@ class TemplateTag extends TagBlock
|
|||
{
|
||||
return $this->body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue