Merge pull request #131 from bzick/develop

small fixes
This commit is contained in:
Ivan Shalganov 2015-01-07 17:42:58 +03:00
commit e4a7a07107
5 changed files with 18 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('', '');
@ -312,7 +310,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 +434,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 +774,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 +785,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 +960,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 +1015,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

@ -1467,13 +1467,13 @@ class Template extends Render
if ($tokens->is(Tokenizer::MACRO_STRING)) {
$key = $tokens->getAndNext();
if ($defaults && !isset($defaults[$key])) {
throw new \Exception("Unknown parameter '$key'");
throw new InvalidUsageException("Unknown parameter '$key'");
}
if ($tokens->is("=")) {
$tokens->next();
$params[$key] = $this->parseExpr($tokens);
} else {
$params[$key] = 'true';
throw new InvalidUsageException("Invalid value for parameter '$key'");
}
} 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,");
}
/**