summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/Configuration/TSimpleDynamicParser.php
blob: e58d8af837b018ad8810bbc5e779744c4c26e8e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

class TSimpleDynamicParser
{
	private $PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/';
	
	const DYNAMIC_TOKEN = '`!`';
	
	public function parse($sqlMap, $statement, $sqlText, $scope)
	{
		$matches = array();
		$mappings = array();
		preg_match_all($this->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);
	}	
}

?>