* @link http://www.pradosoft.com/ * @copyright Copyright © 2005-2013 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id: TSimpleDynamicParser.php 3245 2013-01-07 20:23:32Z ctrlaltca $ * @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 * @version $Id: TSimpleDynamicParser.php 3245 2013-01-07 20:23:32Z ctrlaltca $ * @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); } }