From b7a48b7ecb381e818054d37e26b2ac67c1c2c21f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 26 Jul 2016 22:39:15 -0700 Subject: [PATCH] CRM-14885 - CRM_Core_CodeGen_Util_Template - Use fresh instances of Smarty --- CRM/Core/CodeGen/Util/Smarty.php | 32 ++++++++++++++---------------- CRM/Core/CodeGen/Util/Template.php | 15 +------------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/CRM/Core/CodeGen/Util/Smarty.php b/CRM/Core/CodeGen/Util/Smarty.php index 8ab0b2adcb..6044f3808f 100644 --- a/CRM/Core/CodeGen/Util/Smarty.php +++ b/CRM/Core/CodeGen/Util/Smarty.php @@ -21,11 +21,6 @@ class CRM_Core_CodeGen_Util_Smarty { private $smartyPluginDirs = array(); - /** - * @var Smarty - */ - private $smarty; - private $compileDir; public function __destruct() { @@ -41,7 +36,6 @@ class CRM_Core_CodeGen_Util_Smarty { */ public function setPluginDirs($pluginDirs) { $this->smartyPluginDirs = $pluginDirs; - $this->smarty = NULL; } /** @@ -57,20 +51,24 @@ class CRM_Core_CodeGen_Util_Smarty { } /** - * Get smarty instance. + * Create a Smarty instance. * * @return \Smarty */ - public function getSmarty() { - if ($this->smarty === NULL) { - require_once 'Smarty/Smarty.class.php'; - $this->smarty = new Smarty(); - $this->smarty->template_dir = './templates'; - $this->smarty->plugins_dir = $this->smartyPluginDirs; - $this->smarty->compile_dir = $this->getCompileDir(); - $this->smarty->clear_all_cache(); - } - return $this->smarty; + public function createSmarty() { + require_once 'Smarty/Smarty.class.php'; + $smarty = new Smarty(); + $smarty->template_dir = './templates'; + $smarty->plugins_dir = $this->smartyPluginDirs; + $smarty->compile_dir = $this->getCompileDir(); + $smarty->clear_all_cache(); + + // CRM-5308 / CRM-3507 - we need {localize} to work in the templates + + require_once 'CRM/Core/Smarty/plugins/block.localize.php'; + $smarty->register_block('localize', 'smarty_block_localize'); + + return $smarty; } } diff --git a/CRM/Core/CodeGen/Util/Template.php b/CRM/Core/CodeGen/Util/Template.php index b6387e48d4..0c08aa9135 100644 --- a/CRM/Core/CodeGen/Util/Template.php +++ b/CRM/Core/CodeGen/Util/Template.php @@ -15,14 +15,10 @@ class CRM_Core_CodeGen_Util_Template { public function __construct($filetype) { $this->filetype = $filetype; - $this->smarty = CRM_Core_CodeGen_Util_Smarty::singleton()->getSmarty(); + $this->smarty = CRM_Core_CodeGen_Util_Smarty::singleton()->createSmarty(); $this->assign('generated', "DO NOT EDIT. Generated by CRM_Core_CodeGen"); - // CRM-5308 / CRM-3507 - we need {localize} to work in the templates - require_once 'CRM/Core/Smarty/plugins/block.localize.php'; - $this->smarty->register_block('localize', 'smarty_block_localize'); - if ($this->filetype === 'php') { require_once 'PHP/Beautifier.php'; // create an instance @@ -80,13 +76,4 @@ class CRM_Core_CodeGen_Util_Template { $this->smarty->assign_by_ref($key, $value); } - /** - * Clear the smarty cache and assign default values. - * FIXME: unused cos we no longer do evil singleton magick - */ - protected function reset() { - $this->smarty->clear_all_assign(); - $this->smarty->clear_all_cache(); - } - } -- 2.25.1