Cleanup. Improves.

This commit is contained in:
bzick 2015-01-07 15:24:57 +03:00
parent d4bfb366b8
commit 22fb471c89
5 changed files with 19 additions and 27 deletions

View File

@ -405,9 +405,6 @@ class Fenom
$this->_provider = $provider;
}
public function setCachePerms() {
}
/**
* Set compile directory
*

View File

@ -9,11 +9,9 @@
*/
namespace Fenom;
use Doctrine\Instantiator\Exception\InvalidArgumentException;
use Fenom\Error\InvalidUsageException;
use Fenom\Error\UnexpectedTokenException;
use Fenom\Tokenizer;
use Fenom\Template;
use Fenom\Scope;
/**
* Compilers collection
@ -116,7 +114,7 @@ class Compiler
* @param Tag $scope
* @return string
*/
public static function tagElse(Tokenizer $tokens, Tag $scope)
public static function tagElse($tokens, Tag $scope)
{
$scope["else"] = true;
return '} else {';
@ -247,8 +245,8 @@ class Compiler
"last" => false,
"step" => 1,
"to" => false,
"max" => false,
"min" => false
// "max" => false,
// "min" => false
);
$scope["after"] = $before = $body = array();
$i = array('', '');
@ -263,6 +261,9 @@ class Compiler
$p = $scope->tpl->parseParams($tokens, $p);
if (is_numeric($p["step"])) {
if($p['to'] === false) {
throw new InvalidArgumentException("Invalid value for parameter 'to'");
}
if ($p["step"] > 0) {
$condition = "$var <= {$p['to']}";
if ($p["last"]) {
@ -312,7 +313,7 @@ class Compiler
* @param Tag $scope
* @return string
*/
public static function forElse(Tokenizer $tokens, Tag $scope)
public static function forElse($tokens, Tag $scope)
{
$scope["no-break"] = $scope["no-continue"] = true;
$scope["else"] = true;
@ -436,7 +437,7 @@ class Compiler
* @param Tag $scope
* @return string
*/
public static function switchClose(Tokenizer $tokens, Tag $scope)
public static function switchClose($tokens, Tag $scope)
{
self::_caseResort($scope);
$expr = $scope["var"];
@ -776,7 +777,7 @@ class Compiler
* @param Tag $scope
* @return string
*/
public static function setClose(Tokenizer $tokens, Tag $scope)
public static function setClose($tokens, Tag $scope)
{
return $scope["name"] . '=' . $scope["value"] . ';';
}
@ -787,7 +788,7 @@ class Compiler
* @param Tag $scope
* @return string
*/
public static function filterOpen(Tokenizer $tokens, Tag $scope)
public static function filterOpen($tokens, Tag $scope)
{
$scope["filter"] = $scope->tpl->parseModifier($tokens, "ob_get_clean()");
return "ob_start();";
@ -962,7 +963,7 @@ class Compiler
* @param Tokenizer $tokens
* @param Tag $scope
*/
public static function macroClose(Tokenizer $tokens, Tag $scope)
public static function macroClose($tokens, Tag $scope)
{
if ($scope["recursive"]) {
$scope["macro"]["recursive"] = true;
@ -1017,7 +1018,7 @@ class Compiler
* @param Tokenizer $tokens
* @param Tag $tag
*/
public static function ignoreOpen(Tokenizer $tokens, Tag $tag)
public static function ignoreOpen($tokens, Tag $tag)
{
$tag->tpl->ignore('ignore');
}

View File

@ -1472,8 +1472,6 @@ class Template extends Render
if ($tokens->is("=")) {
$tokens->next();
$params[$key] = $this->parseExpr($tokens);
} else {
$params[$key] = 'true';
}
} elseif ($tokens->is(Tokenizer::MACRO_SCALAR, '"', T_VARIABLE, "[", '(')) {
$params[] = $this->parseExpr($tokens);

View File

@ -8,14 +8,13 @@ class SandboxTest extends TestCase {
public function test()
{
// $this->assertEquals([1, 2, 4, "as" => 767, "df" => ["qert"]], [1, 2, 4, "as" => 767, "df" => ["qet"]]);
// $this->fenom->addBlockCompiler('php', 'Fenom\Compiler::nope', function ($tokens, Tag $tag) {
// return '<?php ' . $tag->cutContent();
// });
// $this->tpl('welcome.tpl', '{$a}');
// try {
// var_dump($this->fenom->compileCode('{$.fetch("welcome.tpl", ["a" => 1])}')->getBody());
// var_dump($this->fenom->compileCode('{for $i=0 to 3} {/for}')->getBody());
// } catch (\Exception $e) {
// print_r($e->getMessage() . "\n" . $e->getTraceAsString());
// while ($e->getPrevious()) {

View File

@ -5,15 +5,12 @@ namespace Fenom;
class TagsTest extends TestCase
{
public function _testSandbox()
/**
* @group test-for
*/
public function testFor()
{
try {
var_dump($this->fenom->compileCode("{var \$a=12313}\nVar: {\$a}")->getBody());
} catch (\Exception $e) {
echo "$e";
}
exit;
$this->assertRender('{for $i=0 to=3}{$i},{/for}', "0,1,2,3,");
}
/**