blob: c3516b853fc22240232ff60406f538a32dc9dc20 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001<?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 EndsWithBinary extends AbstractBinary
17{
18 public function compile(Compiler $compiler): void
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 || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right))
28 ;
29 }
30
31 public function operator(Compiler $compiler): Compiler
32 {
33 return $compiler->raw('');
34 }
35}