Revision 1938
Added by darkviper almost 11 years ago
Environment.php | ||
---|---|---|
12 | 12 |
/** |
13 | 13 |
* Stores the Twig configuration. |
14 | 14 |
* |
15 |
* @package twig |
|
16 |
* @author Fabien Potencier <fabien@symfony.com> |
|
15 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 | 16 |
*/ |
18 | 17 |
class Twig_Environment |
19 | 18 |
{ |
20 |
const VERSION = '1.12.2';
|
|
19 |
const VERSION = '1.13.1';
|
|
21 | 20 |
|
22 | 21 |
protected $charset; |
23 | 22 |
protected $loader; |
... | ... | |
54 | 53 |
* * debug: When set to true, it automatically set "auto_reload" to true as |
55 | 54 |
* well (default to false). |
56 | 55 |
* |
57 |
* * charset: The charset used by the templates (default to utf-8).
|
|
56 |
* * charset: The charset used by the templates (default to UTF-8).
|
|
58 | 57 |
* |
59 | 58 |
* * base_template_class: The base template class to use for generated |
60 | 59 |
* templates (default to Twig_Template). |
... | ... | |
100 | 99 |
), $options); |
101 | 100 |
|
102 | 101 |
$this->debug = (bool) $options['debug']; |
103 |
$this->charset = $options['charset'];
|
|
102 |
$this->charset = strtoupper($options['charset']);
|
|
104 | 103 |
$this->baseTemplateClass = $options['base_template_class']; |
105 | 104 |
$this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload']; |
106 | 105 |
$this->strictVariables = (bool) $options['strict_variables']; |
... | ... | |
567 | 566 |
*/ |
568 | 567 |
public function setCharset($charset) |
569 | 568 |
{ |
570 |
$this->charset = $charset;
|
|
569 |
$this->charset = strtoupper($charset);
|
|
571 | 570 |
} |
572 | 571 |
|
573 | 572 |
/** |
... | ... | |
757 | 756 |
*/ |
758 | 757 |
public function addFilter($name, $filter = null) |
759 | 758 |
{ |
760 |
if ($this->extensionInitialized) { |
|
761 |
throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name)); |
|
762 |
} |
|
763 |
|
|
764 | 759 |
if (!$name instanceof Twig_SimpleFilter && !($filter instanceof Twig_SimpleFilter || $filter instanceof Twig_FilterInterface)) { |
765 | 760 |
throw new LogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter'); |
766 | 761 |
} |
... | ... | |
769 | 764 |
$filter = $name; |
770 | 765 |
$name = $filter->getName(); |
771 | 766 |
} |
772 |
|
|
767 |
|
|
768 |
if ($this->extensionInitialized) { |
|
769 |
throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name)); |
|
770 |
} |
|
771 |
|
|
773 | 772 |
$this->staging->addFilter($name, $filter); |
774 | 773 |
} |
775 | 774 |
|
... | ... | |
846 | 845 |
*/ |
847 | 846 |
public function addTest($name, $test = null) |
848 | 847 |
{ |
849 |
if ($this->extensionInitialized) { |
|
850 |
throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name)); |
|
851 |
} |
|
852 |
|
|
853 | 848 |
if (!$name instanceof Twig_SimpleTest && !($test instanceof Twig_SimpleTest || $test instanceof Twig_TestInterface)) { |
854 | 849 |
throw new LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest'); |
855 | 850 |
} |
... | ... | |
858 | 853 |
$test = $name; |
859 | 854 |
$name = $test->getName(); |
860 | 855 |
} |
856 |
|
|
857 |
if ($this->extensionInitialized) { |
|
858 |
throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name)); |
|
859 |
} |
|
861 | 860 |
|
862 | 861 |
$this->staging->addTest($name, $test); |
863 | 862 |
} |
... | ... | |
904 | 903 |
*/ |
905 | 904 |
public function addFunction($name, $function = null) |
906 | 905 |
{ |
907 |
if ($this->extensionInitialized) { |
|
908 |
throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name)); |
|
909 |
} |
|
910 |
|
|
911 | 906 |
if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) { |
912 | 907 |
throw new LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction'); |
913 | 908 |
} |
... | ... | |
916 | 911 |
$function = $name; |
917 | 912 |
$name = $function->getName(); |
918 | 913 |
} |
919 |
|
|
914 |
|
|
915 |
if ($this->extensionInitialized) { |
|
916 |
throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name)); |
|
917 |
} |
|
918 |
|
|
920 | 919 |
$this->staging->addFunction($name, $function); |
921 | 920 |
} |
922 | 921 |
|
... | ... | |
1100 | 1099 |
{ |
1101 | 1100 |
$globals = array(); |
1102 | 1101 |
foreach ($this->extensions as $extension) { |
1103 |
$globals = array_merge($globals, $extension->getGlobals()); |
|
1102 |
$extGlob = $extension->getGlobals(); |
|
1103 |
if (!is_array($extGlob)) { |
|
1104 |
throw new UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', get_class($extension))); |
|
1105 |
} |
|
1106 |
|
|
1107 |
$globals[] = $extGlob; |
|
1104 | 1108 |
} |
1105 | 1109 |
|
1106 |
return array_merge($globals, $this->staging->getGlobals()); |
|
1110 |
$globals[] = $this->staging->getGlobals(); |
|
1111 |
|
|
1112 |
return call_user_func_array('array_merge', $globals); |
|
1107 | 1113 |
} |
1108 | 1114 |
|
1109 | 1115 |
protected function initExtensions() |
Also available in: Unified diff
update Twig template engine to version 1.13.1