11 public function __construct($srcPath, $fileType) {
12 $this->filetype
= $fileType;
14 $this->smarty
= \Civi\Setup\SmartyUtil
::createSmarty($srcPath);
16 $this->assign('generated', "DO NOT EDIT. Generated by Installer");
18 if ($this->filetype
=== 'php') {
19 $packagePath = PackageUtil
::getPath($srcPath);
20 require_once implode(DIRECTORY_SEPARATOR
, [$packagePath, 'PHP', 'Beautifier.php']);
22 $this->beautifier
= new PHP_Beautifier();
23 $this->beautifier
->addFilter('ArrayNested');
24 // add one or more filters
25 $this->beautifier
->setIndentChar(' ');
26 $this->beautifier
->setIndentNumber(2);
27 $this->beautifier
->setNewLine("\n");
31 public function assign($tpl_var, $value = NULL) {
32 return $this->smarty
->assign($tpl_var, $value);
36 * Run template generator.
38 * @param string $infile
39 * Filename of the template, without a path.
42 public function getContent($infile) {
43 $contents = $this->smarty
->fetch($infile);
45 if ($this->filetype
=== 'php') {
46 $this->beautifier
->setInputString($contents);
47 $this->beautifier
->process();
48 $contents = $this->beautifier
->get();
49 // The beautifier isn't as beautiful as one would hope. Here's some extra string fudging.
52 "\n }\n}\n" => "\n }\n\n}\n",
53 '=> true,' => '=> TRUE,',
54 '=> false,' => '=> FALSE,',
56 $contents = str_replace(array_keys($replacements), array_values($replacements), $contents);
57 $contents = preg_replace('#(\s*)\\/\\*\\*#', "\n\$1/**", $contents);
58 // Convert old array syntax to new square brackets
59 $contents = CRM_Core_CodeGen_Util_ArraySyntaxConverter
::convert($contents);
66 * @param array $inputs
69 public function getConcatContent($inputs) {
71 foreach ($inputs as $infile) {
72 // FIXME: does not beautify. Document.
73 $content .= $this->smarty
->fetch($infile) . "\n";