4 * Class CRM_Core_CodeGen_BaseTask
6 abstract class CRM_Core_CodeGen_BaseTask
implements CRM_Core_CodeGen_ITask
{
8 * @var CRM_Core_CodeGen_Main
15 * @param CRM_Core_CodeGen_Main $config
17 public function __construct($config) {
18 $this->setConfig($config);
22 * TODO: this is the most rudimentary possible hack. CG config should
23 * eventually be made into a first-class object.
25 * @param object $config
27 public function setConfig($config) {
28 $this->config
= $config;
29 $this->tables
= $this->config
->tables
;
34 * TRUE if an update is needed.
36 public function needsUpdate() {
41 * Extract a single regex from a file.
45 * @param string $regex
46 * A pattern to match. Ex: "foo=([a-z]+)".
50 protected static function extractRegex($file, $regex) {
51 $content = file_get_contents($file);
52 if (preg_match($regex, $content, $matches)) {
61 * Determine if two snippets of PHP code are approximately equivalent.
63 * This includes exceptions to equivalence for (a) whitespace and (b)
64 * the token "GenCodeChecksum".
66 * This is useful for determining if someone has manually mucked with
67 * one the files. However, it's not perfect -- because whitespace changes
68 * are not detected. Hence, it's good to use in combination with another
75 protected function isApproxPhpMatch($actual, $expected) {
76 foreach (['actual', 'expected'] as $var) {
77 $
$var = CRM_Core_CodeGen_Util_ArraySyntaxConverter
::convert($
$var);
78 $
$var = preg_replace("# '\\d+' => #", " ", $
$var);
79 $
$var = preg_replace(';\(GenCodeChecksum:([a-zA-Z0-9]+)\);', '', $
$var);
80 $
$var = strtolower(preg_replace(';[ \r\n\t];', '', $
$var));
82 return $actual === $expected;