Fix #132 + test.

Also small performance fix
This commit is contained in:
bzick 2015-01-08 15:52:33 +03:00
parent 16d5f337c0
commit d096a80395
3 changed files with 15 additions and 8 deletions

View File

@ -922,9 +922,9 @@ class Fenom
{ {
$options |= $this->_options; $options |= $this->_options;
if (is_array($template)) { if (is_array($template)) {
$key = dechex($options) . "@" . implode(",", $template); $key = $options . "@" . implode(",", $template);
} else { } else {
$key = dechex($options) . "@" . $template; $key = $options . "@" . $template;
} }
if (isset($this->_storage[$key])) { if (isset($this->_storage[$key])) {
/** @var Fenom\Template $tpl */ /** @var Fenom\Template $tpl */
@ -948,6 +948,10 @@ class Fenom
*/ */
public function templateExists($template) public function templateExists($template)
{ {
$key = $this->_options . "@" . $template;
if (isset($this->_storage[$key])) { // already loaded
return true;
}
if ($provider = strstr($template, ":", true)) { if ($provider = strstr($template, ":", true)) {
if (isset($this->_providers[$provider])) { if (isset($this->_providers[$provider])) {
return $this->_providers[$provider]->templateExists(substr($template, strlen($provider) + 1)); return $this->_providers[$provider]->templateExists(substr($template, strlen($provider) + 1));
@ -972,7 +976,10 @@ class Fenom
$fenom = $this; // used in template $fenom = $this; // used in template
$_tpl = include($this->_compile_dir . "/" . $file_name); $_tpl = include($this->_compile_dir . "/" . $file_name);
/* @var Fenom\Render $_tpl */ /* @var Fenom\Render $_tpl */
if (!($this->_options & self::AUTO_RELOAD) || ($this->_options & self::AUTO_RELOAD) && $_tpl->isValid()) { if (!($this->_options & self::AUTO_RELOAD) || ($this->_options & self::AUTO_RELOAD) && $_tpl->isValid()) {
dumpt("loaded");
return $_tpl; return $_tpl;
} }
} }

View File

@ -265,10 +265,9 @@ class Template extends Render
foreach ($this->_stack as $scope) { foreach ($this->_stack as $scope) {
$_names[] = '{' . $scope->name . '} opened on line ' . $scope->line; $_names[] = '{' . $scope->name . '} opened on line ' . $scope->line;
} }
throw new CompileException("Unclosed tag" . (count($_names) > 1 ? "s" : "") . ": " . implode( /* @var Tag $scope */
", ", $message = "Unclosed tag" . (count($_names) > 1 ? "s" : "") . ": " . implode(", ", $_names);
$_names throw new CompileException($message, 0, 1, $this->_name, $scope->line);
), 0, 1, $this->_name, $scope->line); // for PHPStorm: $scope already defined there!
} }
$this->_src = ""; // cleanup $this->_src = ""; // cleanup
if ($this->_post) { if ($this->_post) {
@ -467,7 +466,7 @@ class Template extends Render
*/ */
public function addDepend(Render $tpl) public function addDepend(Render $tpl)
{ {
$this->_depends[$tpl->getScm()][$tpl->getName()] = $tpl->getTime(); $this->_depends[$tpl->getScm()][$tpl->getBaseName()] = $tpl->getTime();
} }
/** /**

View File

@ -17,6 +17,7 @@ class CustomProviderTest extends TestCase
$this->assertTrue($this->fenom->templateExists('my:include.tpl')); $this->assertTrue($this->fenom->templateExists('my:include.tpl'));
$this->assertFalse($this->fenom->templateExists('my:include-none.tpl')); $this->assertFalse($this->fenom->templateExists('my:include-none.tpl'));
$this->assertRender("start: {include 'my:include.tpl'}", 'start: include template'); $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());
} }
} }