migrate to php8
This commit is contained in:
parent
a4fbc2a6aa
commit
3af87c3419
|
@ -426,10 +426,8 @@ class Fenom
|
||||||
{
|
{
|
||||||
if (is_string($source)) {
|
if (is_string($source)) {
|
||||||
$provider = new Fenom\Provider($source);
|
$provider = new Fenom\Provider($source);
|
||||||
} elseif ($source instanceof ProviderInterface) {
|
|
||||||
$provider = $source;
|
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException("Source must be a valid path or provider object");
|
$provider = $source;
|
||||||
}
|
}
|
||||||
$fenom = new static($provider);
|
$fenom = new static($provider);
|
||||||
$fenom->setCompileDir($compile_dir);
|
$fenom->setCompileDir($compile_dir);
|
||||||
|
|
|
@ -176,7 +176,7 @@ class Provider implements ProviderInterface
|
||||||
if($this->_clear_cache) {
|
if($this->_clear_cache) {
|
||||||
clearstatcache(true, $template);
|
clearstatcache(true, $template);
|
||||||
}
|
}
|
||||||
if (@filemtime($template) !== $mtime) {
|
if (@filemtime($template) != $mtime) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ class Tag extends \ArrayObject
|
||||||
private bool $_closed = true;
|
private bool $_closed = true;
|
||||||
private string $_body;
|
private string $_body;
|
||||||
private int $_type = 0;
|
private int $_type = 0;
|
||||||
private string $_open;
|
private mixed $_open;
|
||||||
private string $_close;
|
private mixed $_close;
|
||||||
private array $_tags = [];
|
private array $_tags = [];
|
||||||
private array $_floats = [];
|
private array $_floats = [];
|
||||||
private array $_changed = [];
|
private array $_changed = [];
|
||||||
|
|
|
@ -646,7 +646,7 @@ class Template extends Render
|
||||||
{
|
{
|
||||||
$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, "\\") && !$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));
|
||||||
|
@ -906,7 +906,7 @@ class Template extends Render
|
||||||
$call = $func . $this->parseArgs($tokens->next());
|
$call = $func . $this->parseArgs($tokens->next());
|
||||||
}
|
}
|
||||||
$code = $unary . $this->parseChain($tokens, $call);
|
$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);
|
$method = $this->parseStatic($tokens);
|
||||||
$args = $this->parseArgs($tokens);
|
$args = $this->parseArgs($tokens);
|
||||||
$code = $unary . $this->parseChain($tokens, $method . $args);
|
$code = $unary . $this->parseChain($tokens, $method . $args);
|
||||||
|
@ -1178,7 +1178,7 @@ class Template extends Render
|
||||||
return $invert . '(' . $value . ' instanceof \\' . $this->parseName($tokens) . ')';
|
return $invert . '(' . $value . ' instanceof \\' . $this->parseName($tokens) . ')';
|
||||||
} elseif ($tokens->is(T_VARIABLE, '[', Tokenizer::MACRO_SCALAR, '"')) {
|
} elseif ($tokens->is(T_VARIABLE, '[', Tokenizer::MACRO_SCALAR, '"')) {
|
||||||
return '(' . $value . ' ' . $equal . '= ' . $this->parseTerm($tokens) . ')';
|
return '(' . $value . ' ' . $equal . '= ' . $this->parseTerm($tokens) . ')';
|
||||||
} elseif ($tokens->is(T_NS_SEPARATOR)) { //
|
} elseif ($tokens->is("\\")) { //
|
||||||
return $invert . '(' . $value . ' instanceof \\' . $this->parseName($tokens) . ')';
|
return $invert . '(' . $value . ' instanceof \\' . $this->parseName($tokens) . ')';
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidUsageException("Unknown argument");
|
throw new InvalidUsageException("Unknown argument");
|
||||||
|
@ -1250,11 +1250,11 @@ class Template extends Render
|
||||||
*/
|
*/
|
||||||
public function parseName(Tokenizer $tokens): string
|
public function parseName(Tokenizer $tokens): string
|
||||||
{
|
{
|
||||||
$tokens->skipIf(T_NS_SEPARATOR);
|
$tokens->skipIf("\\");
|
||||||
$name = "";
|
$name = "";
|
||||||
if ($tokens->is(T_STRING)) {
|
if ($tokens->is(T_STRING)) {
|
||||||
$name .= $tokens->getAndNext();
|
$name .= $tokens->getAndNext();
|
||||||
while ($tokens->is(T_NS_SEPARATOR)) {
|
while ($tokens->is("\\")) {
|
||||||
$name .= '\\' . $tokens->next()->get(T_STRING);
|
$name .= '\\' . $tokens->next()->get(T_STRING);
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
}
|
}
|
||||||
|
@ -1364,7 +1364,7 @@ class Template extends Render
|
||||||
{
|
{
|
||||||
while ($tokens->is("|")) {
|
while ($tokens->is("|")) {
|
||||||
$modifier = $tokens->getNext(Tokenizer::MACRO_STRING);
|
$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);
|
$mods = $this->parseStatic($tokens);
|
||||||
} else {
|
} else {
|
||||||
$mods = $this->_fenom->getModifier($modifier, $this);
|
$mods = $this->_fenom->getModifier($modifier, $this);
|
||||||
|
@ -1376,9 +1376,11 @@ class Template extends Render
|
||||||
|
|
||||||
$args = array();
|
$args = array();
|
||||||
while ($tokens->is(":")) {
|
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);
|
throw new UnexpectedTokenException($tokens);
|
||||||
}
|
}
|
||||||
|
$args[] = $term;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_string($mods)) { // dynamic modifier
|
if (!is_string($mods)) { // dynamic modifier
|
||||||
|
@ -1496,11 +1498,11 @@ class Template extends Render
|
||||||
if ($this->_options & Fenom::DENY_STATICS) {
|
if ($this->_options & Fenom::DENY_STATICS) {
|
||||||
throw new \LogicException("Static methods are disabled");
|
throw new \LogicException("Static methods are disabled");
|
||||||
}
|
}
|
||||||
$tokens->skipIf(T_NS_SEPARATOR);
|
$tokens->skipIf("\\");
|
||||||
$name = "";
|
$name = "";
|
||||||
if ($tokens->is(T_STRING)) {
|
if ($tokens->is(T_STRING)) {
|
||||||
$name .= $tokens->getAndNext();
|
$name .= $tokens->getAndNext();
|
||||||
while ($tokens->is(T_NS_SEPARATOR)) {
|
while ($tokens->is("\\")) {
|
||||||
$name .= '\\' . $tokens->next()->get(T_STRING);
|
$name .= '\\' . $tokens->next()->get(T_STRING);
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ class TestCase extends \PHPUnit\Framework\TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tpl($name, $code)
|
public function tpl($name, $code): float
|
||||||
{
|
{
|
||||||
$dir = dirname($name);
|
$dir = dirname($name);
|
||||||
if ($dir != "." && !is_dir(FENOM_RESOURCES . '/template/' . $dir)) {
|
if ($dir != "." && !is_dir(FENOM_RESOURCES . '/template/' . $dir)) {
|
||||||
|
|
|
@ -1202,8 +1202,8 @@ class TemplateTest extends TestCase
|
||||||
$this->values = $vars;
|
$this->values = $vars;
|
||||||
$this->tpl("insert.tpl", $code);
|
$this->tpl("insert.tpl", $code);
|
||||||
$tpl = $this->fenom->getTemplate('insert.tpl');
|
$tpl = $this->fenom->getTemplate('insert.tpl');
|
||||||
$this->assertSame($result, $tpl->fetch($vars));
|
$this->assertSame($result, $tpl->fetch($vars), $code);
|
||||||
$this->assertTrue($tpl->isValid());
|
$this->assertTrue($tpl->isValid(), $code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,25 +48,12 @@ class FenomTest extends \Fenom\TestCase
|
||||||
$fenom->clearAllCompiles();
|
$fenom->clearAllCompiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException LogicException
|
|
||||||
* @expectedExceptionMessage Cache directory /invalid/path is not writable
|
|
||||||
*/
|
|
||||||
public function testFactoryInvalid()
|
public function testFactoryInvalid()
|
||||||
{
|
{
|
||||||
|
$this->expectException(LogicException::class, "Cache directory /invalid/path is not writable");
|
||||||
Fenom::factory(FENOM_RESOURCES . '/template', '/invalid/path');
|
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()
|
public function testCompileFile()
|
||||||
{
|
{
|
||||||
$a = array(
|
$a = array(
|
||||||
|
|
Loading…
Reference in New Issue