diff --git a/README.md b/README.md index 3135a2e..8ebcd3e 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ __DIR__ . '/templates', diff --git a/autoload.php b/autoload.php index 7f0c689..dc788e7 100644 --- a/autoload.php +++ b/autoload.php @@ -6,7 +6,7 @@ */ spl_autoload_register(function ($class) { - $prefix = 'Beobles\\Core\\View\\'; + $prefix = 'Core\\View\\'; $baseDir = __DIR__ . '/src/Core/View/'; if (strpos($class, $prefix) !== 0) { diff --git a/examples/index.php b/examples/index.php index 39253a0..9392a5e 100644 --- a/examples/index.php +++ b/examples/index.php @@ -2,7 +2,7 @@ require_once __DIR__ . '/../autoload.php'; -use Beobles\Core\View\Engine; +use Core\View\Engine; // Criar engine $engine = new Engine([ diff --git a/src/Core/View/Abstract/AbstractDirective.php b/src/Core/View/Abstract/AbstractDirective.php index 6bde27f..529c943 100644 --- a/src/Core/View/Abstract/AbstractDirective.php +++ b/src/Core/View/Abstract/AbstractDirective.php @@ -1,6 +1,6 @@ false]); + if (!is_array($payload) || !array_key_exists('value', $payload) || !array_key_exists('expires_at', $payload)) { + return $content; + } + + $expiresAt = $payload['expires_at']; + if (is_int($expiresAt) && $expiresAt > 0 && $expiresAt < time()) { + $this->delete($key); + return null; + } + + return $payload['value']; } public function set(string $key, $value, int $ttl = 3600): void { $file = $this->getFilePath($key); - file_put_contents($file, $value); + $expiresAt = $ttl > 0 ? time() + $ttl : null; + $payload = serialize([ + 'value' => $value, + 'expires_at' => $expiresAt, + ]); + file_put_contents($file, $payload); } public function delete(string $key): void diff --git a/src/Core/View/Cache/FileWatcher.php b/src/Core/View/Cache/FileWatcher.php index a343ce4..1708ecf 100644 --- a/src/Core/View/Cache/FileWatcher.php +++ b/src/Core/View/Cache/FileWatcher.php @@ -1,6 +1,6 @@ $nodes */ public function compile(array $nodes): string { @@ -41,7 +45,11 @@ public function compileTextNode(TextNode $node): string public function compileExpressionNode(ExpressionNode $node): string { $expression = $this->compileExpression($node->value); - return 'echo $__engine->escape(' . $expression . ", 'html');\n"; + if ($this->autoEscape) { + return 'echo $__engine->escape(' . $expression . ", 'html');\n"; + } + + return 'echo ' . $expression . ";\n"; } public function compileRawNode(RawNode $node): string diff --git a/src/Core/View/Components/ComponentRegistry.php b/src/Core/View/Components/ComponentRegistry.php index f7a1e70..30b8135 100644 --- a/src/Core/View/Components/ComponentRegistry.php +++ b/src/Core/View/Components/ComponentRegistry.php @@ -1,8 +1,8 @@ lexer = new Lexer(); $this->parser = new Parser($directiveRegistry); - $this->compiler = new Compiler(); + $this->compiler = new Compiler((bool) $this->environment->getConfig('auto_escape', true)); $this->renderer = new Renderer($this->environment->getConfig('compiled_templates_dir', $this->cacheDir)); $this->middlewarePipeline->add(new SecurityMiddleware()); diff --git a/src/Core/View/Environment.php b/src/Core/View/Environment.php index dc5736a..d0ce098 100644 --- a/src/Core/View/Environment.php +++ b/src/Core/View/Environment.php @@ -1,6 +1,6 @@