Add replacing of parsers

This commit is contained in:
bzick 2013-07-25 02:05:44 +04:00
parent bd69bbd86a
commit 2a64bdb1fc
3 changed files with 8 additions and 25 deletions

View File

@ -3,7 +3,7 @@ Fenom - Template Engine for PHP
> Composer package: `{"fenom/fenom": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/bzick/fenom) > Composer package: `{"fenom/fenom": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/bzick/fenom)
[![Build Status](https://travis-ci.org/bzick/fenom.png?branch=master)](https://travis-ci.org/bzick/fenom) [![Build Status](https://travis-ci.org/bzick/fenom.png?branch=master)](https://travis-ci.org/fenom/fenom)
## [Usage](./docs/usage.md) :: [Documentation](./docs/readme.md) :: [Benchmark](./docs/benchmark.md) :: [Articles](./docs/articles.md) ## [Usage](./docs/usage.md) :: [Documentation](./docs/readme.md) :: [Benchmark](./docs/benchmark.md) :: [Articles](./docs/articles.md)
* Simple [syntax](./docs/syntax.md) * Simple [syntax](./docs/syntax.md)

View File

@ -107,7 +107,6 @@ class Fenom {
"unescape" => 'Fenom\Modifier::unescape', "unescape" => 'Fenom\Modifier::unescape',
"strip" => 'Fenom\Modifier::strip', "strip" => 'Fenom\Modifier::strip',
"length" => 'Fenom\Modifier::length', "length" => 'Fenom\Modifier::length',
"default" => 'Fenom\Modifier::defaultValue',
"iterable" => 'Fenom\Modifier::isIterable' "iterable" => 'Fenom\Modifier::isIterable'
); );
@ -558,12 +557,7 @@ class Fenom {
} }
/** /**
* Set options. May be bitwise mask of constants DENY_METHODS, DENY_INLINE_FUNCS, DENY_SET_VARS, INCLUDE_SOURCES, * Set options
* FORCE_COMPILE, CHECK_MTIME, or associative array with boolean values:
* disable_methods - disable all calls method in template
* disable_native_funcs - disable all native PHP functions in template
* force_compile - recompile template every time (very slow!)
* compile_check - check template modifications (slow!)
* @param int|array $options * @param int|array $options
*/ */
public function setOptions($options) { public function setOptions($options) {
@ -605,7 +599,7 @@ class Fenom {
* @return Fenom\Template * @return Fenom\Template
*/ */
public function getRawTemplate() { public function getRawTemplate() {
return new \Fenom\Template($this, $this->_options); return new Template($this, $this->_options);
} }
/** /**
@ -726,7 +720,7 @@ class Fenom {
*/ */
public function compile($tpl, $store = true, $options = 0) { public function compile($tpl, $store = true, $options = 0) {
$options = $this->_options | $options; $options = $this->_options | $options;
$template = Template::factory($this, $options)->load($tpl); $template = $this->getRawTemplate()->load($tpl);
if($store) { if($store) {
$cache = $this->_getCacheName($tpl, $options); $cache = $this->_getCacheName($tpl, $options);
$tpl_tmp = tempnam($this->_compile_dir, $cache); $tpl_tmp = tempnam($this->_compile_dir, $cache);
@ -766,7 +760,7 @@ class Fenom {
* @return Fenom\Template * @return Fenom\Template
*/ */
public function compileCode($code, $name = 'Runtime compile') { public function compileCode($code, $name = 'Runtime compile') {
return Template::factory($this, $this->_options)->source($name, $code); return $this->getRawTemplate()->source($name, $code);
} }

View File

@ -118,17 +118,6 @@ class Template extends Render {
'third' => '!(%s %% 3)' 'third' => '!(%s %% 3)'
); );
/**
* Just factory
*
* @param \Fenom $fenom
* @param $options
* @return Template
*/
public static function factory(Fenom $fenom, $options) {
return new static($fenom, $options);
}
/** /**
* @param Fenom $fenom Template storage * @param Fenom $fenom Template storage
* @param int $options * @param int $options
@ -215,7 +204,7 @@ class Template extends Render {
$this->_appendText(substr($this->_src, $pos, $start - $pos)); $this->_appendText(substr($this->_src, $pos, $start - $pos));
$end = $start + 1; $end = $start + 1;
do { do {
$need_next_close_symbol = false; $need_more = false;
$end = strpos($this->_src, '}', $end + 1); // search close-symbol of the tag $end = strpos($this->_src, '}', $end + 1); // search close-symbol of the tag
if($end === false) { // if unexpected end of template if($end === false) { // if unexpected end of template
throw new CompileException("Unclosed tag in line {$this->_line}", 0, 1, $this->_name, $this->_line); throw new CompileException("Unclosed tag in line {$this->_line}", 0, 1, $this->_name, $this->_line);
@ -233,7 +222,7 @@ class Template extends Render {
} else { } else {
$tokens = new Tokenizer($_tag); // tokenize the tag $tokens = new Tokenizer($_tag); // tokenize the tag
if($tokens->isIncomplete()) { // all strings finished? if($tokens->isIncomplete()) { // all strings finished?
$need_next_close_symbol = true; $need_more = true;
} else { } else {
$this->_appendCode( $this->parseTag($tokens) , $tag); // start the tag lexer $this->_appendCode( $this->parseTag($tokens) , $tag); // start the tag lexer
if($tokens->key()) { // if tokenizer have tokens - throws exceptions if($tokens->key()) { // if tokenizer have tokens - throws exceptions
@ -241,7 +230,7 @@ class Template extends Render {
} }
} }
} }
} while ($need_next_close_symbol); } while ($need_more);
unset($_tag, $tag); // cleanup unset($_tag, $tag); // cleanup
break; break;
} }