Skip to content

Commit

Permalink
Регистронезависимое раскоментирование переменных fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kikimor committed Jul 3, 2018
1 parent 1882f51 commit 3f073e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
15 changes: 12 additions & 3 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 16 additions & 5 deletions tests/SqlParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function sqlData()
--*param17 case-insensitive2
--*PARAM18 case-insensitive3
/*param19 :@param19*/
/*param20 :@param20*/
';

return [
Expand All @@ -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\)$/"],
];
}

Expand All @@ -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]
],
];
}

Expand Down

0 comments on commit 3f073e8

Please sign in to comment.