Skip to content

Commit

Permalink
tidy: dynamic injection
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Aug 15, 2023
1 parent 8fd2602 commit 725ddba
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Query/SqlQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class SqlQuery extends Query {
];

/** @param array<string, mixed>|array<mixed> $bindings */
public function getSql(array $bindings = []):string {
public function getSql(array &$bindings = []):string {
$sql = file_get_contents($this->getFilePath());
return $this->injectSpecialBindings(
$sql = $this->injectDynamicBindings(
$sql,
$bindings
);
$sql = $this->injectSpecialBindings(
$sql,
$bindings
);
return $sql;
}

/** @param array<string, mixed>|array<mixed> $bindings */
Expand Down Expand Up @@ -117,12 +122,13 @@ public function injectSpecialBindings(
return $sql;
}

/** @param array<string, string|array<string, string>> $data */
public function injectDynamicBindings(string $sql, array &$data):string {
$sql = $this->injectDynamicBindingsValueSet($sql, $data);
$sql = $this->injectDynamicIn($sql, $data);
return $sql;
return $this->injectDynamicIn($sql, $data);
}

/** @param array<string, string|array<string, string>> $data */
private function injectDynamicBindingsValueSet(string $sql, array &$data):string {
$pattern = '/\(\s*:__dynamicValueSet\s\)/';
if(!preg_match($pattern, $sql, $matches)) {
Expand Down Expand Up @@ -164,6 +170,7 @@ private function injectDynamicBindingsValueSet(string $sql, array &$data):string
return str_replace($matches[0], $replacementString, $sql);
}

/** @param array<string, string|array<string, string>> $data */
private function injectDynamicIn(string $sql, array &$data):string {
$pattern = '/\(\s*:__dynamicIn\s\)/';
if(!preg_match($pattern, $sql, $matches)) {
Expand Down

0 comments on commit 725ddba

Please sign in to comment.