From 18f75e0f29f6930f8497c7b7312941d09000c40e Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Sun, 2 Feb 2025 17:46:20 +0000 Subject: [PATCH 1/4] wip --- src/Lexique/CompileHelpers.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Lexique/CompileHelpers.php b/src/Lexique/CompileHelpers.php index 302fff3..86465d2 100644 --- a/src/Lexique/CompileHelpers.php +++ b/src/Lexique/CompileHelpers.php @@ -14,12 +14,10 @@ trait CompileHelpers */ protected function compileHelpersStack(string $expression): string { - foreach ( - [ + foreach ([ "Auth", "Guest", "Lang", "Env", "Csrf", "Flash", "Production", "Trans", "HasFlash", "EndHelpers", "Empty", "NotEmpty", "Method", "Service" - ] as $token - ) { + ] as $token) { $out = $this->{"compile" . $token}($expression); if (strlen($out) !== 0) { $expression = $out; From 8b3b1b382bb9c6cb7163a41a7e59d20de91b9b5a Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Sun, 21 Dec 2025 00:38:35 +0000 Subject: [PATCH 2/4] Fix stack build --- src/StackManager.php | 20 +++++++++++++++++++- src/Tintin.php | 5 +++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/StackManager.php b/src/StackManager.php index cf8075b..a8ce8c5 100644 --- a/src/StackManager.php +++ b/src/StackManager.php @@ -27,6 +27,13 @@ class StackManager */ private Tintin $tintin; + /** + * The context data + * + * @var array + */ + private array $context = []; + /** * StackManager constructor. * @@ -152,7 +159,7 @@ public function getStack(string $name, ?string $default = null) return $this->tintin->renderString( $this->pushes[$name], - ['__tintin' => $this->tintin] + array_merge($this->context, ['__tintin' => $this->tintin]) ); } @@ -168,4 +175,15 @@ public function getStacks() { return $this->stacks; } + + /** + * Set the context data + * + * @param array $context + * @return void + */ + public function setContext(array $context): void + { + $this->context = $context; + } } diff --git a/src/Tintin.php b/src/Tintin.php index 9177480..fd91641 100644 --- a/src/Tintin.php +++ b/src/Tintin.php @@ -122,6 +122,8 @@ public function render($template, array $data = []): string { $__template = $template; + $this->stackManager->setContext($data); + if (is_null($this->loader)) { // Try to compile the plain string return $this->renderString($__template, $data); @@ -175,9 +177,8 @@ public function render($template, array $data = []): string */ public function renderString(string $template, array $data = []): string { - $__template = $template; return $this->executePlainRendering( - trim($this->compiler->compile($__template)), + trim($this->compiler->compile($template)), array_merge($data, ['__tintin' => $this]) ); } From ab4d0b3377ace92a3d201f533a45e9cd5ebbddc3 Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Sun, 21 Dec 2025 00:43:03 +0000 Subject: [PATCH 3/4] Code formatting --- src/Tintin.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Tintin.php b/src/Tintin.php index fd91641..548b729 100644 --- a/src/Tintin.php +++ b/src/Tintin.php @@ -10,7 +10,7 @@ class Tintin { /** - * The tintin parse instance + * The compiler instance * * @var Compiler */ @@ -31,7 +31,7 @@ class Tintin private StackManager $stackManager; /** - * The stack manager instance + * The macro manager instance * * @var MacroManager */ @@ -42,7 +42,7 @@ class Tintin * * @var array */ - private array $__data = []; + private array $sharedData = []; /** * Tintin constructor. @@ -91,13 +91,14 @@ public function getLoader(): ?LoaderInterface * Push shared data * * @param array $data + * @return void */ - public function pushSharedData(array $data) + public function pushSharedData(array $data): void { // The arrangement of values is very important // To refresh the old variables which are // a name with the new comer - $this->__data = array_merge($this->__data, $data); + $this->sharedData = array_merge($this->sharedData, $data); } /** @@ -107,7 +108,7 @@ public function pushSharedData(array $data) */ public function getSharedData(): array { - return $this->__data; + return $this->sharedData; } /** @@ -146,7 +147,7 @@ public function render($template, array $data = []): string // If cache is not still alive we load template // and create the new cache for if (! $this->loader->isExpired($__template)) { - $this->obFlushAndStar(); + $this->obFlushAndStart(); require $this->loader->getCacheFileResolvedPath($__template); @@ -161,7 +162,7 @@ public function render($template, array $data = []): string $this->compiler->compile($content) ); - $this->obFlushAndStar(); + $this->obFlushAndStart(); require $this->loader->getCacheFileResolvedPath($__template); @@ -192,7 +193,7 @@ public function renderString(string $template, array $data = []): string */ private function executePlainRendering(string $content, array $data): string { - $this->obFlushAndStar(); + $this->obFlushAndStart(); extract($data); @@ -223,7 +224,7 @@ private function obGetContent(): string * * @return void */ - private function obFlushAndStar() + private function obFlushAndStart(): void { ob_start(); } @@ -239,7 +240,7 @@ private function createTmpFile(string $content): string $tmp_dir = sys_get_temp_dir() . '/__tintin'; if (!is_dir($tmp_dir)) { - mkdir($tmp_dir, 0777); + @mkdir($tmp_dir, 0755, true); } $file = $tmp_dir . '/' . md5(microtime(true)) . '.php'; From 628c194a7ad73956efdeff8623dbd228f54ab58f Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Sun, 21 Dec 2025 00:44:35 +0000 Subject: [PATCH 4/4] formatting --- src/Lexique/CompileHelpers.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Lexique/CompileHelpers.php b/src/Lexique/CompileHelpers.php index 86465d2..302fff3 100644 --- a/src/Lexique/CompileHelpers.php +++ b/src/Lexique/CompileHelpers.php @@ -14,10 +14,12 @@ trait CompileHelpers */ protected function compileHelpersStack(string $expression): string { - foreach ([ + foreach ( + [ "Auth", "Guest", "Lang", "Env", "Csrf", "Flash", "Production", "Trans", "HasFlash", "EndHelpers", "Empty", "NotEmpty", "Method", "Service" - ] as $token) { + ] as $token + ) { $out = $this->{"compile" . $token}($expression); if (strlen($out) !== 0) { $expression = $out;