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

View File

@ -15,8 +15,8 @@
"ext-tokenizer": "*" "ext-tokenizer": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "<6.0", "phpunit/phpunit": "*",
"satooshi/php-coveralls": "*" "phpunit/php-code-coverage": "^4"
}, },
"autoload": { "autoload": {
"psr-0": { "Fenom\\": "src/" }, "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 * Tag router
* @param Tokenizer $tokens * @param Tokenizer $tokens
* *
* @throws SecurityException
* @throws CompileException
* @return string executable PHP code * @return string executable PHP code
*/ */
public function parseTag(Tokenizer $tokens) public function parseTag(Tokenizer $tokens)
{ {
try { try {
if ($tokens->is(Tokenizer::MACRO_STRING)) { if ($tokens->is(Tokenizer::MACRO_STRING)) {
return $this->parseAct($tokens); 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) { } 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) { } 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) { } 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) { } 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 * @static
* @param Tokenizer $tokens * @param Tokenizer $tokens
* @throws \LogicException
* @throws \RuntimeException
* @throws Error\TokenizeException
* @return string * @return string
*/ */
public function parseAct(Tokenizer $tokens) public function parseAct(Tokenizer $tokens)
{ {
$action = $tokens->get(Tokenizer::MACRO_STRING); $action = $tokens->get(Tokenizer::MACRO_STRING);
$tokens->next(); $tokens->next();
if ($tokens->is("(", T_DOUBLE_COLON, T_NS_SEPARATOR) && !$tokens->isWhiteSpaced() if ($tokens->is("(", T_DOUBLE_COLON, T_NS_SEPARATOR) && !$tokens->isWhiteSpaced()) { // just invoke function or static method
) { // just invoke function or static method
$tokens->back(); $tokens->back();
return $this->out($this->parseExpr($tokens)); return $this->out($this->parseExpr($tokens));
} elseif ($tokens->is('.')) { }
if ($tokens->is('.')) {
$name = $tokens->skip()->get(Tokenizer::MACRO_STRING); $name = $tokens->skip()->get(Tokenizer::MACRO_STRING);
if ($action !== "macro") { if ($action !== "macro") {
$name = $action . "." . $name; $name = $action . "." . $name;
} }
return $this->parseMacroCall($tokens, $name); return $this->parseMacroCall($tokens, $name);
} }
if ($info = $this->_fenom->getTag($action, $this)) { if ($info = $this->_fenom->getTag($action, $this)) {
$tag = new Tag($action, $this, $info, $this->_body); $tag = new Tag($action, $this, $info, $this->_body);
if ($tokens->is(':')) { // parse tag options if ($tokens->is(':')) { // parse tag options
@ -652,7 +657,7 @@ class Template extends Render
if ($tag->isClosed()) { if ($tag->isClosed()) {
$tag->restoreAll(); $tag->restoreAll();
} else { } else {
array_push($this->_stack, $tag); $this->_stack[] = $tag;
} }
return $code; return $code;
} }
@ -662,6 +667,7 @@ class Template extends Render
return $this->_stack[$i]->tag($action, $tokens); return $this->_stack[$i]->tag($action, $tokens);
} }
} }
if ($tags = $this->_fenom->getTagOwners($action)) { // unknown template tag if ($tags = $this->_fenom->getTagOwners($action)) { // unknown template tag
throw new TokenizeException( throw new TokenizeException(
"Unexpected tag '$action' (this tag can be used with '" . implode( "Unexpected tag '$action' (this tag can be used with '" . implode(
@ -669,9 +675,9 @@ class Template extends Render
$tags $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() 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]; $cur = $this->curr[1];
$this->next(); $this->next();
return $cur; 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])) { if ($this->curr && $this->_valid(func_get_args(), $this->curr[0])) {
return $this->curr[1]; 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 * Get token name
* @static * @static
* @param int|string $token * @param int|string|array $token
* @return string * @return string
*/ */
public static function getName($token) public static function getName($token)
{ {
if (is_string($token)) { if (is_string($token)) {
return $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])) { if ($this->_valid(func_get_args(), $this->curr[0])) {
$this->next(); $this->next();
return $this; return $this;
} else {
throw new UnexpectedTokenException($this, func_get_args());
} }
} else {
$this->next(); throw new UnexpectedTokenException($this, func_get_args());
return $this;
} }
$this->next();
return $this;
} }
/** /**
@ -523,7 +531,7 @@ class Tokenizer
*/ */
public function skipIf($token1 /*, $token2, ...*/) 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(); $this->next();
} }
return $this; return $this;
@ -538,11 +546,11 @@ class Tokenizer
*/ */
public function need($token1 /*, $token2, ...*/) 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; return $this;
} else {
throw new UnexpectedTokenException($this, func_get_args());
} }
throw new UnexpectedTokenException($this, func_get_args());
} }
/** /**