diff --git a/sandbox/fenom.php b/sandbox/fenom.php index e4709c9..8d8877f 100644 --- a/sandbox/fenom.php +++ b/sandbox/fenom.php @@ -6,11 +6,13 @@ require_once __DIR__.'/../tests/tools.php'; \Fenom::registerAutoload(); $fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled'); -$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_VERIFY | Fenom::FORCE_INCLUDE); +//$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_VERIFY | Fenom::FORCE_INCLUDE); //var_dump($fenom->compile("nested.tpl", [])->getTemplateCode()); //exit; -var_dump($fenom->compile('bug241/recursive.tpl', false)->getBody()); +//var_dump($fenom->compile('bug241/recursive.tpl', false)->getBody()); //var_dump($fenom->compile('bug249/bread.tpl', false)->getBody()); //var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode()); //var_dump($fenom->display("bug158/main.tpl", [])); // $fenom->getTemplate("problem.tpl"); + +var_dump($fenom->compileCode('{$.php.Fenom::factory()->addDay()}')->getBody()); diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index b6912c7..ec8a90e 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -829,7 +829,14 @@ class Template extends Render case '$': $code = $this->parseAccessor($tokens, $is_var); if (!$is_var) { - $code = $unary . $code; + if($tokens->is(T_OBJECT_OPERATOR)) { + if ($this->_options & Fenom::DENY_METHODS) { + throw new \LogicException("Forbidden to call methods"); + } + $code = $unary . $this->parseChain($tokens, $code); + } else { + $code = $unary . $code; + } break; } /* no break */ diff --git a/tests/cases/Fenom/AccessorTest.php b/tests/cases/Fenom/AccessorTest.php index ff82496..cff346a 100644 --- a/tests/cases/Fenom/AccessorTest.php +++ b/tests/cases/Fenom/AccessorTest.php @@ -94,58 +94,66 @@ class AccessorTest extends TestCase } - public static function providerPHP() { + public static function providerCall() { return array( - array('$.php.strrev("string")', strrev("string")), - array('$.php.strrev("string")', strrev("string"), 'str*'), - array('$.php.strrev("string")', strrev("string"), 'strrev'), - array('$.php.get_current_user', get_current_user()), - array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12)), - array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\\*'), - array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\helper_func'), - array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), '*helper_func'), - array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), '*'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string")), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase*'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::*'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::dots'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::*'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::dots'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*::dots'), - array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*'), + array('$.call.strrev("string")', strrev("string")), + array('$.call.strrev("string")', strrev("string"), 'str*'), + array('$.call.strrev("string")', strrev("string"), 'strrev'), + array('$.call.get_current_user', get_current_user()), + array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12)), + array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\\*'), + array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\helper_func'), + array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), '*helper_func'), + array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), '*'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string")), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase*'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::*'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::dots'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::*'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::dots'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*::dots'), + array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*'), ); } /** - * @dataProvider providerPHP + * @dataProvider providerCall * @group php */ - public function testPHP($tpl, $result, $mask = null) { + public function testCall($tpl, $result, $mask = null) { if($mask) { $this->fenom->addCallFilter($mask); } $this->assertRender('{'.$tpl.'}', $result); } + /** + * @group issue260 + */ + public function testBug260() { + $this->fenom->compileCode('{$.php.Fenom::factory()->addDay()}'); + } + + public static function providerPHPInvalid() { return array( - array('$.php.aaa("string")', 'Fenom\Error\CompileException', 'PHP method aaa does not exists'), - array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'strrevZ'), - array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'str*Z'), - array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', '*Z'), - array('$.php.Fenom.aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.aaa does not exists'), - array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Reflection\*'), - array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*Z'), - array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*::*'), - array('$.php.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method TestCase::aaa does not exists'), - array('$.php.Fenom.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.TestCase::aaa does not exists'), - array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Reflection\*'), - array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*Z'), - array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*::get*'), - array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::get*'), - array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::*Z'), - array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', '*::*Z'), + array('$.call.aaa("string")', 'Fenom\Error\CompileException', 'PHP method aaa does not exists'), + array('$.call.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'strrevZ'), + array('$.call.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'str*Z'), + array('$.call.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', '*Z'), + array('$.call.Fenom.aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.aaa does not exists'), + array('$.call.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Reflection\*'), + array('$.call.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*Z'), + array('$.call.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*::*'), + array('$.call.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method TestCase::aaa does not exists'), + array('$.call.Fenom.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.TestCase::aaa does not exists'), + array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Reflection\*'), + array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*Z'), + array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*::get*'), + array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::get*'), + array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::*Z'), + array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', '*::*Z'), ); } @@ -258,7 +266,7 @@ class AccessorTest extends TestCase } /** - * @group dev + * */ public function testCallbackAccessor() { $index = 1; diff --git a/tests/cases/Fenom/RenderTest.php b/tests/cases/Fenom/RenderTest.php index fdcd07a..149aa45 100644 --- a/tests/cases/Fenom/RenderTest.php +++ b/tests/cases/Fenom/RenderTest.php @@ -4,7 +4,7 @@ namespace Fenom; use Fenom, Fenom\Render; -class RenderTest extends \PHPUnit_Framework_TestCase +class RenderTest extends TestCase { /** diff --git a/tests/cases/Fenom/TokenizerTest.php b/tests/cases/Fenom/TokenizerTest.php index 02dca99..dd07c60 100644 --- a/tests/cases/Fenom/TokenizerTest.php +++ b/tests/cases/Fenom/TokenizerTest.php @@ -4,7 +4,7 @@ namespace Fenom; use Fenom\Error\UnexpectedTokenException; use Fenom\Tokenizer; -class TokenizerTest extends \PHPUnit_Framework_TestCase +class TokenizerTest extends TestCase { public function testGetName()