From: Tim Otten Date: Wed, 27 Jul 2016 21:22:29 +0000 (-0700) Subject: CRM_Core_CodeGen_BaseTask::extractRegex() - Pull up helper from subclass X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=64b070bfca54d649076498a41b6e19af5791dd51;p=civicrm-core.git CRM_Core_CodeGen_BaseTask::extractRegex() - Pull up helper from subclass --- diff --git a/CRM/Core/CodeGen/BaseTask.php b/CRM/Core/CodeGen/BaseTask.php index f220415bd0..73bf72a5d7 100644 --- a/CRM/Core/CodeGen/BaseTask.php +++ b/CRM/Core/CodeGen/BaseTask.php @@ -37,4 +37,24 @@ abstract class CRM_Core_CodeGen_BaseTask implements CRM_Core_CodeGen_ITask { return TRUE; } + /** + * Extract a single regex from a file. + * + * @param string $file + * File name + * @param string $regex + * A pattern to match. Ex: "foo=([a-z]+)". + * @return string|NULL + * The value matched. + */ + protected static function extractRegex($file, $regex) { + $content = file_get_contents($file); + if (preg_match($regex, $content, $matches)) { + return $matches[1]; + } + else { + return NULL; + } + } + } diff --git a/CRM/Core/CodeGen/DAO.php b/CRM/Core/CodeGen/DAO.php index d182ceeb4f..e070af5ce4 100644 --- a/CRM/Core/CodeGen/DAO.php +++ b/CRM/Core/CodeGen/DAO.php @@ -28,7 +28,7 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask { if (!file_exists($this->getAbsFileName())) { return TRUE; } - return $this->getChecksum() !== self::extractChecksum($this->getAbsFileName(), ';\(GenCodeChecksum:([a-z0-9]+)\);'); + return $this->getChecksum() !== self::extractRegex($this->getAbsFileName(), ';\(GenCodeChecksum:([a-z0-9]+)\);'); } public function run() { @@ -59,16 +59,6 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask { return $absFileName; } - protected static function extractChecksum($file, $regex) { - $content = file_get_contents($file); - if (preg_match($regex, $content, $matches)) { - return $matches[1]; - } - else { - return NULL; - } - } - protected function getChecksum() { if (!$this->checksum) { CRM_Utils_Array::flatten($this->tables[$this->name], $flat);