diff --git a/Parser.php b/Parser.php index 2558b39..62303b3 100644 --- a/Parser.php +++ b/Parser.php @@ -233,13 +233,22 @@ private function replaceComment($comment, $queryInComment, $paramName) */ private function getParam($name) { - $name = mb_strtolower(ltrim($name, ':')); + $name = $outName = mb_strtolower(ltrim($name, ':')); + + // Формируем имя параметра на выход точно такое же, какое и забиндено в парметры. + foreach ($this->params as $key => $value) { + if (mb_strtolower($key) == $name) { + $outName = $key; + break; + } + } + $params = array_change_key_case($this->params, CASE_LOWER); if (array_key_exists($name, $params)) { - return [$name, $params[$name]]; + return [$outName, $params[$name]]; } elseif (array_key_exists(':' . $name, $params)) { - return [$name, $params[':' . $name]]; + return [$outName, $params[':' . $name]]; } return false; diff --git a/tests/SqlParserTest.php b/tests/SqlParserTest.php index 0ac443c..c41f46a 100644 --- a/tests/SqlParserTest.php +++ b/tests/SqlParserTest.php @@ -20,6 +20,7 @@ public function sqlData() --*param17 case-insensitive2 --*PARAM18 case-insensitive3 /*param19 :@param19*/ + /*param20 :@param20*/ '; return [ @@ -32,14 +33,15 @@ public function sqlData() [$query, ['param8' => 'v8', 'param9' => 'v9', 'param10' => 'v10'], '/^\s*sql10\s*$/'], ["sql1\n\n\n\n\nsql2", ['param1' => 'v1'], '/^sql1\nsql2$/'], ["sql1", [], '/^sql1$/'], - ["-- test\n".$query, [], '/^-- test$/'], + ["-- test\n" . $query, [], '/^-- test$/'], [$query, ['param11' => [['v1', 'v2']]], "/^:param11_0,:param11_1$/"], ["--*param order by param", ['param' => ['v1', 'bind' => 'text']], "/^order by v1$/"], [$query, ['param12' => 'test'], "/^test multiple$/"], [$query, ['param14' => 'test'], "/^test multiple$/"], [$query, ['PARAM17' => 'test'], "/^case-insensitive2$/"], [$query, ['PARAM18' => 'test'], "/^case-insensitive3$/"], - [$query, ['PARAM19' => [[1, 2]]], "/^:param19_0,:param19_1$/"], + [$query, ['PARAM19' => [[1, 2]]], "/^:PARAM19_0,:PARAM19_1$/"], + [$query, ['PARAM20' => ['bind' => 'tuple', [[1], [2]]]], "/^\(:PARAM20_0_0\),\(:PARAM20_1_0\)$/"], ]; } @@ -56,11 +58,20 @@ public function paramsData() return [ [[], []], [[':simpleName' => 'simpleValue'], [':simpleName' => 'simpleValue']], - [[':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]], [':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]]], - [[':complexNameSimpleValue' => ['simpleValue', 'bind' => true]], [':complexNameSimpleValue' => 'simpleValue']], + [ + [':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]], + [':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]] + ], + [ + [':complexNameSimpleValue' => ['simpleValue', 'bind' => true]], + [':complexNameSimpleValue' => 'simpleValue'] + ], [[':complexNameBindText' => ['simpleValue', 'bind' => 'text']], []], [[':complexNameNoBind' => ['bind' => false]], []], - [['arrayName' => [[0, 1, 2, 3]]], [':arrayName_0' => 0, ':arrayName_1' => 1, ':arrayName_2' => 2, ':arrayName_3' => 3]], + [ + ['arrayName' => [[0, 1, 2, 3]]], + [':arrayName_0' => 0, ':arrayName_1' => 1, ':arrayName_2' => 2, ':arrayName_3' => 3] + ], ]; }