return $this;
}
+
+ public function getVarName()
+ {
+ return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
+ }
}
{
public function compile(Twig_Compiler $compiler)
{
+ $varName = $compiler->getVarName();
$compiler
- ->raw('(0 === strpos(')
- ->subcompile($this->getNode('left'))
- ->raw(', ')
+ ->raw(sprintf("(('' === (\$%s = ", $varName))
->subcompile($this->getNode('right'))
- ->raw('))')
+ ->raw(')) ? true : 0 === strpos(')
+ ->subcompile($this->getNode('left'))
+ ->raw(sprintf(', $%s))', $varName))
;
}
{{ 'foo' starts with 'f' ? 'OK' : 'KO' }}
{{ 'foo' starts
with 'f' ? 'OK' : 'KO' }}
+{{ 'foo' starts with '' ? 'OK' : 'KO' }}
+{{ '1' starts with true ? 'OK' : 'KO' }}
+{{ '' starts with false ? 'OK' : 'KO' }}
+{{ 'a' starts with false ? 'OK' : 'KO' }}
--DATA--
return array()
--EXPECT--
OK
OK
OK
+OK
+KO
+KO
+KO