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
File: Compiler.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;
[11] Fix | Delete
[12] Fix | Delete
use WPML\Core\Twig\Node\ModuleNode;
[13] Fix | Delete
/**
[14] Fix | Delete
* Compiles a node to PHP code.
[15] Fix | Delete
*
[16] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[17] Fix | Delete
*/
[18] Fix | Delete
class Compiler implements \WPML\Core\Twig_CompilerInterface
[19] Fix | Delete
{
[20] Fix | Delete
protected $lastLine;
[21] Fix | Delete
protected $source;
[22] Fix | Delete
protected $indentation;
[23] Fix | Delete
protected $env;
[24] Fix | Delete
protected $debugInfo = [];
[25] Fix | Delete
protected $sourceOffset;
[26] Fix | Delete
protected $sourceLine;
[27] Fix | Delete
protected $filename;
[28] Fix | Delete
private $varNameSalt = 0;
[29] Fix | Delete
public function __construct(\WPML\Core\Twig\Environment $env)
[30] Fix | Delete
{
[31] Fix | Delete
$this->env = $env;
[32] Fix | Delete
}
[33] Fix | Delete
/**
[34] Fix | Delete
* @deprecated since 1.25 (to be removed in 2.0)
[35] Fix | Delete
*/
[36] Fix | Delete
public function getFilename()
[37] Fix | Delete
{
[38] Fix | Delete
@\trigger_error(\sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), \E_USER_DEPRECATED);
[39] Fix | Delete
return $this->filename;
[40] Fix | Delete
}
[41] Fix | Delete
/**
[42] Fix | Delete
* Returns the environment instance related to this compiler.
[43] Fix | Delete
*
[44] Fix | Delete
* @return Environment
[45] Fix | Delete
*/
[46] Fix | Delete
public function getEnvironment()
[47] Fix | Delete
{
[48] Fix | Delete
return $this->env;
[49] Fix | Delete
}
[50] Fix | Delete
/**
[51] Fix | Delete
* Gets the current PHP code after compilation.
[52] Fix | Delete
*
[53] Fix | Delete
* @return string The PHP code
[54] Fix | Delete
*/
[55] Fix | Delete
public function getSource()
[56] Fix | Delete
{
[57] Fix | Delete
return $this->source;
[58] Fix | Delete
}
[59] Fix | Delete
/**
[60] Fix | Delete
* Compiles a node.
[61] Fix | Delete
*
[62] Fix | Delete
* @param int $indentation The current indentation
[63] Fix | Delete
*
[64] Fix | Delete
* @return $this
[65] Fix | Delete
*/
[66] Fix | Delete
public function compile(\WPML\Core\Twig_NodeInterface $node, $indentation = 0)
[67] Fix | Delete
{
[68] Fix | Delete
$this->lastLine = null;
[69] Fix | Delete
$this->source = '';
[70] Fix | Delete
$this->debugInfo = [];
[71] Fix | Delete
$this->sourceOffset = 0;
[72] Fix | Delete
// source code starts at 1 (as we then increment it when we encounter new lines)
[73] Fix | Delete
$this->sourceLine = 1;
[74] Fix | Delete
$this->indentation = $indentation;
[75] Fix | Delete
$this->varNameSalt = 0;
[76] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\ModuleNode) {
[77] Fix | Delete
// to be removed in 2.0
[78] Fix | Delete
$this->filename = $node->getTemplateName();
[79] Fix | Delete
}
[80] Fix | Delete
$node->compile($this);
[81] Fix | Delete
return $this;
[82] Fix | Delete
}
[83] Fix | Delete
public function subcompile(\WPML\Core\Twig_NodeInterface $node, $raw = \true)
[84] Fix | Delete
{
[85] Fix | Delete
if (\false === $raw) {
[86] Fix | Delete
$this->source .= \str_repeat(' ', $this->indentation * 4);
[87] Fix | Delete
}
[88] Fix | Delete
$node->compile($this);
[89] Fix | Delete
return $this;
[90] Fix | Delete
}
[91] Fix | Delete
/**
[92] Fix | Delete
* Adds a raw string to the compiled code.
[93] Fix | Delete
*
[94] Fix | Delete
* @param string $string The string
[95] Fix | Delete
*
[96] Fix | Delete
* @return $this
[97] Fix | Delete
*/
[98] Fix | Delete
public function raw($string)
[99] Fix | Delete
{
[100] Fix | Delete
$this->source .= $string;
[101] Fix | Delete
return $this;
[102] Fix | Delete
}
[103] Fix | Delete
/**
[104] Fix | Delete
* Writes a string to the compiled code by adding indentation.
[105] Fix | Delete
*
[106] Fix | Delete
* @return $this
[107] Fix | Delete
*/
[108] Fix | Delete
public function write()
[109] Fix | Delete
{
[110] Fix | Delete
$strings = \func_get_args();
[111] Fix | Delete
foreach ($strings as $string) {
[112] Fix | Delete
$this->source .= \str_repeat(' ', $this->indentation * 4) . $string;
[113] Fix | Delete
}
[114] Fix | Delete
return $this;
[115] Fix | Delete
}
[116] Fix | Delete
/**
[117] Fix | Delete
* Appends an indentation to the current PHP code after compilation.
[118] Fix | Delete
*
[119] Fix | Delete
* @return $this
[120] Fix | Delete
*
[121] Fix | Delete
* @deprecated since 1.27 (to be removed in 2.0).
[122] Fix | Delete
*/
[123] Fix | Delete
public function addIndentation()
[124] Fix | Delete
{
[125] Fix | Delete
@\trigger_error('The ' . __METHOD__ . ' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', \E_USER_DEPRECATED);
[126] Fix | Delete
$this->source .= \str_repeat(' ', $this->indentation * 4);
[127] Fix | Delete
return $this;
[128] Fix | Delete
}
[129] Fix | Delete
/**
[130] Fix | Delete
* Adds a quoted string to the compiled code.
[131] Fix | Delete
*
[132] Fix | Delete
* @param string $value The string
[133] Fix | Delete
*
[134] Fix | Delete
* @return $this
[135] Fix | Delete
*/
[136] Fix | Delete
public function string($value)
[137] Fix | Delete
{
[138] Fix | Delete
$this->source .= \sprintf('"%s"', \addcslashes($value, "\0\t\"\$\\"));
[139] Fix | Delete
return $this;
[140] Fix | Delete
}
[141] Fix | Delete
/**
[142] Fix | Delete
* Returns a PHP representation of a given value.
[143] Fix | Delete
*
[144] Fix | Delete
* @param mixed $value The value to convert
[145] Fix | Delete
*
[146] Fix | Delete
* @return $this
[147] Fix | Delete
*/
[148] Fix | Delete
public function repr($value)
[149] Fix | Delete
{
[150] Fix | Delete
if (\is_int($value) || \is_float($value)) {
[151] Fix | Delete
if (\false !== ($locale = \setlocale(\LC_NUMERIC, '0'))) {
[152] Fix | Delete
\setlocale(\LC_NUMERIC, 'C');
[153] Fix | Delete
}
[154] Fix | Delete
$this->raw(\var_export($value, \true));
[155] Fix | Delete
if (\false !== $locale) {
[156] Fix | Delete
\setlocale(\LC_NUMERIC, $locale);
[157] Fix | Delete
}
[158] Fix | Delete
} elseif (null === $value) {
[159] Fix | Delete
$this->raw('null');
[160] Fix | Delete
} elseif (\is_bool($value)) {
[161] Fix | Delete
$this->raw($value ? 'true' : 'false');
[162] Fix | Delete
} elseif (\is_array($value)) {
[163] Fix | Delete
$this->raw('[');
[164] Fix | Delete
$first = \true;
[165] Fix | Delete
foreach ($value as $key => $v) {
[166] Fix | Delete
if (!$first) {
[167] Fix | Delete
$this->raw(', ');
[168] Fix | Delete
}
[169] Fix | Delete
$first = \false;
[170] Fix | Delete
$this->repr($key);
[171] Fix | Delete
$this->raw(' => ');
[172] Fix | Delete
$this->repr($v);
[173] Fix | Delete
}
[174] Fix | Delete
$this->raw(']');
[175] Fix | Delete
} else {
[176] Fix | Delete
$this->string($value);
[177] Fix | Delete
}
[178] Fix | Delete
return $this;
[179] Fix | Delete
}
[180] Fix | Delete
/**
[181] Fix | Delete
* Adds debugging information.
[182] Fix | Delete
*
[183] Fix | Delete
* @return $this
[184] Fix | Delete
*/
[185] Fix | Delete
public function addDebugInfo(\WPML\Core\Twig_NodeInterface $node)
[186] Fix | Delete
{
[187] Fix | Delete
if ($node->getTemplateLine() != $this->lastLine) {
[188] Fix | Delete
$this->write(\sprintf("// line %d\n", $node->getTemplateLine()));
[189] Fix | Delete
// when mbstring.func_overload is set to 2
[190] Fix | Delete
// mb_substr_count() replaces substr_count()
[191] Fix | Delete
// but they have different signatures!
[192] Fix | Delete
if ((int) \ini_get('mbstring.func_overload') & 2) {
[193] Fix | Delete
@\trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', \E_USER_DEPRECATED);
[194] Fix | Delete
// this is much slower than the "right" version
[195] Fix | Delete
$this->sourceLine += \mb_substr_count(\mb_substr($this->source, $this->sourceOffset), "\n");
[196] Fix | Delete
} else {
[197] Fix | Delete
$this->sourceLine += \substr_count($this->source, "\n", $this->sourceOffset);
[198] Fix | Delete
}
[199] Fix | Delete
$this->sourceOffset = \strlen($this->source);
[200] Fix | Delete
$this->debugInfo[$this->sourceLine] = $node->getTemplateLine();
[201] Fix | Delete
$this->lastLine = $node->getTemplateLine();
[202] Fix | Delete
}
[203] Fix | Delete
return $this;
[204] Fix | Delete
}
[205] Fix | Delete
public function getDebugInfo()
[206] Fix | Delete
{
[207] Fix | Delete
\ksort($this->debugInfo);
[208] Fix | Delete
return $this->debugInfo;
[209] Fix | Delete
}
[210] Fix | Delete
/**
[211] Fix | Delete
* Indents the generated code.
[212] Fix | Delete
*
[213] Fix | Delete
* @param int $step The number of indentation to add
[214] Fix | Delete
*
[215] Fix | Delete
* @return $this
[216] Fix | Delete
*/
[217] Fix | Delete
public function indent($step = 1)
[218] Fix | Delete
{
[219] Fix | Delete
$this->indentation += $step;
[220] Fix | Delete
return $this;
[221] Fix | Delete
}
[222] Fix | Delete
/**
[223] Fix | Delete
* Outdents the generated code.
[224] Fix | Delete
*
[225] Fix | Delete
* @param int $step The number of indentation to remove
[226] Fix | Delete
*
[227] Fix | Delete
* @return $this
[228] Fix | Delete
*
[229] Fix | Delete
* @throws \LogicException When trying to outdent too much so the indentation would become negative
[230] Fix | Delete
*/
[231] Fix | Delete
public function outdent($step = 1)
[232] Fix | Delete
{
[233] Fix | Delete
// can't outdent by more steps than the current indentation level
[234] Fix | Delete
if ($this->indentation < $step) {
[235] Fix | Delete
throw new \LogicException('Unable to call outdent() as the indentation would become negative.');
[236] Fix | Delete
}
[237] Fix | Delete
$this->indentation -= $step;
[238] Fix | Delete
return $this;
[239] Fix | Delete
}
[240] Fix | Delete
public function getVarName()
[241] Fix | Delete
{
[242] Fix | Delete
return \sprintf('__internal_%s', \hash('sha256', __METHOD__ . $this->varNameSalt++));
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
\class_alias('WPML\\Core\\Twig\\Compiler', 'WPML\\Core\\Twig_Compiler');
[246] Fix | Delete
[247] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function