CRM-14885 - CRM_Core_CodeGen_Util_Template - Use fresh instances of Smarty
authorTim Otten <totten@civicrm.org>
Wed, 27 Jul 2016 05:39:15 +0000 (22:39 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 28 Jul 2016 00:20:16 +0000 (17:20 -0700)
CRM/Core/CodeGen/Util/Smarty.php
CRM/Core/CodeGen/Util/Template.php

index 8ab0b2adcb0c2388a8b370a38477164103c368c2..6044f3808ff014f0c16fa52c1dd37a97eaae5df5 100644 (file)
@@ -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;
   }
 
 }
index b6387e48d4a52d14fb2c3c75d960421f2ec27501..0c08aa91355e941df97b2119e957c1d1c636280b 100644 (file)
@@ -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();
-  }
-
 }