*/
class Twig_Environment
{
- const VERSION = '1.34.3';
- const VERSION_ID = 13403;
+ const VERSION = '1.35.4';
+ const VERSION_ID = 13504;
const MAJOR_VERSION = 1;
- const MINOR_VERSION = 34;
- const RELEASE_VERSION = 3;
+ const MINOR_VERSION = 35;
+ const RELEASE_VERSION = 4;
const EXTRA_VERSION = '';
protected $charset;
private $runtimeLoaders = array();
private $runtimes = array();
private $optionsHash;
+ private $loading = array();
/**
* Constructor.
// For BC
if (is_string($this->originalCache)) {
$r = new ReflectionMethod($this, 'writeCacheFile');
- if ($r->getDeclaringClass()->getName() !== __CLASS__) {
+ if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error('The Twig_Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
$this->bcWriteCacheFile = true;
}
$r = new ReflectionMethod($this, 'getCacheFilename');
- if ($r->getDeclaringClass()->getName() !== __CLASS__) {
+ if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error('The Twig_Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
$this->bcGetCacheFilename = true;
*
* @param string|Twig_TemplateWrapper|Twig_Template $name The template name
*
+ * @throws Twig_Error_Loader When the template cannot be found
+ * @throws Twig_Error_Runtime When a previously generated cache is corrupted
+ * @throws Twig_Error_Syntax When an error occurred during compilation
+ *
* @return Twig_TemplateWrapper
*/
public function load($name)
$this->initRuntime();
}
- return $this->loadedTemplates[$cls] = new $cls($this);
+ if (isset($this->loading[$cls])) {
+ throw new Twig_Error_Runtime(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, array($name)))));
+ }
+
+ $this->loading[$cls] = $name;
+
+ try {
+ $this->loadedTemplates[$cls] = new $cls($this);
+ unset($this->loading[$cls]);
+ } catch (\Exception $e) {
+ unset($this->loading[$cls]);
+
+ throw $e;
+ }
+
+ return $this->loadedTemplates[$cls];
}
/**
/**
* Tries to load a template consecutively from an array.
*
- * Similar to loadTemplate() but it also accepts Twig_TemplateInterface instances and an array
- * of templates where each is tried to be loaded.
+ * Similar to loadTemplate() but it also accepts instances of Twig_Template and
+ * Twig_TemplateWrapper, and an array of templates where each is tried to be loaded.
*
- * @param string|Twig_Template|array $names A template or an array of templates to try consecutively
+ * @param string|Twig_Template|Twig_TemplateWrapper|array $names A template or an array of templates to try consecutively
*
- * @return Twig_Template
+ * @return Twig_Template|Twig_TemplateWrapper
*
* @throws Twig_Error_Loader When none of the templates can be found
* @throws Twig_Error_Syntax When an error occurred during compilation
return $name;
}
+ if ($name instanceof Twig_TemplateWrapper) {
+ return $name;
+ }
+
try {
return $this->loadTemplate($name);
} catch (Twig_Error_Loader $e) {