From ff1a1d220447ec2e5230866edb5f4472a0e0054c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 7 Aug 2020 13:05:52 -0400 Subject: [PATCH] REF - add helper function to get codeGen tpl --- CRM/Core/CodeGen/DAO.php | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/CRM/Core/CodeGen/DAO.php b/CRM/Core/CodeGen/DAO.php index 2bd4e810ce..ef6dc88f96 100644 --- a/CRM/Core/CodeGen/DAO.php +++ b/CRM/Core/CodeGen/DAO.php @@ -75,17 +75,8 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask { return; } - $template = new CRM_Core_CodeGen_Util_Template('php'); - $template->assign('table', $this->tables[$this->name]); - if (empty($this->tables[$this->name]['index'])) { - $template->assign('indicesPhp', var_export([], 1)); - } - else { - $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1)); - } + $template = $this->getTemplate(); $template->assign('genCodeChecksum', $this->getTableChecksum()); - $template->assign('tsFunctionName', $this->tsFunctionName); - $template->assign('useHelper', $this->useHelper); $template->run('dao.tpl', $this->getAbsFileName()); } @@ -96,22 +87,30 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask { */ public function getRaw() { if (!$this->raw) { - $template = new CRM_Core_CodeGen_Util_Template('php'); - $template->assign('table', $this->tables[$this->name]); - if (empty($this->tables[$this->name]['index'])) { - $template->assign('indicesPhp', var_export([], 1)); - } - else { - $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1)); - } + $template = $this->getTemplate(); $template->assign('genCodeChecksum', 'NEW'); - $template->assign('tsFunctionName', $this->tsFunctionName); - $template->assign('useHelper', $this->useHelper); $this->raw = $template->fetch('dao.tpl'); } return $this->raw; } + /** + * @return CRM_Core_CodeGen_Util_Template + */ + private function getTemplate() { + $template = new CRM_Core_CodeGen_Util_Template('php'); + $template->assign('table', $this->tables[$this->name]); + if (empty($this->tables[$this->name]['index'])) { + $template->assign('indicesPhp', var_export([], 1)); + } + else { + $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1)); + } + $template->assign('tsFunctionName', $this->tsFunctionName); + $template->assign('useHelper', $this->useHelper); + return $template; + } + /** * Get relative file name. * -- 2.25.1