From 90b9cb2c99ef6527aa310d2037ae437bb210b57b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 27 Jul 2016 17:15:50 -0700 Subject: [PATCH] CRM_Core_CodeGen_Util_Smarty - Allow generating templates without a special bootstrap --- CRM/Core/CodeGen/Main.php | 6 ++---- CRM/Core/CodeGen/Util/Smarty.php | 17 ++++------------- CRM/Core/CodeGen/Util/Template.php | 4 ++++ .../phpunit/CRM/Core/CodeGen/FreshnessTest.php | 7 ++----- xml/GenCode.php | 2 +- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/CRM/Core/CodeGen/Main.php b/CRM/Core/CodeGen/Main.php index bb681dc204..a9b83b3a4e 100644 --- a/CRM/Core/CodeGen/Main.php +++ b/CRM/Core/CodeGen/Main.php @@ -44,13 +44,13 @@ class CRM_Core_CodeGen_Main { * @param $sqlCodePath * @param $phpCodePath * @param $tplCodePath - * @param $smartyPluginDirs + * @param $IGNORE * @param $argCms * @param $argVersion * @param $schemaPath * @param $digestPath */ - public function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $smartyPluginDirs, $argCms, $argVersion, $schemaPath, $digestPath) { + public function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $IGNORE, $argCms, $argVersion, $schemaPath, $digestPath) { $this->CoreDAOCodePath = $CoreDAOCodePath; $this->sqlCodePath = $sqlCodePath; $this->phpCodePath = $phpCodePath; @@ -61,8 +61,6 @@ class CRM_Core_CodeGen_Main { // default cms is 'drupal', if not specified $this->cms = isset($argCms) ? strtolower($argCms) : 'drupal'; - CRM_Core_CodeGen_Util_Smarty::singleton()->setPluginDirs($smartyPluginDirs); - $versionFile = $this->phpCodePath . "/xml/version.xml"; $versionXML = CRM_Core_CodeGen_Util_Xml::parse($versionFile); $this->db_version = $versionXML->version_no; diff --git a/CRM/Core/CodeGen/Util/Smarty.php b/CRM/Core/CodeGen/Util/Smarty.php index 6044f3808f..7e22561d9a 100644 --- a/CRM/Core/CodeGen/Util/Smarty.php +++ b/CRM/Core/CodeGen/Util/Smarty.php @@ -19,8 +19,6 @@ class CRM_Core_CodeGen_Util_Smarty { return self::$singleton; } - private $smartyPluginDirs = array(); - private $compileDir; public function __destruct() { @@ -29,15 +27,6 @@ class CRM_Core_CodeGen_Util_Smarty { } } - /** - * Set plugin directories. - * - * @param array $pluginDirs - */ - public function setPluginDirs($pluginDirs) { - $this->smartyPluginDirs = $pluginDirs; - } - /** * Get templates_c directory. * @@ -56,10 +45,12 @@ class CRM_Core_CodeGen_Util_Smarty { * @return \Smarty */ public function createSmarty() { + $base = dirname(dirname(dirname(dirname(__DIR__)))); + require_once 'Smarty/Smarty.class.php'; $smarty = new Smarty(); - $smarty->template_dir = './templates'; - $smarty->plugins_dir = $this->smartyPluginDirs; + $smarty->template_dir = "$base/xml/templates"; + $smarty->plugins_dir = array("$base/packages/Smarty/plugins", "$base/CRM/Core/Smarty/plugins"); $smarty->compile_dir = $this->getCompileDir(); $smarty->clear_all_cache(); diff --git a/CRM/Core/CodeGen/Util/Template.php b/CRM/Core/CodeGen/Util/Template.php index 0c08aa9135..36af880bf6 100644 --- a/CRM/Core/CodeGen/Util/Template.php +++ b/CRM/Core/CodeGen/Util/Template.php @@ -68,6 +68,10 @@ class CRM_Core_CodeGen_Util_Template { } } + public function fetch($infile) { + return $this->smarty->fetch($infile); + } + /** * @param $key * @param $value diff --git a/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php b/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php index 0868747abc..bde3451d1e 100644 --- a/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php +++ b/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php @@ -13,6 +13,7 @@ class CRM_Core_CodeGen_FreshnessTest extends CiviUnitTestCase { $tasks = $this->findTasks('CRM_Core_CodeGen_DAO'); $names = array(); foreach ($tasks as $task) { + /** @var CRM_Core_CodeGen_DAO $task */ $names[] = $task->name; $this->assertFalse($task->needsUpdate(), "Expect DAO for {$task->name} is up-to-date"); } @@ -59,11 +60,7 @@ class CRM_Core_CodeGen_FreshnessTest extends CiviUnitTestCase { $path . '/sql/', // $sqlCodePath $path . '/', // $phpCodePath $path . '/templates/', // $tplCodePath - array( - // smarty plugin dirs - $path . '/packages/Smarty/plugins', - $path . '/CRM/Core/Smarty/plugins', - ), + NULL, // IGNORE, CIVICRM_UF, // cms NULL, // db version $path . '/xml/schema/Schema.xml', // schema file diff --git a/xml/GenCode.php b/xml/GenCode.php index 76e6fa6c9d..dc071c795a 100644 --- a/xml/GenCode.php +++ b/xml/GenCode.php @@ -31,7 +31,7 @@ $genCode = new CRM_Core_CodeGen_Main( '../sql/', // $sqlCodePath '../', // $phpCodePath '../templates/', // $tplCodePath - array('../packages/Smarty/plugins', '../CRM/Core/Smarty/plugins'), // smarty plugin dirs + NULL, // IGNORE @$argv[3], // cms empty($argv[2]) ? NULL : $argv[2], // db version empty($argv[1]) ? 'schema/Schema.xml' : $argv[1], // schema file -- 2.25.1