You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 14, 2023. It is now read-only.
@@ -771,29 +780,73 @@ public function initRuntime()
771
780
/**
772
781
* Returns true if the given extension is registered.
773
782
*
774
-
* @param string $name The extension name
783
+
* @param string $class The extension class name
775
784
*
776
785
* @return bool Whether the extension is registered or not
777
786
*/
778
-
publicfunctionhasExtension($name)
787
+
publicfunctionhasExtension($class)
788
+
{
789
+
if (isset($this->legacyExtensionNames[$class])) {
790
+
$class = $this->legacyExtensionNames[$class];
791
+
@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);
* @return Twig_ExtensionInterface A Twig_ExtensionInterface instance
789
811
*/
790
-
publicfunctiongetExtension($name)
812
+
publicfunctiongetExtension($class)
813
+
{
814
+
if (isset($this->legacyExtensionNames[$class])) {
815
+
$class = $this->legacyExtensionNames[$class];
816
+
@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);
817
+
}
818
+
819
+
$class = ltrim($class, '\\');
820
+
821
+
if (!isset($this->extensions[$class])) {
822
+
thrownewTwig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $class));
823
+
}
824
+
825
+
return$this->extensions[$class];
826
+
}
827
+
828
+
/**
829
+
* Returns the runtime implementation of a Twig element (filter/function/test).
830
+
*
831
+
* @param string $class A runtime class name
832
+
*
833
+
* @return object The runtime implementation
834
+
*
835
+
* @throws Twig_Error_Runtime When the template cannot be found
836
+
*/
837
+
publicfunctiongetRuntime($class)
791
838
{
792
-
if (!isset($this->extensions[$name])) {
793
-
thrownewTwig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $name));
839
+
if (isset($this->runtimes[$class])) {
840
+
return$this->runtimes[$class];
841
+
}
842
+
843
+
foreach ($this->runtimeLoadersas$loader) {
844
+
if (null !== $runtime = $loader->load($class)) {
845
+
return$this->runtimes[$class] = $runtime;
846
+
}
794
847
}
795
848
796
-
return$this->extensions[$name];
849
+
thrownewTwig_Error_Runtime(sprintf('Unable to load the "%s" runtime.', $class));
797
850
}
798
851
799
852
/**
@@ -803,19 +856,26 @@ public function getExtension($name)
thrownewLogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $name));
862
+
thrownewLogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $class));
810
863
}
811
864
812
-
if (isset($this->extensions[$name])) {
813
-
@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.', $name), E_USER_DEPRECATED);
@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.', $class), E_USER_DEPRECATED);
@@ -831,11 +891,17 @@ public function removeExtension($name)
831
891
{
832
892
@trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
833
893
894
+
if (isset($this->legacyExtensionNames[$name])) {
895
+
$name = $this->legacyExtensionNames[$name];
896
+
@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.', $name), E_USER_DEPRECATED);
897
+
}
898
+
834
899
if ($this->extensionInitialized) {
835
900
thrownewLogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name));
836
901
}
837
902
838
-
unset($this->extensions[$name]);
903
+
unset($this->extensions[ltrim($name, '\\')]);
904
+
$this->updateOptionsHash();
839
905
}
840
906
841
907
/**
@@ -853,7 +919,7 @@ public function setExtensions(array $extensions)
853
919
/**
854
920
* Returns all registered extensions.
855
921
*
856
-
* @return array An array of extensions
922
+
* @return Twig_ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on)
857
923
*/
858
924
publicfunctiongetExtensions()
859
925
{
@@ -950,7 +1016,7 @@ public function getNodeVisitors()
950
1016
publicfunctionaddFilter($name, $filter = null)
951
1017
{
952
1018
if (!$nameinstanceof Twig_SimpleFilter && !($filterinstanceof Twig_SimpleFilter || $filterinstanceof Twig_FilterInterface)) {
953
-
thrownewLogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter');
1019
+
thrownewLogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter.');
954
1020
}
955
1021
956
1022
if ($nameinstanceof Twig_SimpleFilter) {
@@ -1045,7 +1111,7 @@ public function getFilters()
1045
1111
publicfunctionaddTest($name, $test = null)
1046
1112
{
1047
1113
if (!$nameinstanceof Twig_SimpleTest && !($testinstanceof Twig_SimpleTest || $testinstanceof Twig_TestInterface)) {
1048
-
thrownewLogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest');
1114
+
thrownewLogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest.');
1049
1115
}
1050
1116
1051
1117
if ($nameinstanceof Twig_SimpleTest) {
@@ -1109,7 +1175,7 @@ public function getTest($name)
0 commit comments