106 @trigger_error(
'Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated since version 1.21.', E_USER_DEPRECATED);
111 'charset' =>
'UTF-8',
112 'base_template_class' =>
'Twig_Template',
113 'strict_variables' =>
false,
114 'autoescape' =>
'html',
116 'auto_reload' =>
null,
117 'optimizations' => -1,
120 $this->debug = (bool)
$options[
'debug'];
121 $this->charset = strtoupper(
$options[
'charset']);
122 $this->baseTemplateClass =
$options[
'base_template_class'];
123 $this->autoReload =
null ===
$options[
'auto_reload'] ? $this->debug : (bool)
$options[
'auto_reload'];
124 $this->strictVariables = (bool)
$options[
'strict_variables'];
133 if (is_string($this->originalCache)) {
134 $r =
new ReflectionMethod($this,
'writeCacheFile');
135 if (__CLASS__ !==
$r->getDeclaringClass()->getName()) {
136 @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 $this->bcWriteCacheFile =
true;
141 $r =
new ReflectionMethod($this,
'getCacheFilename');
142 if (__CLASS__ !==
$r->getDeclaringClass()->getName()) {
143 @trigger_error(
'The Twig_Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
145 $this->bcGetCacheFilename =
true;
167 $this->baseTemplateClass = $class;
185 $this->debug =
false;
204 $this->autoReload =
true;
212 $this->autoReload =
false;
230 $this->strictVariables =
true;
239 $this->strictVariables =
false;
277 $this->originalCache =
$cache;
279 } elseif (
false ===
$cache) {
280 $this->originalCache =
$cache;
282 } elseif (
null ===
$cache) {
283 @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);
284 $this->originalCache =
false;
287 $this->originalCache = $this->cache =
$cache;
289 throw new LogicException(
sprintf(
'Cache can only be a string, false, or a Twig_CacheInterface implementation.'));
304 @trigger_error(
sprintf(
'The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
332 return $this->templateClassPrefix.hash(
'sha256',
$key).(null ===
$index ?
'' :
'_'.$index);
344 @trigger_error(
sprintf(
'The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
429 if (isset($this->loadedTemplates[$cls])) {
430 return $this->loadedTemplates[$cls];
433 if (!class_exists($cls,
false)) {
434 if ($this->bcGetCacheFilename) {
437 $key = $this->cache->generateKey(
$name, $mainCls);
441 $this->cache->load(
$key);
444 if (!class_exists($cls,
false)) {
454 if ($this->bcWriteCacheFile) {
457 $this->cache->write(
$key, $content);
458 $this->cache->load(
$key);
461 if (!class_exists($mainCls,
false)) {
471 if (!class_exists($cls,
false)) {
476 if (!$this->runtimeInitialized) {
480 if (isset($this->loading[$cls])) {
484 $this->loading[$cls] =
$name;
487 $this->loadedTemplates[$cls] =
new $cls($this);
488 unset($this->loading[$cls]);
489 }
catch (\Exception $e) {
490 unset($this->loading[$cls]);
495 return $this->loadedTemplates[$cls];
522 }
catch (Exception $e) {
526 }
catch (Throwable $e) {
550 if (0 === $this->lastModifiedExtension) {
551 foreach ($this->extensions as $extension) {
552 $r =
new ReflectionObject($extension);
553 if (file_exists(
$r->getFileName()) && ($extensionTime = filemtime(
$r->getFileName())) > $this->lastModifiedExtension) {
554 $this->lastModifiedExtension = $extensionTime;
596 if (1 === count(
$names)) {
610 @trigger_error(
sprintf(
'The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
612 $this->loadedTemplates = array();
622 @trigger_error(
sprintf(
'The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
624 if (is_string($this->originalCache)) {
625 foreach (
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->originalCache), RecursiveIteratorIterator::LEAVES_ONLY) as
$file) {
626 if (
$file->isFile()) {
627 @unlink(
$file->getPathname());
642 @trigger_error(
sprintf(
'The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
644 if (
null === $this->lexer) {
669 @trigger_error(
sprintf(
'Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
673 if (
null === $this->lexer) {
677 return $this->lexer->tokenize(
$source);
689 @trigger_error(
sprintf(
'The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
691 if (
null === $this->parser) {
712 if (
null === $this->parser) {
716 return $this->parser->parse(
$stream);
728 @trigger_error(
sprintf(
'The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
730 if (
null === $this->compiler) {
749 if (
null === $this->compiler) {
753 return $this->compiler->compile($node)->getSource();
769 @trigger_error(
sprintf(
'Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
778 }
catch (Exception $e) {
786 @trigger_error(
sprintf(
'Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', get_class(
$loader)), E_USER_DEPRECATED);
799 if (
null === $this->loader) {
800 throw new LogicException(
'You must set a loader first.');
813 $this->charset = strtoupper(
$charset);
833 $this->runtimeInitialized =
true;
837 $m =
new ReflectionMethod($extension,
'initRuntime');
839 if (
'Twig_Extension' !==
$m->getDeclaringClass()->getName()) {
840 @trigger_error(
sprintf(
'Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig_Extension_InitRuntimeInterface if needed (not recommended).',
$name), E_USER_DEPRECATED);
844 $extension->initRuntime($this);
857 $class = ltrim($class,
'\\');
858 if (!isset($this->extensionsByClass[$class]) && class_exists($class,
false)) {
860 $class =
new ReflectionClass($class);
861 $class = $class->name;
864 if (isset($this->extensions[$class])) {
865 if ($class !== get_class($this->extensions[$class])) {
866 @trigger_error(
sprintf(
'Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
872 return isset($this->extensionsByClass[$class]);
880 $this->runtimeLoaders[] =
$loader;
892 $class = ltrim($class,
'\\');
893 if (!isset($this->extensionsByClass[$class]) && class_exists($class,
false)) {
895 $class =
new ReflectionClass($class);
896 $class = $class->name;
899 if (isset($this->extensions[$class])) {
900 if ($class !== get_class($this->extensions[$class])) {
901 @trigger_error(
sprintf(
'Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
904 return $this->extensions[$class];
907 if (!isset($this->extensionsByClass[$class])) {
911 return $this->extensionsByClass[$class];
925 if (isset($this->runtimes[$class])) {
926 return $this->runtimes[$class];
929 foreach ($this->runtimeLoaders as
$loader) {
930 if (
null !== $runtime =
$loader->load($class)) {
931 return $this->runtimes[$class] = $runtime;
940 if ($this->extensionInitialized) {
941 throw new LogicException(
sprintf(
'Unable to register extension "%s" as extensions have already been initialized.', $extension->
getName()));
944 $class = get_class($extension);
945 if ($class !== $extension->
getName()) {
946 if (isset($this->extensions[$extension->
getName()])) {
947 unset($this->extensions[$extension->
getName()], $this->extensionsByClass[$class]);
948 @trigger_error(
sprintf(
'The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->
getName()), E_USER_DEPRECATED);
952 $this->lastModifiedExtension = 0;
953 $this->extensionsByClass[$class] = $extension;
954 $this->extensions[$extension->
getName()] = $extension;
969 @trigger_error(
sprintf(
'The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
971 if ($this->extensionInitialized) {
972 throw new LogicException(
sprintf(
'Unable to remove extension "%s" as extensions have already been initialized.',
$name));
975 $class = ltrim(
$name,
'\\');
976 if (!isset($this->extensionsByClass[$class]) && class_exists($class,
false)) {
978 $class =
new ReflectionClass($class);
979 $class = $class->name;
982 if (isset($this->extensions[$class])) {
983 if ($class !== get_class($this->extensions[$class])) {
984 @trigger_error(
sprintf(
'Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
987 unset($this->extensions[$class]);
990 unset($this->extensions[$class]);
1018 if ($this->extensionInitialized) {
1019 throw new LogicException(
'Unable to add a token parser as extensions have already been initialized.');
1022 $this->staging->addTokenParser(
$parser);
1034 if (!$this->extensionInitialized) {
1064 if ($this->extensionInitialized) {
1065 throw new LogicException(
'Unable to add a node visitor as extensions have already been initialized.');
1068 $this->staging->addNodeVisitor($visitor);
1080 if (!$this->extensionInitialized) {
1096 throw new LogicException(
'A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter.');
1101 $name = $filter->getName();
1103 @trigger_error(
sprintf(
'Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__,
$name), E_USER_DEPRECATED);
1106 if ($this->extensionInitialized) {
1107 throw new LogicException(
sprintf(
'Unable to add filter "%s" as extensions have already been initialized.',
$name));
1110 $this->staging->addFilter(
$name, $filter);
1127 if (!$this->extensionInitialized) {
1131 if (isset($this->filters[
$name])) {
1132 return $this->filters[
$name];
1135 foreach ($this->filters as $pattern => $filter) {
1136 $pattern = str_replace(
'\\*',
'(.*?)', preg_quote($pattern,
'#'), $count);
1139 if (preg_match(
'#^'.$pattern.
'$#',
$name, $matches)) {
1140 array_shift($matches);
1141 $filter->setArguments($matches);
1148 foreach ($this->filterCallbacks as $callback) {
1149 if (
false !== $filter = call_user_func($callback,
$name)) {
1159 $this->filterCallbacks[] = $callable;
1175 if (!$this->extensionInitialized) {
1191 throw new LogicException(
'A test must be an instance of Twig_TestInterface or Twig_SimpleTest.');
1198 @trigger_error(
sprintf(
'Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__,
$name), E_USER_DEPRECATED);
1201 if ($this->extensionInitialized) {
1202 throw new LogicException(
sprintf(
'Unable to add test "%s" as extensions have already been initialized.',
$name));
1217 if (!$this->extensionInitialized) {
1235 if (!$this->extensionInitialized) {
1239 if (isset($this->tests[
$name])) {
1240 return $this->tests[
$name];
1255 throw new LogicException(
'A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction.');
1262 @trigger_error(
sprintf(
'Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__,
$name), E_USER_DEPRECATED);
1265 if ($this->extensionInitialized) {
1266 throw new LogicException(
sprintf(
'Unable to add function "%s" as extensions have already been initialized.',
$name));
1286 if (!$this->extensionInitialized) {
1290 if (isset($this->functions[
$name])) {
1291 return $this->functions[
$name];
1294 foreach ($this->functions as $pattern =>
$function) {
1295 $pattern = str_replace(
'\\*',
'(.*?)', preg_quote($pattern,
'#'), $count);
1298 if (preg_match(
'#^'.$pattern.
'$#',
$name, $matches)) {
1299 array_shift($matches);
1307 foreach ($this->functionCallbacks as $callback) {
1318 $this->functionCallbacks[] = $callable;
1334 if (!$this->extensionInitialized) {
1352 if ($this->extensionInitialized || $this->runtimeInitialized) {
1353 if (
null === $this->globals) {
1357 if (!array_key_exists(
$name, $this->globals)) {
1359 @trigger_error(
sprintf(
'Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.',
$name), E_USER_DEPRECATED);
1364 if ($this->extensionInitialized || $this->runtimeInitialized) {
1366 $this->globals[
$name] = $value;
1368 $this->staging->addGlobal(
$name, $value);
1381 if (!$this->runtimeInitialized && !$this->extensionInitialized) {
1385 if (
null === $this->globals) {
1404 if (!array_key_exists(
$key, $context)) {
1405 $context[
$key] = $value;
1421 if (!$this->extensionInitialized) {
1437 if (!$this->extensionInitialized) {
1449 @trigger_error(
sprintf(
'The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
1460 foreach ($this->extensions as
$name => $extension) {
1462 $m =
new ReflectionMethod($extension,
'getGlobals');
1464 if (
'Twig_Extension' !==
$m->getDeclaringClass()->getName()) {
1465 @trigger_error(
sprintf(
'Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig_Extension_GlobalsInterface is deprecated since version 1.23.',
$name), E_USER_DEPRECATED);
1469 $extGlob = $extension->getGlobals();
1470 if (!is_array($extGlob)) {
1471 throw new UnexpectedValueException(
sprintf(
'"%s::getGlobals()" must return an array of globals.', get_class($extension)));
1477 $globals[] = $this->staging->getGlobals();
1479 return call_user_func_array(
'array_merge',
$globals);
1487 if ($this->extensionInitialized) {
1492 $this->filters = array();
1493 $this->functions = array();
1494 $this->tests = array();
1495 $this->visitors = array();
1496 $this->unaryOperators = array();
1497 $this->binaryOperators = array();
1499 foreach ($this->extensions as $extension) {
1504 $this->extensionInitialized =
true;
1515 $name = $filter->getName();
1517 @trigger_error(
sprintf(
'Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use Twig_SimpleFilter instead.', get_class($filter),
$name), E_USER_DEPRECATED);
1520 $this->filters[
$name] = $filter;
1528 @trigger_error(
sprintf(
'Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use Twig_SimpleFunction instead.', get_class(
$function),
$name), E_USER_DEPRECATED);
1539 @trigger_error(
sprintf(
'Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use Twig_SimpleTest instead.', get_class(
$test),
$name), E_USER_DEPRECATED);
1548 $this->parsers->addTokenParser(
$parser);
1550 @trigger_error(
'Registering a Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED);
1552 $this->parsers->addTokenParserBroker(
$parser);
1554 throw new LogicException(
'getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances.');
1560 $this->visitors[] = $visitor;
1565 if (!is_array($operators)) {
1566 throw new InvalidArgumentException(
sprintf(
'"%s::getOperators()" must return an array with operators, got "%s".', get_class($extension), is_object($operators) ? get_class($operators) : gettype($operators).(is_resource($operators) ?
'' :
'#'.$operators)));
1569 if (2 !== count($operators)) {
1570 throw new InvalidArgumentException(
sprintf(
'"%s::getOperators()" must return an array of 2 elements, got %d.', get_class($extension), count($operators)));
1573 $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
1574 $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
1583 $this->cache->write(
$file, $content);
1588 $hashParts = array_merge(
1589 array_keys($this->extensions),
1591 (
int) function_exists(
'twig_template_get_attributes'),
1596 $this->baseTemplateClass,
1597 (
int) $this->strictVariables,
1600 $this->optionsHash = implode(
':', $hashParts);
1604class_alias(
'Twig_Environment',
'Twig\Environment',
false);
sprintf('%.4f', $callTime)
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
An exception for terminatinating execution or to throw for unit testing.
Implements a cache on the filesystem.
Implements a no-cache strategy.
Compiles a node to PHP code.
Stores the Twig configuration.
clearCacheFiles()
Clears the template cache files on the filesystem.
disableAutoReload()
Disables the auto_reload option.
isDebug()
Checks if debug mode is enabled.
compile(Twig_NodeInterface $node)
Compiles a node and returns the PHP code.
registerUndefinedFilterCallback($callable)
getCompiler()
Gets the Compiler instance.
setBaseTemplateClass($class)
Sets the base template class for compiled templates.
getLexer()
Gets the Lexer instance.
getTokenParsers()
Gets the registered Token Parsers.
removeExtension($name)
Removes an extension by name.
disableDebug()
Disables debugging mode.
setLoader(Twig_LoaderInterface $loader)
getBinaryOperators()
Gets the registered binary Operators.
registerUndefinedFunctionCallback($callable)
getGlobals()
Gets the registered Globals.
computeAlternatives($name, $items)
setCompiler(Twig_CompilerInterface $compiler)
setParser(Twig_ParserInterface $parser)
initRuntime()
Initializes the runtime environment.
getExtensions()
Returns all registered extensions.
getRuntime($class)
Returns the runtime implementation of a Twig element (filter/function/test).
setLexer(Twig_LexerInterface $lexer)
getUnaryOperators()
Gets the registered unary Operators.
__construct(Twig_LoaderInterface $loader=null, $options=array())
Constructor.
compileSource($source, $name=null)
Compiles a template source code.
isStrictVariables()
Checks if the strict_variables option is enabled.
disableStrictVariables()
Disables the strict_variables option.
initExtension(Twig_ExtensionInterface $extension)
addRuntimeLoader(Twig_RuntimeLoaderInterface $loader)
Adds a runtime loader.
getLoader()
Gets the Loader instance.
getFunction($name)
Get a function by name.
createTemplate($template)
Creates a template from source.
tokenize($source, $name=null)
Tokenizes a source code.
hasExtension($class)
Returns true if the given extension is registered.
addTest($name, $test=null)
Registers a Test.
setCharset($charset)
Sets the default template charset.
addGlobal($name, $value)
Registers a Global.
loadTemplate($name, $index=null)
Loads a template internal representation.
load($name)
Loads a template.
setCache($cache)
Sets the current cache implementation.
parse(Twig_TokenStream $stream)
Converts a token stream to a node tree.
enableDebug()
Enables debugging mode.
mergeGlobals(array $context)
Merges a context with the defined globals.
writeCacheFile($file, $content)
setExtensions(array $extensions)
Registers an array of extensions.
getFunctions()
Gets registered functions.
getTests()
Gets the registered Tests.
getTemplateClassPrefix()
Gets the template class prefix.
getCacheFilename($name)
Gets the cache filename for a given template.
addFilter($name, $filter=null)
Registers a Filter.
isAutoReload()
Checks if the auto_reload option is enabled.
enableAutoReload()
Enables the auto_reload option.
addExtension(Twig_ExtensionInterface $extension)
getFilters()
Gets the registered Filters.
getFilter($name)
Get a filter by name.
enableStrictVariables()
Enables the strict_variables option.
getTemplateClass($name, $index=null)
Gets the template class associated with the given string.
getExtension($class)
Gets an extension by class name.
render($name, array $context=array())
Renders a template.
clearTemplateCache()
Clears the internal template cache.
getTags()
Gets registered tags.
getNodeVisitors()
Gets the registered Node Visitors.
display($name, array $context=array())
Displays a template.
addNodeVisitor(Twig_NodeVisitorInterface $visitor)
getBaseTemplateClass()
Gets the base template class for compiled templates.
getCharset()
Gets the default template charset.
resolveTemplate($names)
Tries to load a template consecutively from an array.
getCache($original=true)
Gets the current cache implementation.
getTest($name)
Gets a test by name.
getParser()
Gets the Parser instance.
isTemplateFresh($name, $time)
Returns true if the template is still fresh.
addFunction($name, $function=null)
Registers a Function.
addTokenParser(Twig_TokenParserInterface $parser)
Exception thrown when an error occurs during template loading.
Exception thrown when an error occurs at runtime.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
static computeAlternatives($name, $items)
setSourceContext(Twig_Source $source=null)
Sets the source context of the Twig template where the error occurred.
Loads a template from an array.
Loads templates from other loaders.
Default parser implementation.
Represents a template filter.
Represents a template function.
Represents a template test.
Holds information about a non-compiled Twig template.
Exposes a template to userland.
Default base class for compiled templates.
Default implementation of a token parser broker.
Represents a token stream.
Interface implemented by cache classes.
Interface implemented by compiler classes.
Interface implemented by extension classes.
getFilters()
Returns a list of filters to add to the existing list.
getTokenParsers()
Returns the token parser instances to add to the existing list.
getOperators()
Returns a list of operators to add to the existing list.
getFunctions()
Returns a list of functions to add to the existing list.
getTests()
Returns a list of tests to add to the existing list.
getNodeVisitors()
Returns the node visitor instances to add to the existing list.
getName()
Returns the name of the extension.
Enables usage of the deprecated Twig_Extension::getGlobals() method.
Enables usage of the deprecated Twig_Extension::initRuntime() method.
Represents a template filter.
Represents a template function.
Interface implemented by lexer classes.
Interface all loaders must implement.
Represents a node in the AST.
Twig_NodeVisitorInterface is the interface the all node visitor classes must implement.
Interface implemented by parser classes.
Creates runtime implementations for Twig elements (filters/functions/tests).
Adds a getSourceContext() method for loaders.
Represents a template test.
Interface implemented by token parser brokers.
Interface implemented by token parsers.
$stream
PHP stream implementation.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file