leilukin-tumbleblog/includes/lib/Twig/Node/Expression/Binary/EndsWithBinary.php

36 lines
890 B
PHP
Raw Permalink Normal View History

2024-06-20 14:10:42 +00:00
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Binary;
use Twig\Compiler;
class EndsWithBinary extends AbstractBinary
{
public function compile(Compiler $compiler): void
{
$left = $compiler->getVarName();
$right = $compiler->getVarName();
$compiler
2024-09-05 17:51:48 +00:00
->raw(\sprintf('(is_string($%s = ', $left))
2024-06-20 14:10:42 +00:00
->subcompile($this->getNode('left'))
2024-09-05 17:51:48 +00:00
->raw(\sprintf(') && is_string($%s = ', $right))
2024-06-20 14:10:42 +00:00
->subcompile($this->getNode('right'))
2024-09-05 17:51:48 +00:00
->raw(\sprintf(') && str_ends_with($%1$s, $%2$s))', $left, $right))
2024-06-20 14:10:42 +00:00
;
}
public function operator(Compiler $compiler): Compiler
{
return $compiler->raw('');
}
}