mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix AUTO_RELOAD option
This commit is contained in:
parent
75c8d983d8
commit
ecc842cc04
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,4 +10,6 @@ tests/resources/template/*
|
|||||||
!.gitkeep
|
!.gitkeep
|
||||||
benchmark/compile/*
|
benchmark/compile/*
|
||||||
benchmark/templates/inheritance/smarty
|
benchmark/templates/inheritance/smarty
|
||||||
benchmark/templates/inheritance/twig
|
benchmark/templates/inheritance/twig
|
||||||
|
benchmark/sandbox/compiled/*
|
||||||
|
!.gitkeep
|
0
benchmark/sandbox/compiled/.gitkeep
Normal file
0
benchmark/sandbox/compiled/.gitkeep
Normal file
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
require_once __DIR__.'/../../vendor/autoload.php';
|
require_once __DIR__.'/../../vendor/autoload.php';
|
||||||
|
|
||||||
$t = new Fenom\Tokenizer('some "asd {$$ddd} dfg" some');
|
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled', Fenom::FORCE_COMPILE);
|
||||||
|
|
||||||
var_dump($t->tokens);
|
$fenom->display("greeting.tpl", array(
|
||||||
|
"user" => array(
|
||||||
|
"name" => "Ivka"
|
||||||
|
)
|
||||||
|
));
|
8
benchmark/sandbox/templates/greeting.tpl
Normal file
8
benchmark/sandbox/templates/greeting.tpl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Greeting,
|
||||||
|
{if $user}
|
||||||
|
{$user.name}!
|
||||||
|
{else}
|
||||||
|
anonymous?
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
3
|
@ -757,12 +757,15 @@ class Fenom
|
|||||||
protected function _load($tpl, $opts)
|
protected function _load($tpl, $opts)
|
||||||
{
|
{
|
||||||
$file_name = $this->_getCacheName($tpl, $opts);
|
$file_name = $this->_getCacheName($tpl, $opts);
|
||||||
if (!is_file($this->_compile_dir . "/" . $file_name)) {
|
if (is_file($this->_compile_dir . "/" . $file_name)) {
|
||||||
return $this->compile($tpl, true, $opts);
|
|
||||||
} else {
|
|
||||||
$fenom = $this;
|
$fenom = $this;
|
||||||
return include($this->_compile_dir . "/" . $file_name);
|
$_tpl = include($this->_compile_dir . "/" . $file_name);
|
||||||
|
/* @var Fenom\Render $tpl */
|
||||||
|
if($_tpl->isValid()) {
|
||||||
|
return $_tpl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return $this->compile($tpl, true, $opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,7 +99,7 @@ class Template extends Render
|
|||||||
|
|
||||||
private $_filters = array();
|
private $_filters = array();
|
||||||
|
|
||||||
private static $_checkers = array(
|
protected static $_tests = array(
|
||||||
'integer' => 'is_int(%s)',
|
'integer' => 'is_int(%s)',
|
||||||
'int' => 'is_int(%s)',
|
'int' => 'is_int(%s)',
|
||||||
'float' => 'is_float(%s)',
|
'float' => 'is_float(%s)',
|
||||||
@ -223,6 +223,10 @@ class Template extends Render
|
|||||||
unset($comment); // cleanup
|
unset($comment); // cleanup
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
// var_dump($this->_src[$pos]);
|
||||||
|
if($this->_src[$pos] === "\n") {
|
||||||
|
$pos++;
|
||||||
|
}
|
||||||
$this->_appendText(substr($this->_src, $pos, $start - $pos));
|
$this->_appendText(substr($this->_src, $pos, $start - $pos));
|
||||||
$end = $start + 1;
|
$end = $start + 1;
|
||||||
do {
|
do {
|
||||||
@ -260,6 +264,9 @@ class Template extends Render
|
|||||||
}
|
}
|
||||||
|
|
||||||
gc_collect_cycles();
|
gc_collect_cycles();
|
||||||
|
if($end < strlen($this->_src) && $this->_src[$end + 1] === "\n") {
|
||||||
|
$end++;
|
||||||
|
}
|
||||||
$this->_appendText(substr($this->_src, $end ? $end + 1 : 0)); // append tail of the template
|
$this->_appendText(substr($this->_src, $end ? $end + 1 : 0)); // append tail of the template
|
||||||
if ($this->_stack) {
|
if ($this->_stack) {
|
||||||
$_names = array();
|
$_names = array();
|
||||||
@ -466,6 +473,7 @@ class Template extends Render
|
|||||||
*/
|
*/
|
||||||
public function addDepend(Render $tpl)
|
public function addDepend(Render $tpl)
|
||||||
{
|
{
|
||||||
|
// var_dump($tpl->getScm(),"$tpl", (new \Exception())->getTraceAsString() );
|
||||||
$this->_depends[$tpl->getScm()][$tpl->getName()] = $tpl->getTime();
|
$this->_depends[$tpl->getScm()][$tpl->getName()] = $tpl->getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1007,7 +1015,7 @@ class Template extends Render
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse 'is' and 'is not' operators
|
* Parse 'is' and 'is not' operators
|
||||||
* @see $_checkers
|
* @see _tests
|
||||||
* @param Tokenizer $tokens
|
* @param Tokenizer $tokens
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param bool $variable
|
* @param bool $variable
|
||||||
@ -1030,10 +1038,10 @@ class Template extends Render
|
|||||||
if (!$variable && ($action == "set" || $action == "empty")) {
|
if (!$variable && ($action == "set" || $action == "empty")) {
|
||||||
$action = "_$action";
|
$action = "_$action";
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
return $invert . sprintf(self::$_checkers[$action], $value);
|
return $invert . sprintf(self::$_tests[$action], $value);
|
||||||
} elseif (isset(self::$_checkers[$action])) {
|
} elseif (isset(self::$_tests[$action])) {
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
return $invert . sprintf(self::$_checkers[$action], $value);
|
return $invert . sprintf(self::$_tests[$action], $value);
|
||||||
} elseif ($tokens->isSpecialVal()) {
|
} elseif ($tokens->isSpecialVal()) {
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
return '(' . $value . ' ' . $equal . '= ' . $action . ')';
|
return '(' . $value . ' ' . $equal . '= ' . $action . ')';
|
||||||
|
@ -65,7 +65,8 @@ class MacrosTest extends TestCase
|
|||||||
// $this->fenom->compile("macro_recursive.tpl")->display([]);
|
// $this->fenom->compile("macro_recursive.tpl")->display([]);
|
||||||
// $this->fenom->flush();
|
// $this->fenom->flush();
|
||||||
// var_dump($this->fenom->fetch("macro_recursive.tpl", []));
|
// var_dump($this->fenom->fetch("macro_recursive.tpl", []));
|
||||||
var_dump( $this->fenom->compile("macro_recursive_import.tpl")->getTemplateCode([]));
|
var_dump( $this->fenom->compile("macro_recursive_import.tpl")->display([]));
|
||||||
|
var_dump( $this->fenom->display("macro_recursive_import.tpl", []));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
var_dump($e->getMessage() . ": " . $e->getTraceAsString());
|
var_dump($e->getMessage() . ": " . $e->getTraceAsString());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user