pull/534/head
Austin Collier 1 year ago
parent aaf6a44a2c
commit 4c60454fa0

@ -58,7 +58,7 @@
"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", "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",
"lint": "phpstan --no-progress -cphpstan.neon", "lint": "phpstan --no-progress -cphpstan.neon",
"beautify": "phpcbf --standard=phpcs.xml", "beautify": "phpcbf --standard=phpcs.xml",
"phpcs": "phpcs --standard=phpcs.xml" "phpcs": "phpcs --standard=phpcs.xml -n"
}, },
"suggest": { "suggest": {
"latte/latte": "Latte template engine", "latte/latte": "Latte template engine",

@ -106,36 +106,36 @@ class PdoWrapper extends PDO
protected function processInStatementSql(string $sql, array $params = []): array protected function processInStatementSql(string $sql, array $params = []): array
{ {
// Replace "IN(?)" with "IN(?,?,?)" // Replace "IN(?)" with "IN(?,?,?)"
$sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql); $sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql);
$current_index = 0; $current_index = 0;
while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) { while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) {
$preceeding_count = substr_count($sql, '?', 0, $current_index - 1); $preceeding_count = substr_count($sql, '?', 0, $current_index - 1);
$param = $params[$preceeding_count]; $param = $params[$preceeding_count];
$question_marks = '?'; $question_marks = '?';
if (is_string($param) || is_array($param)) { if (is_string($param) || is_array($param)) {
$params_to_use = $param; $params_to_use = $param;
if (is_string($param)) { if (is_string($param)) {
$params_to_use = explode(',', $param); $params_to_use = explode(',', $param);
} }
foreach ($params_to_use as $key => $value) { foreach ($params_to_use as $key => $value) {
if (is_string($value)) { if (is_string($value)) {
$params_to_use[$key] = trim($value); $params_to_use[$key] = trim($value);
}
} }
}
$question_marks = join(',', array_fill(0, count($params_to_use), '?')); $question_marks = join(',', array_fill(0, count($params_to_use), '?'));
$sql = substr_replace($sql, $question_marks, $current_index + 3, 1); $sql = substr_replace($sql, $question_marks, $current_index + 3, 1);
array_splice($params, $preceeding_count, 1, $params_to_use); array_splice($params, $preceeding_count, 1, $params_to_use);
} }
$current_index += strlen($question_marks) + 4; $current_index += strlen($question_marks) + 4;
} }
return [ 'sql' => $sql, 'params' => $params ]; return [ 'sql' => $sql, 'params' => $params ];
} }
} }

@ -192,9 +192,9 @@ class Route
// catches potential optional parameter // catches potential optional parameter
$url = str_replace('(/', '/', $url); $url = str_replace('(/', '/', $url);
// trim any trailing slashes // trim any trailing slashes
if($url !== '/') { if ($url !== '/') {
$url = rtrim($url, '/'); $url = rtrim($url, '/');
} }
return $url; return $url;
} }

@ -533,7 +533,7 @@ class RouterTest extends TestCase
$this->assertTrue($result); $this->assertTrue($result);
} }
public function testGetRootUrlByAlias() public function testGetRootUrlByAlias()
{ {
$this->router->map('/', [$this, 'ok'], false, 'path1'); $this->router->map('/', [$this, 'ok'], false, 'path1');
$url = $this->router->getUrlByAlias('path1'); $url = $this->router->getUrlByAlias('path1');

Loading…
Cancel
Save