1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Twig\Node\Expression\Binary; 13 14use Twig\Compiler; 15 16class StartsWithBinary extends AbstractBinary 17{ 18 public function compile(Compiler $compiler) 19 { 20 $left = $compiler->getVarName(); 21 $right = $compiler->getVarName(); 22 $compiler 23 ->raw(sprintf('(is_string($%s = ', $left)) 24 ->subcompile($this->getNode('left')) 25 ->raw(sprintf(') && is_string($%s = ', $right)) 26 ->subcompile($this->getNode('right')) 27 ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right)) 28 ; 29 } 30 31 public function operator(Compiler $compiler) 32 { 33 return $compiler->raw(''); 34 } 35} 36 37class_alias('Twig\Node\Expression\Binary\StartsWithBinary', 'Twig_Node_Expression_Binary_StartsWith'); 38