This commit is contained in:
Maksim 2020-01-30 20:08:09 +03:00 committed by GitHub
commit 96442a5185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 1978 deletions

View File

@ -1,7 +1,5 @@
language: php
sudo: false
php:
- 5.4
- 5.5
@ -9,13 +7,20 @@ php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
before_script:
- composer global require satooshi/php-coveralls
# - composer update --dev --quiet
matrix:
allow_failures:
- php: 5.4
- php: 5.5
- php: nightly
install: composer install --dev
script:
- phpunit -c phpunit.xml.dist
- php vendor/bin/phpunit -c phpunit.xml.dist
after_script:
- coveralls
after_success:
- travis_retry php vendor/bin/php-coveralls

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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'");
}
/**

View File

@ -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());
}
/**