mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
commit
47cee02dd3
@ -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,6 +976,7 @@ 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()) {
|
||||
return $_tpl;
|
||||
}
|
||||
|
@ -107,11 +107,9 @@ class Modifier
|
||||
if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) {
|
||||
if (count($match) == 3) {
|
||||
if ($by_words) {
|
||||
return preg_replace('#\s.*$#usS', "", $match[1]) . $etc . preg_replace(
|
||||
'#.*\s#usS',
|
||||
"",
|
||||
$match[2]
|
||||
);
|
||||
return preg_replace('#\s.*$#usS', "", $match[1]) .
|
||||
$etc .
|
||||
preg_replace('#.*\s#usS', "", $match[2]);
|
||||
} else {
|
||||
return $match[1] . $etc . $match[2];
|
||||
}
|
||||
|
@ -146,8 +146,8 @@ class Provider implements ProviderInterface
|
||||
*/
|
||||
protected function _getTemplatePath($tpl)
|
||||
{
|
||||
|
||||
if (($path = realpath($this->_path . "/" . $tpl)) && strpos($path, $this->_path) === 0) {
|
||||
$path = realpath($this->_path . "/" . $tpl);
|
||||
if ($path && strpos($path, $this->_path) === 0) {
|
||||
return $path;
|
||||
} else {
|
||||
throw new \RuntimeException("Template $tpl not found");
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user