3 * TSimpleDynamicParser class file.
5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6 * @link https://github.com/pradosoft/prado
7 * @copyright Copyright © 2005-2016 The PRADO Group
8 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9 * @package System.Data.SqlMap.Configuration
13 * TSimpleDynamicParser finds place holders $name$ in the sql text and replaces
14 * it with a TSimpleDynamicParser::DYNAMIC_TOKEN.
16 * @author Wei Zhuo <weizho[at]gmail[dot]com>
17 * @package System.Data.SqlMap.Configuration
20 class TSimpleDynamicParser
22 const PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/';
23 const DYNAMIC_TOKEN = '`!`';
26 * Parse the sql text for dynamic place holders of the form $name$.
27 * @param string Sql text.
28 * @return array name value pairs 'sql' and 'parameters'.
30 public function parse($sqlText)
34 preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
35 for($i = 0, $k=count($matches[1]); $i<$k; $i++)
37 $mappings[] = $matches[1][$i];
38 $sqlText = str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText);
40 return array('sql'=>$sqlText, 'parameters'=>$mappings);