mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
commit
feb3a51884
@ -648,10 +648,10 @@ class Compiler
|
|||||||
public static function stdFuncParser(Tokenizer $tokens, Tag $tag)
|
public static function stdFuncParser(Tokenizer $tokens, Tag $tag)
|
||||||
{
|
{
|
||||||
if(is_string($tag->callback)) {
|
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 {
|
} else {
|
||||||
return '$info = $tpl->getStorage()->getTag('.var_export($tag->name, true).');'.PHP_EOL.
|
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);
|
$tag->restore(\Fenom::AUTO_ESCAPE);
|
||||||
if(is_string($tag->callback)) {
|
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 {
|
} else {
|
||||||
return '$info = $tpl->getStorage()->getTag('.var_export($tag->name, true).');'.PHP_EOL.
|
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))');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ class Modifier
|
|||||||
if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) {
|
if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) {
|
||||||
if (count($match) == 3) {
|
if (count($match) == 3) {
|
||||||
if ($by_words) {
|
if ($by_words) {
|
||||||
return preg_replace('#\s.*$#usS', "", $match[1]) .
|
return preg_replace('#\s\S*$#usS', "", $match[1]) .
|
||||||
$etc .
|
$etc .
|
||||||
preg_replace('#.*\s#usS', "", $match[2]);
|
preg_replace('#\S*\s#usS', "", $match[2]);
|
||||||
} else {
|
} else {
|
||||||
return $match[1] . $etc . $match[2];
|
return $match[1] . $etc . $match[2];
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ class Modifier
|
|||||||
} else {
|
} else {
|
||||||
if (preg_match('#^(.{' . $length . '})#usS', $string, $match)) {
|
if (preg_match('#^(.{' . $length . '})#usS', $string, $match)) {
|
||||||
if ($by_words) {
|
if ($by_words) {
|
||||||
return preg_replace('#\s.*$#usS', "", $match[1]) . $etc;
|
return preg_replace('#\s\S*$#usS', "", $match[1]) . $etc;
|
||||||
} else {
|
} else {
|
||||||
return $match[1] . $etc;
|
return $match[1] . $etc;
|
||||||
}
|
}
|
||||||
@ -170,10 +170,12 @@ class Modifier
|
|||||||
*/
|
*/
|
||||||
public static function in($value, $haystack)
|
public static function in($value, $haystack)
|
||||||
{
|
{
|
||||||
if (is_array($haystack)) {
|
if(is_scalar($value)) {
|
||||||
return in_array($value, $haystack) || array_key_exists($value, $haystack);
|
if (is_array($haystack)) {
|
||||||
} elseif (is_string($haystack)) {
|
return in_array($value, $haystack) || array_key_exists($value, $haystack);
|
||||||
return strpos($haystack, $value) !== false;
|
} elseif (is_string($haystack)) {
|
||||||
|
return strpos($haystack, $value) !== false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,12 @@ class TestCase extends \PHPUnit_Framework_TestCase
|
|||||||
"b" => 2,
|
"b" => 2,
|
||||||
"two" => 2
|
"two" => 2
|
||||||
),
|
),
|
||||||
|
"level1" => array(
|
||||||
|
"level2" => array(
|
||||||
|
"one" => 1,
|
||||||
|
"two" => 2
|
||||||
|
)
|
||||||
|
),
|
||||||
"num" => array(
|
"num" => array(
|
||||||
1 => "one",
|
1 => "one",
|
||||||
2 => "two",
|
2 => "two",
|
||||||
|
@ -1184,6 +1184,9 @@ class TemplateTest extends TestCase
|
|||||||
array('{if $one in ["one", "two", "three"]} block1 {else} block2 {/if}', 'block2'),
|
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 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 $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'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user