From d096a8039542edad1fc5ebd1227fa47dddeb452e Mon Sep 17 00:00:00 2001 From: bzick Date: Thu, 8 Jan 2015 15:52:33 +0300 Subject: [PATCH] Fix #132 + test. Also small performance fix --- src/Fenom.php | 11 +++++++++-- src/Fenom/Template.php | 9 ++++----- tests/cases/Fenom/CustomProviderTest.php | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Fenom.php b/src/Fenom.php index 0b4cbac..1c33509 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -922,9 +922,9 @@ class Fenom { $options |= $this->_options; if (is_array($template)) { - $key = dechex($options) . "@" . implode(",", $template); + $key = $options . "@" . implode(",", $template); } else { - $key = dechex($options) . "@" . $template; + $key = $options . "@" . $template; } if (isset($this->_storage[$key])) { /** @var Fenom\Template $tpl */ @@ -948,6 +948,10 @@ class Fenom */ public function templateExists($template) { + $key = $this->_options . "@" . $template; + if (isset($this->_storage[$key])) { // already loaded + return true; + } if ($provider = strstr($template, ":", true)) { if (isset($this->_providers[$provider])) { return $this->_providers[$provider]->templateExists(substr($template, strlen($provider) + 1)); @@ -972,7 +976,10 @@ class Fenom $fenom = $this; // used in template $_tpl = include($this->_compile_dir . "/" . $file_name); /* @var Fenom\Render $_tpl */ + if (!($this->_options & self::AUTO_RELOAD) || ($this->_options & self::AUTO_RELOAD) && $_tpl->isValid()) { + dumpt("loaded"); + return $_tpl; } } diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index 3d6df8f..441aaf6 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -265,10 +265,9 @@ class Template extends Render foreach ($this->_stack as $scope) { $_names[] = '{' . $scope->name . '} opened on line ' . $scope->line; } - throw new CompileException("Unclosed tag" . (count($_names) > 1 ? "s" : "") . ": " . implode( - ", ", - $_names - ), 0, 1, $this->_name, $scope->line); // for PHPStorm: $scope already defined there! + /* @var Tag $scope */ + $message = "Unclosed tag" . (count($_names) > 1 ? "s" : "") . ": " . implode(", ", $_names); + throw new CompileException($message, 0, 1, $this->_name, $scope->line); } $this->_src = ""; // cleanup if ($this->_post) { @@ -467,7 +466,7 @@ class Template extends Render */ public function addDepend(Render $tpl) { - $this->_depends[$tpl->getScm()][$tpl->getName()] = $tpl->getTime(); + $this->_depends[$tpl->getScm()][$tpl->getBaseName()] = $tpl->getTime(); } /** diff --git a/tests/cases/Fenom/CustomProviderTest.php b/tests/cases/Fenom/CustomProviderTest.php index 483ed1c..30c9c63 100644 --- a/tests/cases/Fenom/CustomProviderTest.php +++ b/tests/cases/Fenom/CustomProviderTest.php @@ -17,6 +17,7 @@ class CustomProviderTest extends TestCase $this->assertTrue($this->fenom->templateExists('my:include.tpl')); $this->assertFalse($this->fenom->templateExists('my:include-none.tpl')); $this->assertRender("start: {include 'my:include.tpl'}", 'start: include template'); - //$this->assertRender("start: {import 'my:macros.tpl' as ops} {ops.add a=3 b=6}"); + $this->assertTrue($this->fenom->getTemplate('my:include.tpl')->isValid()); } + } \ No newline at end of file