Skip to content

Commit 287855a

Browse files
committed
allow with parameter to take any type of data
1 parent 312a2d6 commit 287855a

File tree

3 files changed

+80
-30
lines changed

3 files changed

+80
-30
lines changed

src/Route.php

+78-28
Original file line numberDiff line numberDiff line change
@@ -39,84 +39,134 @@
3939

4040
/**
4141
* @param array<string, string> $where
42-
* @param array<string, string> $with
42+
* @param array<string, mixed> $with
4343
*/
44-
public static function get(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
45-
{
44+
public static function get(
45+
string $path,
46+
mixed $callback,
47+
array $where = [],
48+
array $with = [],
49+
?string $name = null
50+
): RouteElement {
4651
return new RouteElement(self::GET, $path, $callback, $where, $with, $name);
4752
}
4853

4954
/**
5055
* @param array<string, string> $where
51-
* @param array<string, string> $with
56+
* @param array<string, mixed> $with
5257
*/
53-
public static function post(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
54-
{
58+
public static function post(
59+
string $path,
60+
mixed $callback,
61+
array $where = [],
62+
array $with = [],
63+
?string $name = null
64+
): RouteElement {
5565
return new RouteElement(self::POST, $path, $callback, $where, $with, $name);
5666
}
5767

5868
/**
5969
* @param array<string, string> $where
60-
* @param array<string, string> $with
70+
* @param array<string, mixed> $with
6171
*/
62-
public static function put(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
63-
{
72+
public static function put(
73+
string $path,
74+
mixed $callback,
75+
array $where = [],
76+
array $with = [],
77+
?string $name = null
78+
): RouteElement {
6479
return new RouteElement(self::PUT, $path, $callback, $where, $with, $name);
6580
}
6681

6782
/**
6883
* @param array<string, string> $where
69-
* @param array<string, string> $with
84+
* @param array<string, mixed> $with
7085
*/
71-
public static function patch(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
72-
{
86+
public static function patch(
87+
string $path,
88+
mixed $callback,
89+
array $where = [],
90+
array $with = [],
91+
?string $name = null
92+
): RouteElement {
7393
return new RouteElement(self::PATCH, $path, $callback, $where, $with, $name);
7494
}
7595

7696
/**
7797
* @param array<string, string> $where
78-
* @param array<string, string> $with
98+
* @param array<string, mixed> $with
7999
*/
80-
public static function delete(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
81-
{
100+
public static function delete(
101+
string $path,
102+
mixed $callback,
103+
array $where = [],
104+
array $with = [],
105+
?string $name = null
106+
): RouteElement {
82107
return new RouteElement(self::DELETE, $path, $callback, $where, $with, $name);
83108
}
84109

85110
/**
86111
* @param array<string, string> $where
87-
* @param array<string, string> $with
112+
* @param array<string, mixed> $with
88113
*/
89-
public static function head(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
90-
{
114+
public static function head(
115+
string $path,
116+
mixed $callback,
117+
array $where = [],
118+
array $with = [],
119+
?string $name = null
120+
): RouteElement {
91121
return new RouteElement(self::HEAD, $path, $callback, $where, $with, $name);
92122
}
93123

94124
/**
95125
* @param array<string, string> $where
96-
* @param array<string, string> $with
126+
* @param array<string, mixed> $with
97127
*/
98-
public static function options(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
99-
{
128+
public static function options(
129+
string $path,
130+
mixed $callback,
131+
array $where = [],
132+
array $with = [],
133+
?string $name = null
134+
): RouteElement {
100135
return new RouteElement(self::OPTIONS, $path, $callback, $where, $with, $name);
101136
}
102137

103138
/**
104139
* @param array<string, string> $where
105-
* @param array<string, string> $with
140+
* @param array<string, mixed> $with
106141
*/
107-
public static function any(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
108-
{
142+
public static function any(
143+
string $path,
144+
mixed $callback,
145+
array $where = [],
146+
array $with = [],
147+
?string $name = null
148+
): RouteElement {
109149
return new RouteElement(self::ANY, $path, $callback, $where, $with, $name);
110150
}
111151

112152
/**
113153
* @param string[] $methods
114154
* @param array<string, string> $where
115-
* @param array<string, string> $with
155+
* @param array<string, mixed> $with
116156
*/
117-
public static function some(array $methods, string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
118-
{
119-
$method = array_reduce($methods, static fn($carry, $methodString): int => $carry | self::METHODS[strtoupper($methodString)], 0);
157+
public static function some(
158+
array $methods,
159+
string $path,
160+
mixed $callback,
161+
array $where = [],
162+
array $with = [],
163+
?string $name = null
164+
): RouteElement {
165+
$method = array_reduce(
166+
$methods,
167+
static fn($carry, $methodString): int => $carry | self::METHODS[strtoupper($methodString)],
168+
0
169+
);
120170

121171
return new RouteElement($method, $path, $callback, $where, $with, $name);
122172
}

src/Route/RouteElement.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
/**
3939
* @param array<string, string> $where
40-
* @param array<string, string> $with
40+
* @param array<string, mixed> $with
4141
*/
4242
public function __construct(
4343
public int $method,

src/RouteGroup.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class RouteGroup
1818
* @param mixed[] $middlewares
1919
* @param mixed[] $conditions
2020
* @param array<string, string> $where
21-
* @param array<string, string> $with
21+
* @param array<string, mixed> $with
2222
*/
2323
public function __construct(
2424
array $routes,

0 commit comments

Comments
 (0)