Skip to content

Commit da426cc

Browse files
committed
Make url params case sensitive
1 parent b5370a0 commit da426cc

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

Diff for: src/Router.php

+8-15
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function exists(): bool {
3737
protected ?int $version;
3838
protected ?\Swoole\Http\Request $request;
3939
protected function __construct(string $uri, string $method, ?int $version) {
40-
$action = explode('/', strtolower($uri));
40+
$action = explode('/', $uri);
4141
array_shift($action);
4242
if ('' === end($action)) {
4343
array_pop($action);
@@ -64,7 +64,7 @@ public function getControllerName(): string {
6464
return $this->controller_name;
6565
}
6666
public function isWebhook(): bool {
67-
$action1 = reset($this->action);
67+
$action1 = strtolower(reset($this->action));
6868
return 'webhook' === $action1 || 'server' === $action1 || 'service' === $action1;
6969
}
7070
public function getHost(): string {
@@ -92,7 +92,7 @@ public function getController(\Swoole\Http\Response $response): Controller {
9292
$par = [];
9393
$action = $this->action;
9494
do {
95-
$controller_name = '/' . implode('/', $action);
95+
$controller_name = '/' . strtolower(implode('/', $action));
9696
$cache_key = self::getCacheKey($controller_name, $this->method, $this->version, count($par));
9797
if (array_key_exists($cache_key, self::$cache)) {
9898
$classname = self::$cache[$cache_key];
@@ -113,31 +113,24 @@ public function getController(\Swoole\Http\Response $response): Controller {
113113
$par[] = array_pop($action);
114114
continue;
115115
}
116-
$tmp = $action;
117-
$tmp[] = $this->method . $v;
118-
$classname = '\\Controller\\' . implode('\\', $tmp);
116+
$classname = '\\Controller\\' . strtolower(implode('\\', $action)) . '\\' . $this->method . $v;
119117
$class_exists = class_exists($classname, false);
120118
if (! $class_exists) {
121-
$file_name = Environment::getDir()->controller . implode('/', $tmp) . '.php';
119+
$file_name = Environment::getDir()->controller . strtolower(implode('/', $action)) . '/' .
120+
$this->method . $v . '.php';
122121
if (file_exists($file_name)) {
123122
require_once $file_name;
124123
$class_exists = class_exists($classname, false);
125124
}
126125
}
127-
if (! $class_exists) {
128-
if (empty($action)) {
129-
break;
130-
}
131-
$par[] = array_pop($action);
132-
continue;
133-
} elseif ((! empty($par) && ! $classname::WITH_PAR)) {
126+
if ((! $class_exists) || (! empty($par) && ! $classname::WITH_PAR)) {
134127
if (empty($action)) {
135128
break;
136129
}
137130
$par[] = array_pop($action);
138131
continue;
139132
}
140-
$controller_name = '/' . implode('/', $action);
133+
$controller_name = '/' . strtolower(implode('/', $action));
141134
$this->controller_name = $controller_name;
142135
if ($classname::USE_ROUTER_CACHE) {
143136
$cache_key = self::getCacheKey($controller_name, $this->method, $this->version, count($par));

0 commit comments

Comments
 (0)