Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/sitepres.../lib/twig/src/Node
File: ForNode.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of Twig.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier
[5] Fix | Delete
* (c) Armin Ronacher
[6] Fix | Delete
*
[7] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[8] Fix | Delete
* file that was distributed with this source code.
[9] Fix | Delete
*/
[10] Fix | Delete
namespace WPML\Core\Twig\Node;
[11] Fix | Delete
[12] Fix | Delete
use WPML\Core\Twig\Compiler;
[13] Fix | Delete
use WPML\Core\Twig\Node\Expression\AbstractExpression;
[14] Fix | Delete
use WPML\Core\Twig\Node\Expression\AssignNameExpression;
[15] Fix | Delete
/**
[16] Fix | Delete
* Represents a for node.
[17] Fix | Delete
*
[18] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[19] Fix | Delete
*/
[20] Fix | Delete
class ForNode extends \WPML\Core\Twig\Node\Node
[21] Fix | Delete
{
[22] Fix | Delete
protected $loop;
[23] Fix | Delete
public function __construct(\WPML\Core\Twig\Node\Expression\AssignNameExpression $keyTarget, \WPML\Core\Twig\Node\Expression\AssignNameExpression $valueTarget, \WPML\Core\Twig\Node\Expression\AbstractExpression $seq, \WPML\Core\Twig\Node\Expression\AbstractExpression $ifexpr = null, \WPML\Core\Twig_NodeInterface $body, \WPML\Core\Twig_NodeInterface $else = null, $lineno, $tag = null)
[24] Fix | Delete
{
[25] Fix | Delete
$body = new \WPML\Core\Twig\Node\Node([$body, $this->loop = new \WPML\Core\Twig\Node\ForLoopNode($lineno, $tag)]);
[26] Fix | Delete
if (null !== $ifexpr) {
[27] Fix | Delete
$body = new \WPML\Core\Twig\Node\IfNode(new \WPML\Core\Twig\Node\Node([$ifexpr, $body]), null, $lineno, $tag);
[28] Fix | Delete
}
[29] Fix | Delete
$nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body];
[30] Fix | Delete
if (null !== $else) {
[31] Fix | Delete
$nodes['else'] = $else;
[32] Fix | Delete
}
[33] Fix | Delete
parent::__construct($nodes, ['with_loop' => \true, 'ifexpr' => null !== $ifexpr], $lineno, $tag);
[34] Fix | Delete
}
[35] Fix | Delete
public function compile(\WPML\Core\Twig\Compiler $compiler)
[36] Fix | Delete
{
[37] Fix | Delete
$compiler->addDebugInfo($this)->write("\$context['_parent'] = \$context;\n")->write("\$context['_seq'] = twig_ensure_traversable(")->subcompile($this->getNode('seq'))->raw(");\n");
[38] Fix | Delete
if ($this->hasNode('else')) {
[39] Fix | Delete
$compiler->write("\$context['_iterated'] = false;\n");
[40] Fix | Delete
}
[41] Fix | Delete
if ($this->getAttribute('with_loop')) {
[42] Fix | Delete
$compiler->write("\$context['loop'] = [\n")->write(" 'parent' => \$context['_parent'],\n")->write(" 'index0' => 0,\n")->write(" 'index' => 1,\n")->write(" 'first' => true,\n")->write("];\n");
[43] Fix | Delete
if (!$this->getAttribute('ifexpr')) {
[44] Fix | Delete
$compiler->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof \\Countable)) {\n")->indent()->write("\$length = count(\$context['_seq']);\n")->write("\$context['loop']['revindex0'] = \$length - 1;\n")->write("\$context['loop']['revindex'] = \$length;\n")->write("\$context['loop']['length'] = \$length;\n")->write("\$context['loop']['last'] = 1 === \$length;\n")->outdent()->write("}\n");
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
$this->loop->setAttribute('else', $this->hasNode('else'));
[48] Fix | Delete
$this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
[49] Fix | Delete
$this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
[50] Fix | Delete
$compiler->write("foreach (\$context['_seq'] as ")->subcompile($this->getNode('key_target'))->raw(' => ')->subcompile($this->getNode('value_target'))->raw(") {\n")->indent()->subcompile($this->getNode('body'))->outdent()->write("}\n");
[51] Fix | Delete
if ($this->hasNode('else')) {
[52] Fix | Delete
$compiler->write("if (!\$context['_iterated']) {\n")->indent()->subcompile($this->getNode('else'))->outdent()->write("}\n");
[53] Fix | Delete
}
[54] Fix | Delete
$compiler->write("\$_parent = \$context['_parent'];\n");
[55] Fix | Delete
// remove some "private" loop variables (needed for nested loops)
[56] Fix | Delete
$compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\'' . $this->getNode('key_target')->getAttribute('name') . '\'], $context[\'' . $this->getNode('value_target')->getAttribute('name') . '\'], $context[\'_parent\'], $context[\'loop\']);' . "\n");
[57] Fix | Delete
// keep the values set in the inner context for variables defined in the outer context
[58] Fix | Delete
$compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n");
[59] Fix | Delete
}
[60] Fix | Delete
}
[61] Fix | Delete
\class_alias('WPML\\Core\\Twig\\Node\\ForNode', 'WPML\\Core\\Twig_Node_For');
[62] Fix | Delete
[63] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function