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: Environment.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
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
namespace WPML\Core\Twig;
[10] Fix | Delete
[11] Fix | Delete
use WPML\Core\Twig\Cache\CacheInterface;
[12] Fix | Delete
use WPML\Core\Twig\Cache\FilesystemCache;
[13] Fix | Delete
use WPML\Core\Twig\Cache\NullCache;
[14] Fix | Delete
use WPML\Core\Twig\Error\Error;
[15] Fix | Delete
use WPML\Core\Twig\Error\LoaderError;
[16] Fix | Delete
use WPML\Core\Twig\Error\RuntimeError;
[17] Fix | Delete
use WPML\Core\Twig\Error\SyntaxError;
[18] Fix | Delete
use WPML\Core\Twig\Extension\CoreExtension;
[19] Fix | Delete
use WPML\Core\Twig\Extension\EscaperExtension;
[20] Fix | Delete
use WPML\Core\Twig\Extension\ExtensionInterface;
[21] Fix | Delete
use WPML\Core\Twig\Extension\GlobalsInterface;
[22] Fix | Delete
use WPML\Core\Twig\Extension\InitRuntimeInterface;
[23] Fix | Delete
use WPML\Core\Twig\Extension\OptimizerExtension;
[24] Fix | Delete
use WPML\Core\Twig\Extension\StagingExtension;
[25] Fix | Delete
use WPML\Core\Twig\Loader\ArrayLoader;
[26] Fix | Delete
use WPML\Core\Twig\Loader\ChainLoader;
[27] Fix | Delete
use WPML\Core\Twig\Loader\LoaderInterface;
[28] Fix | Delete
use WPML\Core\Twig\Loader\SourceContextLoaderInterface;
[29] Fix | Delete
use WPML\Core\Twig\Node\ModuleNode;
[30] Fix | Delete
use WPML\Core\Twig\NodeVisitor\NodeVisitorInterface;
[31] Fix | Delete
use WPML\Core\Twig\RuntimeLoader\RuntimeLoaderInterface;
[32] Fix | Delete
use WPML\Core\Twig\TokenParser\TokenParserInterface;
[33] Fix | Delete
/**
[34] Fix | Delete
* Stores the Twig configuration.
[35] Fix | Delete
*
[36] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[37] Fix | Delete
*/
[38] Fix | Delete
class Environment
[39] Fix | Delete
{
[40] Fix | Delete
const VERSION = '1.42.4';
[41] Fix | Delete
const VERSION_ID = 14204;
[42] Fix | Delete
const MAJOR_VERSION = 1;
[43] Fix | Delete
const MINOR_VERSION = 42;
[44] Fix | Delete
const RELEASE_VERSION = 4;
[45] Fix | Delete
const EXTRA_VERSION = '';
[46] Fix | Delete
protected $charset;
[47] Fix | Delete
protected $loader;
[48] Fix | Delete
protected $debug;
[49] Fix | Delete
protected $autoReload;
[50] Fix | Delete
protected $cache;
[51] Fix | Delete
protected $lexer;
[52] Fix | Delete
protected $parser;
[53] Fix | Delete
protected $compiler;
[54] Fix | Delete
protected $baseTemplateClass;
[55] Fix | Delete
protected $extensions;
[56] Fix | Delete
protected $parsers;
[57] Fix | Delete
protected $visitors;
[58] Fix | Delete
protected $filters;
[59] Fix | Delete
protected $tests;
[60] Fix | Delete
protected $functions;
[61] Fix | Delete
protected $globals;
[62] Fix | Delete
protected $runtimeInitialized = \false;
[63] Fix | Delete
protected $extensionInitialized = \false;
[64] Fix | Delete
protected $loadedTemplates;
[65] Fix | Delete
protected $strictVariables;
[66] Fix | Delete
protected $unaryOperators;
[67] Fix | Delete
protected $binaryOperators;
[68] Fix | Delete
protected $templateClassPrefix = '\\WPML\\Core\\__TwigTemplate_';
[69] Fix | Delete
protected $functionCallbacks = [];
[70] Fix | Delete
protected $filterCallbacks = [];
[71] Fix | Delete
protected $staging;
[72] Fix | Delete
private $originalCache;
[73] Fix | Delete
private $bcWriteCacheFile = \false;
[74] Fix | Delete
private $bcGetCacheFilename = \false;
[75] Fix | Delete
private $lastModifiedExtension = 0;
[76] Fix | Delete
private $extensionsByClass = [];
[77] Fix | Delete
private $runtimeLoaders = [];
[78] Fix | Delete
private $runtimes = [];
[79] Fix | Delete
private $optionsHash;
[80] Fix | Delete
/**
[81] Fix | Delete
* Constructor.
[82] Fix | Delete
*
[83] Fix | Delete
* Available options:
[84] Fix | Delete
*
[85] Fix | Delete
* * debug: When set to true, it automatically set "auto_reload" to true as
[86] Fix | Delete
* well (default to false).
[87] Fix | Delete
*
[88] Fix | Delete
* * charset: The charset used by the templates (default to UTF-8).
[89] Fix | Delete
*
[90] Fix | Delete
* * base_template_class: The base template class to use for generated
[91] Fix | Delete
* templates (default to \Twig\Template).
[92] Fix | Delete
*
[93] Fix | Delete
* * cache: An absolute path where to store the compiled templates,
[94] Fix | Delete
* a \Twig\Cache\CacheInterface implementation,
[95] Fix | Delete
* or false to disable compilation cache (default).
[96] Fix | Delete
*
[97] Fix | Delete
* * auto_reload: Whether to reload the template if the original source changed.
[98] Fix | Delete
* If you don't provide the auto_reload option, it will be
[99] Fix | Delete
* determined automatically based on the debug value.
[100] Fix | Delete
*
[101] Fix | Delete
* * strict_variables: Whether to ignore invalid variables in templates
[102] Fix | Delete
* (default to false).
[103] Fix | Delete
*
[104] Fix | Delete
* * autoescape: Whether to enable auto-escaping (default to html):
[105] Fix | Delete
* * false: disable auto-escaping
[106] Fix | Delete
* * true: equivalent to html
[107] Fix | Delete
* * html, js: set the autoescaping to one of the supported strategies
[108] Fix | Delete
* * name: set the autoescaping strategy based on the template name extension
[109] Fix | Delete
* * PHP callback: a PHP callback that returns an escaping strategy based on the template "name"
[110] Fix | Delete
*
[111] Fix | Delete
* * optimizations: A flag that indicates which optimizations to apply
[112] Fix | Delete
* (default to -1 which means that all optimizations are enabled;
[113] Fix | Delete
* set it to 0 to disable).
[114] Fix | Delete
*/
[115] Fix | Delete
public function __construct(\WPML\Core\Twig\Loader\LoaderInterface $loader = null, $options = [])
[116] Fix | Delete
{
[117] Fix | Delete
if (null !== $loader) {
[118] Fix | Delete
$this->setLoader($loader);
[119] Fix | Delete
} else {
[120] Fix | Delete
@\trigger_error('Not passing a "Twig\\Lodaer\\LoaderInterface" as the first constructor argument of "Twig\\Environment" is deprecated since version 1.21.', \E_USER_DEPRECATED);
[121] Fix | Delete
}
[122] Fix | Delete
$options = \array_merge(['debug' => \false, 'charset' => 'UTF-8', 'base_template_class' => '\\WPML\\Core\\Twig\\Template', 'strict_variables' => \false, 'autoescape' => 'html', 'cache' => \false, 'auto_reload' => null, 'optimizations' => -1], $options);
[123] Fix | Delete
$this->debug = (bool) $options['debug'];
[124] Fix | Delete
$this->charset = \strtoupper($options['charset']);
[125] Fix | Delete
$this->baseTemplateClass = $options['base_template_class'];
[126] Fix | Delete
$this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload'];
[127] Fix | Delete
$this->strictVariables = (bool) $options['strict_variables'];
[128] Fix | Delete
$this->setCache($options['cache']);
[129] Fix | Delete
$this->addExtension(new \WPML\Core\Twig\Extension\CoreExtension());
[130] Fix | Delete
$this->addExtension(new \WPML\Core\Twig\Extension\EscaperExtension($options['autoescape']));
[131] Fix | Delete
$this->addExtension(new \WPML\Core\Twig\Extension\OptimizerExtension($options['optimizations']));
[132] Fix | Delete
$this->staging = new \WPML\Core\Twig\Extension\StagingExtension();
[133] Fix | Delete
// For BC
[134] Fix | Delete
if (\is_string($this->originalCache)) {
[135] Fix | Delete
$r = new \ReflectionMethod($this, 'writeCacheFile');
[136] Fix | Delete
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
[137] Fix | Delete
@\trigger_error('The Twig\\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', \E_USER_DEPRECATED);
[138] Fix | Delete
$this->bcWriteCacheFile = \true;
[139] Fix | Delete
}
[140] Fix | Delete
$r = new \ReflectionMethod($this, 'getCacheFilename');
[141] Fix | Delete
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
[142] Fix | Delete
@\trigger_error('The Twig\\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', \E_USER_DEPRECATED);
[143] Fix | Delete
$this->bcGetCacheFilename = \true;
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
/**
[148] Fix | Delete
* Gets the base template class for compiled templates.
[149] Fix | Delete
*
[150] Fix | Delete
* @return string The base template class name
[151] Fix | Delete
*/
[152] Fix | Delete
public function getBaseTemplateClass()
[153] Fix | Delete
{
[154] Fix | Delete
return $this->baseTemplateClass;
[155] Fix | Delete
}
[156] Fix | Delete
/**
[157] Fix | Delete
* Sets the base template class for compiled templates.
[158] Fix | Delete
*
[159] Fix | Delete
* @param string $class The base template class name
[160] Fix | Delete
*/
[161] Fix | Delete
public function setBaseTemplateClass($class)
[162] Fix | Delete
{
[163] Fix | Delete
$this->baseTemplateClass = $class;
[164] Fix | Delete
$this->updateOptionsHash();
[165] Fix | Delete
}
[166] Fix | Delete
/**
[167] Fix | Delete
* Enables debugging mode.
[168] Fix | Delete
*/
[169] Fix | Delete
public function enableDebug()
[170] Fix | Delete
{
[171] Fix | Delete
$this->debug = \true;
[172] Fix | Delete
$this->updateOptionsHash();
[173] Fix | Delete
}
[174] Fix | Delete
/**
[175] Fix | Delete
* Disables debugging mode.
[176] Fix | Delete
*/
[177] Fix | Delete
public function disableDebug()
[178] Fix | Delete
{
[179] Fix | Delete
$this->debug = \false;
[180] Fix | Delete
$this->updateOptionsHash();
[181] Fix | Delete
}
[182] Fix | Delete
/**
[183] Fix | Delete
* Checks if debug mode is enabled.
[184] Fix | Delete
*
[185] Fix | Delete
* @return bool true if debug mode is enabled, false otherwise
[186] Fix | Delete
*/
[187] Fix | Delete
public function isDebug()
[188] Fix | Delete
{
[189] Fix | Delete
return $this->debug;
[190] Fix | Delete
}
[191] Fix | Delete
/**
[192] Fix | Delete
* Enables the auto_reload option.
[193] Fix | Delete
*/
[194] Fix | Delete
public function enableAutoReload()
[195] Fix | Delete
{
[196] Fix | Delete
$this->autoReload = \true;
[197] Fix | Delete
}
[198] Fix | Delete
/**
[199] Fix | Delete
* Disables the auto_reload option.
[200] Fix | Delete
*/
[201] Fix | Delete
public function disableAutoReload()
[202] Fix | Delete
{
[203] Fix | Delete
$this->autoReload = \false;
[204] Fix | Delete
}
[205] Fix | Delete
/**
[206] Fix | Delete
* Checks if the auto_reload option is enabled.
[207] Fix | Delete
*
[208] Fix | Delete
* @return bool true if auto_reload is enabled, false otherwise
[209] Fix | Delete
*/
[210] Fix | Delete
public function isAutoReload()
[211] Fix | Delete
{
[212] Fix | Delete
return $this->autoReload;
[213] Fix | Delete
}
[214] Fix | Delete
/**
[215] Fix | Delete
* Enables the strict_variables option.
[216] Fix | Delete
*/
[217] Fix | Delete
public function enableStrictVariables()
[218] Fix | Delete
{
[219] Fix | Delete
$this->strictVariables = \true;
[220] Fix | Delete
$this->updateOptionsHash();
[221] Fix | Delete
}
[222] Fix | Delete
/**
[223] Fix | Delete
* Disables the strict_variables option.
[224] Fix | Delete
*/
[225] Fix | Delete
public function disableStrictVariables()
[226] Fix | Delete
{
[227] Fix | Delete
$this->strictVariables = \false;
[228] Fix | Delete
$this->updateOptionsHash();
[229] Fix | Delete
}
[230] Fix | Delete
/**
[231] Fix | Delete
* Checks if the strict_variables option is enabled.
[232] Fix | Delete
*
[233] Fix | Delete
* @return bool true if strict_variables is enabled, false otherwise
[234] Fix | Delete
*/
[235] Fix | Delete
public function isStrictVariables()
[236] Fix | Delete
{
[237] Fix | Delete
return $this->strictVariables;
[238] Fix | Delete
}
[239] Fix | Delete
/**
[240] Fix | Delete
* Gets the current cache implementation.
[241] Fix | Delete
*
[242] Fix | Delete
* @param bool $original Whether to return the original cache option or the real cache instance
[243] Fix | Delete
*
[244] Fix | Delete
* @return CacheInterface|string|false A Twig\Cache\CacheInterface implementation,
[245] Fix | Delete
* an absolute path to the compiled templates,
[246] Fix | Delete
* or false to disable cache
[247] Fix | Delete
*/
[248] Fix | Delete
public function getCache($original = \true)
[249] Fix | Delete
{
[250] Fix | Delete
return $original ? $this->originalCache : $this->cache;
[251] Fix | Delete
}
[252] Fix | Delete
/**
[253] Fix | Delete
* Sets the current cache implementation.
[254] Fix | Delete
*
[255] Fix | Delete
* @param CacheInterface|string|false $cache A Twig\Cache\CacheInterface implementation,
[256] Fix | Delete
* an absolute path to the compiled templates,
[257] Fix | Delete
* or false to disable cache
[258] Fix | Delete
*/
[259] Fix | Delete
public function setCache($cache)
[260] Fix | Delete
{
[261] Fix | Delete
if (\is_string($cache)) {
[262] Fix | Delete
$this->originalCache = $cache;
[263] Fix | Delete
$this->cache = new \WPML\Core\Twig\Cache\FilesystemCache($cache);
[264] Fix | Delete
} elseif (\false === $cache) {
[265] Fix | Delete
$this->originalCache = $cache;
[266] Fix | Delete
$this->cache = new \WPML\Core\Twig\Cache\NullCache();
[267] Fix | Delete
} elseif (null === $cache) {
[268] Fix | Delete
@\trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.', \E_USER_DEPRECATED);
[269] Fix | Delete
$this->originalCache = \false;
[270] Fix | Delete
$this->cache = new \WPML\Core\Twig\Cache\NullCache();
[271] Fix | Delete
} elseif ($cache instanceof \WPML\Core\Twig\Cache\CacheInterface) {
[272] Fix | Delete
$this->originalCache = $this->cache = $cache;
[273] Fix | Delete
} else {
[274] Fix | Delete
throw new \LogicException(\sprintf('Cache can only be a string, false, or a \\Twig\\Cache\\CacheInterface implementation.'));
[275] Fix | Delete
}
[276] Fix | Delete
}
[277] Fix | Delete
/**
[278] Fix | Delete
* Gets the cache filename for a given template.
[279] Fix | Delete
*
[280] Fix | Delete
* @param string $name The template name
[281] Fix | Delete
*
[282] Fix | Delete
* @return string|false The cache file name or false when caching is disabled
[283] Fix | Delete
*
[284] Fix | Delete
* @deprecated since 1.22 (to be removed in 2.0)
[285] Fix | Delete
*/
[286] Fix | Delete
public function getCacheFilename($name)
[287] Fix | Delete
{
[288] Fix | Delete
@\trigger_error(\sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED);
[289] Fix | Delete
$key = $this->cache->generateKey($name, $this->getTemplateClass($name));
[290] Fix | Delete
return !$key ? \false : $key;
[291] Fix | Delete
}
[292] Fix | Delete
/**
[293] Fix | Delete
* Gets the template class associated with the given string.
[294] Fix | Delete
*
[295] Fix | Delete
* The generated template class is based on the following parameters:
[296] Fix | Delete
*
[297] Fix | Delete
* * The cache key for the given template;
[298] Fix | Delete
* * The currently enabled extensions;
[299] Fix | Delete
* * Whether the Twig C extension is available or not;
[300] Fix | Delete
* * PHP version;
[301] Fix | Delete
* * Twig version;
[302] Fix | Delete
* * Options with what environment was created.
[303] Fix | Delete
*
[304] Fix | Delete
* @param string $name The name for which to calculate the template class name
[305] Fix | Delete
* @param int|null $index The index if it is an embedded template
[306] Fix | Delete
*
[307] Fix | Delete
* @return string The template class name
[308] Fix | Delete
*/
[309] Fix | Delete
public function getTemplateClass($name, $index = null)
[310] Fix | Delete
{
[311] Fix | Delete
$key = $this->getLoader()->getCacheKey($name) . $this->optionsHash;
[312] Fix | Delete
return $this->templateClassPrefix . \hash('sha256', $key) . (null === $index ? '' : '___' . $index);
[313] Fix | Delete
}
[314] Fix | Delete
/**
[315] Fix | Delete
* Gets the template class prefix.
[316] Fix | Delete
*
[317] Fix | Delete
* @return string The template class prefix
[318] Fix | Delete
*
[319] Fix | Delete
* @deprecated since 1.22 (to be removed in 2.0)
[320] Fix | Delete
*/
[321] Fix | Delete
public function getTemplateClassPrefix()
[322] Fix | Delete
{
[323] Fix | Delete
@\trigger_error(\sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED);
[324] Fix | Delete
return $this->templateClassPrefix;
[325] Fix | Delete
}
[326] Fix | Delete
/**
[327] Fix | Delete
* Renders a template.
[328] Fix | Delete
*
[329] Fix | Delete
* @param string|TemplateWrapper $name The template name
[330] Fix | Delete
* @param array $context An array of parameters to pass to the template
[331] Fix | Delete
*
[332] Fix | Delete
* @return string The rendered template
[333] Fix | Delete
*
[334] Fix | Delete
* @throws LoaderError When the template cannot be found
[335] Fix | Delete
* @throws SyntaxError When an error occurred during compilation
[336] Fix | Delete
* @throws RuntimeError When an error occurred during rendering
[337] Fix | Delete
*/
[338] Fix | Delete
public function render($name, array $context = [])
[339] Fix | Delete
{
[340] Fix | Delete
return $this->load($name)->render($context);
[341] Fix | Delete
}
[342] Fix | Delete
/**
[343] Fix | Delete
* Displays a template.
[344] Fix | Delete
*
[345] Fix | Delete
* @param string|TemplateWrapper $name The template name
[346] Fix | Delete
* @param array $context An array of parameters to pass to the template
[347] Fix | Delete
*
[348] Fix | Delete
* @throws LoaderError When the template cannot be found
[349] Fix | Delete
* @throws SyntaxError When an error occurred during compilation
[350] Fix | Delete
* @throws RuntimeError When an error occurred during rendering
[351] Fix | Delete
*/
[352] Fix | Delete
public function display($name, array $context = [])
[353] Fix | Delete
{
[354] Fix | Delete
$this->load($name)->display($context);
[355] Fix | Delete
}
[356] Fix | Delete
/**
[357] Fix | Delete
* Loads a template.
[358] Fix | Delete
*
[359] Fix | Delete
* @param string|TemplateWrapper|\Twig\Template $name The template name
[360] Fix | Delete
*
[361] Fix | Delete
* @throws LoaderError When the template cannot be found
[362] Fix | Delete
* @throws RuntimeError When a previously generated cache is corrupted
[363] Fix | Delete
* @throws SyntaxError When an error occurred during compilation
[364] Fix | Delete
*
[365] Fix | Delete
* @return TemplateWrapper
[366] Fix | Delete
*/
[367] Fix | Delete
public function load($name)
[368] Fix | Delete
{
[369] Fix | Delete
if ($name instanceof \WPML\Core\Twig\TemplateWrapper) {
[370] Fix | Delete
return $name;
[371] Fix | Delete
}
[372] Fix | Delete
if ($name instanceof \WPML\Core\Twig\Template) {
[373] Fix | Delete
return new \WPML\Core\Twig\TemplateWrapper($this, $name);
[374] Fix | Delete
}
[375] Fix | Delete
return new \WPML\Core\Twig\TemplateWrapper($this, $this->loadTemplate($name));
[376] Fix | Delete
}
[377] Fix | Delete
/**
[378] Fix | Delete
* Loads a template internal representation.
[379] Fix | Delete
*
[380] Fix | Delete
* This method is for internal use only and should never be called
[381] Fix | Delete
* directly.
[382] Fix | Delete
*
[383] Fix | Delete
* @param string $name The template name
[384] Fix | Delete
* @param int $index The index if it is an embedded template
[385] Fix | Delete
*
[386] Fix | Delete
* @return \Twig_TemplateInterface A template instance representing the given template name
[387] Fix | Delete
*
[388] Fix | Delete
* @throws LoaderError When the template cannot be found
[389] Fix | Delete
* @throws RuntimeError When a previously generated cache is corrupted
[390] Fix | Delete
* @throws SyntaxError When an error occurred during compilation
[391] Fix | Delete
*
[392] Fix | Delete
* @internal
[393] Fix | Delete
*/
[394] Fix | Delete
public function loadTemplate($name, $index = null)
[395] Fix | Delete
{
[396] Fix | Delete
return $this->loadClass($this->getTemplateClass($name), $name, $index);
[397] Fix | Delete
}
[398] Fix | Delete
/**
[399] Fix | Delete
* @internal
[400] Fix | Delete
*/
[401] Fix | Delete
public function loadClass($cls, $name, $index = null)
[402] Fix | Delete
{
[403] Fix | Delete
$mainCls = $cls;
[404] Fix | Delete
if (null !== $index) {
[405] Fix | Delete
$cls .= '___' . $index;
[406] Fix | Delete
}
[407] Fix | Delete
if (isset($this->loadedTemplates[$cls])) {
[408] Fix | Delete
return $this->loadedTemplates[$cls];
[409] Fix | Delete
}
[410] Fix | Delete
if (!\class_exists($cls, \false)) {
[411] Fix | Delete
if ($this->bcGetCacheFilename) {
[412] Fix | Delete
$key = $this->getCacheFilename($name);
[413] Fix | Delete
} else {
[414] Fix | Delete
$key = $this->cache->generateKey($name, $mainCls);
[415] Fix | Delete
}
[416] Fix | Delete
if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
[417] Fix | Delete
$this->cache->load($key);
[418] Fix | Delete
}
[419] Fix | Delete
$source = null;
[420] Fix | Delete
if (!\class_exists($cls, \false)) {
[421] Fix | Delete
$loader = $this->getLoader();
[422] Fix | Delete
if (!$loader instanceof \WPML\Core\Twig\Loader\SourceContextLoaderInterface) {
[423] Fix | Delete
$source = new \WPML\Core\Twig\Source($loader->getSource($name), $name);
[424] Fix | Delete
} else {
[425] Fix | Delete
$source = $loader->getSourceContext($name);
[426] Fix | Delete
}
[427] Fix | Delete
$content = $this->compileSource($source);
[428] Fix | Delete
if ($this->bcWriteCacheFile) {
[429] Fix | Delete
$this->writeCacheFile($key, $content);
[430] Fix | Delete
} else {
[431] Fix | Delete
$this->cache->write($key, $content);
[432] Fix | Delete
$this->cache->load($key);
[433] Fix | Delete
}
[434] Fix | Delete
if (!\class_exists($mainCls, \false)) {
[435] Fix | Delete
/* Last line of defense if either $this->bcWriteCacheFile was used,
[436] Fix | Delete
* $this->cache is implemented as a no-op or we have a race condition
[437] Fix | Delete
* where the cache was cleared between the above calls to write to and load from
[438] Fix | Delete
* the cache.
[439] Fix | Delete
*/
[440] Fix | Delete
eval('?>' . $content);
[441] Fix | Delete
}
[442] Fix | Delete
}
[443] Fix | Delete
if (!\class_exists($cls, \false)) {
[444] Fix | Delete
throw new \WPML\Core\Twig\Error\RuntimeError(\sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source);
[445] Fix | Delete
}
[446] Fix | Delete
}
[447] Fix | Delete
if (!$this->runtimeInitialized) {
[448] Fix | Delete
$this->initRuntime();
[449] Fix | Delete
}
[450] Fix | Delete
return $this->loadedTemplates[$cls] = new $cls($this);
[451] Fix | Delete
}
[452] Fix | Delete
/**
[453] Fix | Delete
* Creates a template from source.
[454] Fix | Delete
*
[455] Fix | Delete
* This method should not be used as a generic way to load templates.
[456] Fix | Delete
*
[457] Fix | Delete
* @param string $template The template source
[458] Fix | Delete
* @param string $name An optional name of the template to be used in error messages
[459] Fix | Delete
*
[460] Fix | Delete
* @return TemplateWrapper A template instance representing the given template name
[461] Fix | Delete
*
[462] Fix | Delete
* @throws LoaderError When the template cannot be found
[463] Fix | Delete
* @throws SyntaxError When an error occurred during compilation
[464] Fix | Delete
*/
[465] Fix | Delete
public function createTemplate($template, $name = null)
[466] Fix | Delete
{
[467] Fix | Delete
$hash = \hash('sha256', $template, \false);
[468] Fix | Delete
if (null !== $name) {
[469] Fix | Delete
$name = \sprintf('%s (string template %s)', $name, $hash);
[470] Fix | Delete
} else {
[471] Fix | Delete
$name = \sprintf('__string_template__%s', $hash);
[472] Fix | Delete
}
[473] Fix | Delete
$loader = new \WPML\Core\Twig\Loader\ChainLoader([new \WPML\Core\Twig\Loader\ArrayLoader([$name => $template]), $current = $this->getLoader()]);
[474] Fix | Delete
$this->setLoader($loader);
[475] Fix | Delete
try {
[476] Fix | Delete
$template = new \WPML\Core\Twig\TemplateWrapper($this, $this->loadTemplate($name));
[477] Fix | Delete
} catch (\Exception $e) {
[478] Fix | Delete
$this->setLoader($current);
[479] Fix | Delete
throw $e;
[480] Fix | Delete
} catch (\Throwable $e) {
[481] Fix | Delete
$this->setLoader($current);
[482] Fix | Delete
throw $e;
[483] Fix | Delete
}
[484] Fix | Delete
$this->setLoader($current);
[485] Fix | Delete
return $template;
[486] Fix | Delete
}
[487] Fix | Delete
/**
[488] Fix | Delete
* Returns true if the template is still fresh.
[489] Fix | Delete
*
[490] Fix | Delete
* Besides checking the loader for freshness information,
[491] Fix | Delete
* this method also checks if the enabled extensions have
[492] Fix | Delete
* not changed.
[493] Fix | Delete
*
[494] Fix | Delete
* @param string $name The template name
[495] Fix | Delete
* @param int $time The last modification time of the cached template
[496] Fix | Delete
*
[497] Fix | Delete
* @return bool true if the template is fresh, false otherwise
[498] Fix | Delete
*/
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function