summaryrefslogtreecommitdiff
path: root/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php
diff options
context:
space:
mode:
authorwei <>2006-12-04 00:02:23 +0000
committerwei <>2006-12-04 00:02:23 +0000
commit18ea316c553f7ccfc18b73f0c987de007f11b275 (patch)
treeb8fa0d14de75582b48c3e4d12050c84f07805920 /framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php
parentb69ca04f50ffd538239342f3bfd1e77ffc6156c0 (diff)
Fixed #469
Diffstat (limited to 'framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php')
-rw-r--r--framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php b/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php
new file mode 100644
index 00000000..b67f7aae
--- /dev/null
+++ b/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * TSimpleDynamicParser class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TSimpleDynamicParser finds place holders $name$ in the sql text and replaces
+ * it with a TSimpleDynamicParser::DYNAMIC_TOKEN.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSimpleDynamicParser
+{
+ const PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/';
+ const DYNAMIC_TOKEN = '`!`';
+
+ /**
+ * Parse the sql text for dynamic place holders of the form $name$.
+ * @param string Sql text.
+ * @return array name value pairs 'sql' and 'parameters'.
+ */
+ public function parse($sqlText)
+ {
+ $matches = array();
+ $mappings = array();
+ preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
+ for($i = 0, $k=count($matches[1]); $i<$k; $i++)
+ {
+ $mappings[] = $matches[1][$i];
+ $sqlText = str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText);
+ }
+ return array('sql'=>$sqlText, 'parameters'=>$mappings);
+ }
+}
+
+?> \ No newline at end of file