protected $beautifier;
/**
- * @var array
- * 'beautifier' => bool
- * 'fudging' => bool
- * 'arraySyntax' => bool
+ * @var bool
*/
- protected $filters;
+ protected $beautify;
/**
* @param string $filetype
- * @praam array $filters
- * 'beautifier' => bool
- * 'fudging' => bool
- * 'arraySyntax' => bool
+ * @param bool $beautify
*/
- public function __construct($filetype, $filters = array()) {
+ public function __construct($filetype, $beautify = TRUE) {
$this->filetype = $filetype;
$this->smarty = CRM_Core_CodeGen_Util_Smarty::singleton()->createSmarty();
$this->assign('generated', "DO NOT EDIT. Generated by CRM_Core_CodeGen");
- if ($this->filetype === 'php') {
+ if ($this->filetype === 'php' && $beautify) {
require_once 'PHP/Beautifier.php';
// create an instance
$this->beautifier = new PHP_Beautifier();
$this->beautifier->setIndentChar(' ');
$this->beautifier->setIndentNumber(2);
$this->beautifier->setNewLine("\n");
-
- $phpDefaultFilters = ['beautifier' => TRUE, 'fudging' => TRUE, 'arraySyntax' => TRUE];
- $filters = array_merge($phpDefaultFilters, $filters);
}
- $this->filters = $filters;
+ $this->beautify = $beautify;
}
/**
public function run($infile, $outpath) {
$contents = $this->smarty->fetch($infile);
- if ($this->filetype === 'php') {
- if ($this->filters['beautifier']) {
- $this->beautifier->setInputString($contents);
- $this->beautifier->process();
- $contents = $this->beautifier->get();
- }
+ if ($this->filetype === 'php' && $this->beautify) {
+ $this->beautifier->setInputString($contents);
+ $this->beautifier->process();
+ $contents = $this->beautifier->get();
// The beautifier isn't as beautiful as one would hope. Here's some extra string fudging.
- if ($this->filters['fudging']) {
- $replacements = [
- ') ,' => '),',
- "\n }\n}\n" => "\n }\n\n}\n",
- '=> true,' => '=> TRUE,',
- '=> false,' => '=> FALSE,',
- ];
- $contents = str_replace(array_keys($replacements), array_values($replacements), $contents);
- $contents = preg_replace('#(\s*)\\/\\*\\*#', "\n\$1/**", $contents);
- }
+ $replacements = [
+ ') ,' => '),',
+ "\n }\n}\n" => "\n }\n\n}\n",
+ '=> true,' => '=> TRUE,',
+ '=> false,' => '=> FALSE,',
+ ];
+ $contents = str_replace(array_keys($replacements), array_values($replacements), $contents);
+ $contents = preg_replace('#(\s*)\\/\\*\\*#', "\n\$1/**", $contents);
// Convert old array syntax to new square brackets
- if ($this->filters['arraySyntax']) {
- $contents = CRM_Core_CodeGen_Util_ArraySyntaxConverter::convert($contents);
- }
- file_put_contents($outpath, $contents);
+ $contents = CRM_Core_CodeGen_Util_ArraySyntaxConverter::convert($contents);
}
- else {
- file_put_contents($outpath, $contents);
+ // Ensure file ends with a newline
+ if (substr($contents, -1) !== "\n") {
+ $contents .= "\n";
}
+ file_put_contents($outpath, $contents);
}
/**
<?php
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.7 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-
// (GenCodeChecksum:IGNORE)
return [
'class' => 'CRM_Price_DAO_LineItem',
'table' => 'civicrm_line_item',
],
-];
\ No newline at end of file
+];
<?php
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.7 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-
// (GenCodeChecksum:{$genCodeChecksum})
-return array(
+return [
{foreach from=$tables key=tableName item=table}
- '{$table.className}' => array(
+ '{$table.className}' => [
'name' => '{$table.objectName}',
'class' => '{$table.className}',
'table' => '{$tableName}',
- ),
+ ],
{/foreach}
-);
+];