diff --git a/src/Fenom/Compiler.php b/src/Fenom/Compiler.php index 5b0f2e3..4b11604 100644 --- a/src/Fenom/Compiler.php +++ b/src/Fenom/Compiler.php @@ -648,10 +648,10 @@ class Compiler public static function stdFuncParser(Tokenizer $tokens, Tag $tag) { if(is_string($tag->callback)) { - return $tag->out($tag->callback . "(" . self::toArray($tag->tpl->parseParams($tokens)) . ', $tpl)'); + return $tag->out($tag->callback . "(" . self::toArray($tag->tpl->parseParams($tokens)) . ', $tpl, $var)'); } else { return '$info = $tpl->getStorage()->getTag('.var_export($tag->name, true).');'.PHP_EOL. - $tag->out('call_user_func($info["function"], '.self::toArray($tag->tpl->parseParams($tokens)).', $tpl)'); + $tag->out('call_user_func_array($info["function"], array('.self::toArray($tag->tpl->parseParams($tokens)).', $tpl, &$var))'); } } @@ -709,10 +709,10 @@ class Compiler { $tag->restore(\Fenom::AUTO_ESCAPE); if(is_string($tag->callback)) { - return $tag->out($tag->callback . "(" . $tag["params"] . ', ob_get_clean(), $tpl)'); + return $tag->out($tag->callback . "(" . $tag["params"] . ', ob_get_clean(), $tpl, $var)'); } else { return '$info = $tpl->getStorage()->getTag('.var_export($tag->name, true).');'.PHP_EOL. - $tag->out('call_user_func($info["function"], ' . $tag["params"] . ', ob_get_clean(), $tpl)'); + $tag->out('call_user_func_array($info["function"], array(' . $tag["params"] . ', ob_get_clean(), $tpl, &$var))'); } } diff --git a/src/Fenom/Modifier.php b/src/Fenom/Modifier.php index cf9fc57..cde94f3 100644 --- a/src/Fenom/Modifier.php +++ b/src/Fenom/Modifier.php @@ -107,9 +107,9 @@ class Modifier if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) { if (count($match) == 3) { if ($by_words) { - return preg_replace('#\s.*$#usS', "", $match[1]) . + return preg_replace('#\s\S*$#usS', "", $match[1]) . $etc . - preg_replace('#.*\s#usS', "", $match[2]); + preg_replace('#\S*\s#usS', "", $match[2]); } else { return $match[1] . $etc . $match[2]; } @@ -118,7 +118,7 @@ class Modifier } else { if (preg_match('#^(.{' . $length . '})#usS', $string, $match)) { if ($by_words) { - return preg_replace('#\s.*$#usS', "", $match[1]) . $etc; + return preg_replace('#\s\S*$#usS', "", $match[1]) . $etc; } else { return $match[1] . $etc; } @@ -170,10 +170,12 @@ class Modifier */ public static function in($value, $haystack) { - if (is_array($haystack)) { - return in_array($value, $haystack) || array_key_exists($value, $haystack); - } elseif (is_string($haystack)) { - return strpos($haystack, $value) !== false; + if(is_scalar($value)) { + if (is_array($haystack)) { + return in_array($value, $haystack) || array_key_exists($value, $haystack); + } elseif (is_string($haystack)) { + return strpos($haystack, $value) !== false; + } } return false; } diff --git a/tests/TestCase.php b/tests/TestCase.php index d20effd..9f97fdb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -29,6 +29,12 @@ class TestCase extends \PHPUnit_Framework_TestCase "b" => 2, "two" => 2 ), + "level1" => array( + "level2" => array( + "one" => 1, + "two" => 2 + ) + ), "num" => array( 1 => "one", 2 => "two", diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index cd8a093..22af39e 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -1184,6 +1184,9 @@ class TemplateTest extends TestCase array('{if $one in ["one", "two", "three"]} block1 {else} block2 {/if}', 'block2'), array('{if $one in keys [1 => "one", 2 => "two", 3 => "three"]} block1 {else} block2 {/if}', 'block1'), array('{if $one in $two} block1 {else} block2 {/if}', 'block2'), + array('{if $one in $list} block1 {else} block2 {/if}', 'block1'), + array('{if "one" in $num} block1 {else} block2 {/if}', 'block1'), + array('{if "one" in $level1.level2} block1 {else} block2 {/if}', 'block1'), ); }