mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
fix for 7.4
This commit is contained in:
parent
fc188a5822
commit
25c9e268b3
@ -9,6 +9,8 @@ php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
|
||||
before_script:
|
||||
- composer global require satooshi/php-coveralls
|
||||
|
@ -15,8 +15,8 @@
|
||||
"ext-tokenizer": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "<6.0",
|
||||
"satooshi/php-coveralls": "*"
|
||||
"phpunit/phpunit": "*",
|
||||
"phpunit/php-code-coverage": "^4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Fenom\\": "src/" },
|
||||
|
1928
composer.lock
generated
1928
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -569,28 +569,34 @@ class Template extends Render
|
||||
* Tag router
|
||||
* @param Tokenizer $tokens
|
||||
*
|
||||
* @throws SecurityException
|
||||
* @throws CompileException
|
||||
* @return string executable PHP code
|
||||
*/
|
||||
public function parseTag(Tokenizer $tokens)
|
||||
{
|
||||
|
||||
try {
|
||||
if ($tokens->is(Tokenizer::MACRO_STRING)) {
|
||||
return $this->parseAct($tokens);
|
||||
} elseif ($tokens->is('/')) {
|
||||
return $this->parseEndTag($tokens);
|
||||
} else {
|
||||
return $this->out($this->parseExpr($tokens));
|
||||
}
|
||||
|
||||
if ($tokens->is('/')) {
|
||||
return $this->parseEndTag($tokens);
|
||||
}
|
||||
|
||||
return $this->out($this->parseExpr($tokens));
|
||||
|
||||
} catch (InvalidUsageException $e) {
|
||||
throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}", 0, E_ERROR, $this->_name, $this->_line, $e);
|
||||
throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}", 0, E_ERROR,
|
||||
$this->_name, $this->_line, $e);
|
||||
} catch (\LogicException $e) {
|
||||
throw new SecurityException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
|
||||
throw new SecurityException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0,
|
||||
0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
|
||||
} catch (\Exception $e) {
|
||||
throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
|
||||
throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0,
|
||||
0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
|
||||
} catch (\Throwable $e) {
|
||||
throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
|
||||
throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0,
|
||||
0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,26 +627,25 @@ class Template extends Render
|
||||
*
|
||||
* @static
|
||||
* @param Tokenizer $tokens
|
||||
* @throws \LogicException
|
||||
* @throws \RuntimeException
|
||||
* @throws Error\TokenizeException
|
||||
* @return string
|
||||
*/
|
||||
public function parseAct(Tokenizer $tokens)
|
||||
{
|
||||
$action = $tokens->get(Tokenizer::MACRO_STRING);
|
||||
$tokens->next();
|
||||
if ($tokens->is("(", T_DOUBLE_COLON, T_NS_SEPARATOR) && !$tokens->isWhiteSpaced()
|
||||
) { // just invoke function or static method
|
||||
if ($tokens->is("(", T_DOUBLE_COLON, T_NS_SEPARATOR) && !$tokens->isWhiteSpaced()) { // just invoke function or static method
|
||||
$tokens->back();
|
||||
return $this->out($this->parseExpr($tokens));
|
||||
} elseif ($tokens->is('.')) {
|
||||
}
|
||||
|
||||
if ($tokens->is('.')) {
|
||||
$name = $tokens->skip()->get(Tokenizer::MACRO_STRING);
|
||||
if ($action !== "macro") {
|
||||
$name = $action . "." . $name;
|
||||
}
|
||||
return $this->parseMacroCall($tokens, $name);
|
||||
}
|
||||
|
||||
if ($info = $this->_fenom->getTag($action, $this)) {
|
||||
$tag = new Tag($action, $this, $info, $this->_body);
|
||||
if ($tokens->is(':')) { // parse tag options
|
||||
@ -652,7 +657,7 @@ class Template extends Render
|
||||
if ($tag->isClosed()) {
|
||||
$tag->restoreAll();
|
||||
} else {
|
||||
array_push($this->_stack, $tag);
|
||||
$this->_stack[] = $tag;
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
@ -662,6 +667,7 @@ class Template extends Render
|
||||
return $this->_stack[$i]->tag($action, $tokens);
|
||||
}
|
||||
}
|
||||
|
||||
if ($tags = $this->_fenom->getTagOwners($action)) { // unknown template tag
|
||||
throw new TokenizeException(
|
||||
"Unexpected tag '$action' (this tag can be used with '" . implode(
|
||||
@ -669,9 +675,9 @@ class Template extends Render
|
||||
$tags
|
||||
) . "')"
|
||||
);
|
||||
} else {
|
||||
throw new TokenizeException("Unexpected tag '$action'");
|
||||
}
|
||||
|
||||
throw new TokenizeException("Unexpected tag '$action'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,7 +254,11 @@ class Tokenizer
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return $this->curr[1];
|
||||
if ($this->curr) {
|
||||
return $this->curr[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -349,9 +353,9 @@ class Tokenizer
|
||||
$cur = $this->curr[1];
|
||||
$this->next();
|
||||
return $cur;
|
||||
} else {
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -395,9 +399,9 @@ class Tokenizer
|
||||
{
|
||||
if ($this->curr && $this->_valid(func_get_args(), $this->curr[0])) {
|
||||
return $this->curr[1];
|
||||
} else {
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -478,20 +482,24 @@ class Tokenizer
|
||||
/**
|
||||
* Get token name
|
||||
* @static
|
||||
* @param int|string $token
|
||||
* @param int|string|array $token
|
||||
* @return string
|
||||
*/
|
||||
public static function getName($token)
|
||||
{
|
||||
if (is_string($token)) {
|
||||
return $token;
|
||||
} elseif (is_integer($token)) {
|
||||
return token_name($token);
|
||||
} elseif (is_array($token)) {
|
||||
return token_name($token[0]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($token)) {
|
||||
return token_name($token);
|
||||
}
|
||||
|
||||
if (is_array($token)) {
|
||||
return token_name($token[0]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -506,13 +514,13 @@ class Tokenizer
|
||||
if ($this->_valid(func_get_args(), $this->curr[0])) {
|
||||
$this->next();
|
||||
return $this;
|
||||
} else {
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
} else {
|
||||
$this->next();
|
||||
return $this;
|
||||
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
|
||||
$this->next();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -523,7 +531,7 @@ class Tokenizer
|
||||
*/
|
||||
public function skipIf($token1 /*, $token2, ...*/)
|
||||
{
|
||||
if ($this->_valid(func_get_args(), $this->curr[0])) {
|
||||
if ($this->curr && $this->_valid(func_get_args(), $this->curr[0])) {
|
||||
$this->next();
|
||||
}
|
||||
return $this;
|
||||
@ -538,11 +546,11 @@ class Tokenizer
|
||||
*/
|
||||
public function need($token1 /*, $token2, ...*/)
|
||||
{
|
||||
if ($this->_valid(func_get_args(), $this->curr[0])) {
|
||||
if ($this->curr && $this->_valid(func_get_args(), $this->curr[0])) {
|
||||
return $this;
|
||||
} else {
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
|
||||
throw new UnexpectedTokenException($this, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user