migrate to php8

This commit is contained in:
ivan shalganov 2023-02-21 22:09:00 +01:00
parent a4fbc2a6aa
commit 3af87c3419
7 changed files with 19 additions and 32 deletions

View File

@ -426,10 +426,8 @@ class Fenom
{
if (is_string($source)) {
$provider = new Fenom\Provider($source);
} elseif ($source instanceof ProviderInterface) {
$provider = $source;
} else {
throw new InvalidArgumentException("Source must be a valid path or provider object");
$provider = $source;
}
$fenom = new static($provider);
$fenom->setCompileDir($compile_dir);

View File

@ -176,7 +176,7 @@ class Provider implements ProviderInterface
if($this->_clear_cache) {
clearstatcache(true, $template);
}
if (@filemtime($template) !== $mtime) {
if (@filemtime($template) != $mtime) {
return false;
}

View File

@ -35,8 +35,8 @@ class Tag extends \ArrayObject
private bool $_closed = true;
private string $_body;
private int $_type = 0;
private string $_open;
private string $_close;
private mixed $_open;
private mixed $_close;
private array $_tags = [];
private array $_floats = [];
private array $_changed = [];

View File

@ -646,7 +646,7 @@ class Template extends Render
{
$action = $tokens->get(Tokenizer::MACRO_STRING);
$tokens->next();
if ($tokens->is("(", T_DOUBLE_COLON, T_NS_SEPARATOR) && !$tokens->isWhiteSpaced()) {
if ($tokens->is("(", T_DOUBLE_COLON, "\\") && !$tokens->isWhiteSpaced()) {
// just invoke function or static method
$tokens->back();
return $this->out($this->parseExpr($tokens));
@ -906,7 +906,7 @@ class Template extends Render
$call = $func . $this->parseArgs($tokens->next());
}
$code = $unary . $this->parseChain($tokens, $call);
} elseif ($tokens->isNext(T_NS_SEPARATOR, T_DOUBLE_COLON)) {
} elseif ($tokens->isNext("\\", T_DOUBLE_COLON)) {
$method = $this->parseStatic($tokens);
$args = $this->parseArgs($tokens);
$code = $unary . $this->parseChain($tokens, $method . $args);
@ -1178,7 +1178,7 @@ class Template extends Render
return $invert . '(' . $value . ' instanceof \\' . $this->parseName($tokens) . ')';
} elseif ($tokens->is(T_VARIABLE, '[', Tokenizer::MACRO_SCALAR, '"')) {
return '(' . $value . ' ' . $equal . '= ' . $this->parseTerm($tokens) . ')';
} elseif ($tokens->is(T_NS_SEPARATOR)) { //
} elseif ($tokens->is("\\")) { //
return $invert . '(' . $value . ' instanceof \\' . $this->parseName($tokens) . ')';
} else {
throw new InvalidUsageException("Unknown argument");
@ -1250,11 +1250,11 @@ class Template extends Render
*/
public function parseName(Tokenizer $tokens): string
{
$tokens->skipIf(T_NS_SEPARATOR);
$tokens->skipIf("\\");
$name = "";
if ($tokens->is(T_STRING)) {
$name .= $tokens->getAndNext();
while ($tokens->is(T_NS_SEPARATOR)) {
while ($tokens->is("\\")) {
$name .= '\\' . $tokens->next()->get(T_STRING);
$tokens->next();
}
@ -1364,7 +1364,7 @@ class Template extends Render
{
while ($tokens->is("|")) {
$modifier = $tokens->getNext(Tokenizer::MACRO_STRING);
if ($tokens->isNext(T_DOUBLE_COLON, T_NS_SEPARATOR)) {
if ($tokens->isNext(T_DOUBLE_COLON, "\\")) {
$mods = $this->parseStatic($tokens);
} else {
$mods = $this->_fenom->getModifier($modifier, $this);
@ -1376,9 +1376,11 @@ class Template extends Render
$args = array();
while ($tokens->is(":")) {
if (($args[] = $this->parseTerm($tokens->next(), $is_var, 0)) === false) {
$term = $this->parseTerm($tokens->next(), $is_var, 0);
if ($term === "") {
throw new UnexpectedTokenException($tokens);
}
$args[] = $term;
}
if (!is_string($mods)) { // dynamic modifier
@ -1496,11 +1498,11 @@ class Template extends Render
if ($this->_options & Fenom::DENY_STATICS) {
throw new \LogicException("Static methods are disabled");
}
$tokens->skipIf(T_NS_SEPARATOR);
$tokens->skipIf("\\");
$name = "";
if ($tokens->is(T_STRING)) {
$name .= $tokens->getAndNext();
while ($tokens->is(T_NS_SEPARATOR)) {
while ($tokens->is("\\")) {
$name .= '\\' . $tokens->next()->get(T_STRING);
$tokens->next();
}

View File

@ -110,7 +110,7 @@ class TestCase extends \PHPUnit\Framework\TestCase
}
}
public function tpl($name, $code)
public function tpl($name, $code): float
{
$dir = dirname($name);
if ($dir != "." && !is_dir(FENOM_RESOURCES . '/template/' . $dir)) {

View File

@ -1202,8 +1202,8 @@ class TemplateTest extends TestCase
$this->values = $vars;
$this->tpl("insert.tpl", $code);
$tpl = $this->fenom->getTemplate('insert.tpl');
$this->assertSame($result, $tpl->fetch($vars));
$this->assertTrue($tpl->isValid());
$this->assertSame($result, $tpl->fetch($vars), $code);
$this->assertTrue($tpl->isValid(), $code);
}
/**

View File

@ -48,25 +48,12 @@ class FenomTest extends \Fenom\TestCase
$fenom->clearAllCompiles();
}
/**
* @expectedException LogicException
* @expectedExceptionMessage Cache directory /invalid/path is not writable
*/
public function testFactoryInvalid()
{
$this->expectException(LogicException::class, "Cache directory /invalid/path is not writable");
Fenom::factory(FENOM_RESOURCES . '/template', '/invalid/path');
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Source must be a valid path or provider object
*/
public function testFactoryInvalid2()
{
Fenom::factory(new StdClass);
}
public function testCompileFile()
{
$a = array(