4 * Class CRM_Core_CodeGen_Util_Template
6 class CRM_Core_CodeGen_Util_Template
{
10 protected $beautifier;
13 * @param string $filetype
15 public function __construct($filetype) {
16 $this->filetype
= $filetype;
18 $this->smarty
= CRM_Core_CodeGen_Util_Smarty
::singleton()->getSmarty();
20 $this->assign('generated', "DO NOT EDIT. Generated by CRM_Core_CodeGen");
22 // CRM-5308 / CRM-3507 - we need {localize} to work in the templates
23 require_once 'CRM/Core/Smarty/plugins/block.localize.php';
24 $this->smarty
->register_block('localize', 'smarty_block_localize');
26 if ($this->filetype
=== 'php') {
27 require_once 'PHP/Beautifier.php';
29 $this->beautifier
= new PHP_Beautifier();
30 $this->beautifier
->addFilter('ArrayNested');
31 // add one or more filters
32 $this->beautifier
->addFilter('Pear');
33 // add one or more filters
34 $this->beautifier
->addFilter('NewLines', array('after' => 'class, public, require, comment'));
35 $this->beautifier
->setIndentChar(' ');
36 $this->beautifier
->setIndentNumber(2);
37 $this->beautifier
->setNewLine("\n");
42 * @param array $inputs
44 * @param string $outpath
45 * Full path to the desired output file.
47 public function runConcat($inputs, $outpath) {
48 if (file_exists($outpath)) {
51 foreach ($inputs as $infile) {
52 // FIXME: does not beautify. Document.
53 file_put_contents($outpath, $this->smarty
->fetch($infile) . "\n", FILE_APPEND
);
58 * @param string $infile
59 * Filename of the template, without a path.
60 * @param string $outpath
61 * Full path to the desired output file.
63 public function run($infile, $outpath) {
64 $renderedContents = $this->smarty
->fetch($infile);
66 if ($this->filetype
=== 'php') {
67 $this->beautifier
->setInputString($renderedContents);
68 $this->beautifier
->setOutputFile($outpath);
69 $this->beautifier
->process();
70 $this->beautifier
->save();
73 file_put_contents($outpath, $renderedContents);
81 public function assign($key, $value) {
82 $this->smarty
->assign_by_ref($key, $value);
86 * Clear the smarty cache and assign default values
87 * FIXME: unused cos we no longer do evil singleton magick
89 protected function reset() {
90 $this->smarty
->clear_all_assign();
91 $this->smarty
->clear_all_cache();