Skip to content

Commit 19e40b9

Browse files
authored
Merge pull request #534 from flightphp/alias-bug
fixed bug with root alias
2 parents a3541a1 + 4c60454 commit 19e40b9

4 files changed

Lines changed: 33 additions & 24 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"test-coverage": "rm clover.xml && XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage --coverage-clover=clover.xml && vendor/bin/coverage-check clover.xml 100",
5959
"lint": "phpstan --no-progress -cphpstan.neon",
6060
"beautify": "phpcbf --standard=phpcs.xml",
61-
"phpcs": "phpcs --standard=phpcs.xml"
61+
"phpcs": "phpcs --standard=phpcs.xml -n"
6262
},
6363
"suggest": {
6464
"latte/latte": "Latte template engine",

flight/database/PdoWrapper.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,36 +106,36 @@ public function fetchAll(string $sql, array $params = []): array
106106
protected function processInStatementSql(string $sql, array $params = []): array
107107
{
108108
// Replace "IN(?)" with "IN(?,?,?)"
109-
$sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql);
109+
$sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql);
110110

111-
$current_index = 0;
112-
while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) {
113-
$preceeding_count = substr_count($sql, '?', 0, $current_index - 1);
111+
$current_index = 0;
112+
while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) {
113+
$preceeding_count = substr_count($sql, '?', 0, $current_index - 1);
114114

115-
$param = $params[$preceeding_count];
116-
$question_marks = '?';
115+
$param = $params[$preceeding_count];
116+
$question_marks = '?';
117117

118-
if (is_string($param) || is_array($param)) {
119-
$params_to_use = $param;
120-
if (is_string($param)) {
121-
$params_to_use = explode(',', $param);
122-
}
118+
if (is_string($param) || is_array($param)) {
119+
$params_to_use = $param;
120+
if (is_string($param)) {
121+
$params_to_use = explode(',', $param);
122+
}
123123

124-
foreach ($params_to_use as $key => $value) {
125-
if (is_string($value)) {
126-
$params_to_use[$key] = trim($value);
124+
foreach ($params_to_use as $key => $value) {
125+
if (is_string($value)) {
126+
$params_to_use[$key] = trim($value);
127+
}
127128
}
128-
}
129129

130-
$question_marks = join(',', array_fill(0, count($params_to_use), '?'));
131-
$sql = substr_replace($sql, $question_marks, $current_index + 3, 1);
130+
$question_marks = join(',', array_fill(0, count($params_to_use), '?'));
131+
$sql = substr_replace($sql, $question_marks, $current_index + 3, 1);
132132

133-
array_splice($params, $preceeding_count, 1, $params_to_use);
134-
}
133+
array_splice($params, $preceeding_count, 1, $params_to_use);
134+
}
135135

136-
$current_index += strlen($question_marks) + 4;
137-
}
136+
$current_index += strlen($question_marks) + 4;
137+
}
138138

139-
return [ 'sql' => $sql, 'params' => $params ];
139+
return [ 'sql' => $sql, 'params' => $params ];
140140
}
141141
}

flight/net/Route.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ public function hydrateUrl(array $params = []): string
192192
// catches potential optional parameter
193193
$url = str_replace('(/', '/', $url);
194194
// trim any trailing slashes
195-
$url = rtrim($url, '/');
195+
if ($url !== '/') {
196+
$url = rtrim($url, '/');
197+
}
196198
return $url;
197199
}
198200

tests/RouterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ public function testRewindAndValid()
533533
$this->assertTrue($result);
534534
}
535535

536+
public function testGetRootUrlByAlias()
537+
{
538+
$this->router->map('/', [$this, 'ok'], false, 'path1');
539+
$url = $this->router->getUrlByAlias('path1');
540+
$this->assertEquals('/', $url);
541+
}
542+
536543
public function testGetUrlByAliasNoMatches()
537544
{
538545
$this->router->map('/path1', [$this, 'ok'], false, 'path1');

0 commit comments

Comments
 (0)