@@ -43,84 +43,41 @@ class Route implements RouteInterface, RouteFactoryInterface
4343 * @param string $method
4444 * @param callable $callback
4545 */
46- public function __construct ($ pattern , $ method , callable $ callback )
46+ public function __construct ($ pattern , string $ method , callable $ callback )
4747 {
48- $ this ->assertString ($ pattern , 'pattern ' );
49- $ this ->assertString ($ method , 'method ' );
48+ $ this ->assertStringOrObject ($ pattern , 'pattern ' );
5049
5150 $ this ->pattern = $ this ->normalizePattern ($ pattern );
5251 $ this ->method = strtoupper ($ method );
5352 $ this ->callback = $ callback ;
5453 $ this ->parameters = ParameterType::extractParameterTypesFromPattern ($ this ->pattern );
5554 }
5655
57- /**
58- * Creates a new Route with the given pattern and callback for the method GET
59- *
60- * @param string $pattern
61- * @param callable $callback
62- * @return static
63- */
64- public static function get ($ pattern , callable $ callback ): \Cundd \Rest \Router \Route
56+ public static function get ($ pattern , callable $ callback ): Route
6557 {
6658 return new static ($ pattern , 'GET ' , $ callback );
6759 }
6860
69- /**
70- * Creates a new Route with the given pattern and callback for the method POST
71- *
72- * @param string $pattern
73- * @param callable $callback
74- * @return static
75- */
7661 public static function post ($ pattern , callable $ callback ): Route
7762 {
7863 return new static ($ pattern , 'POST ' , $ callback );
7964 }
8065
81- /**
82- * Creates a new Route with the given pattern and callback for the method PUT
83- *
84- * @param string $pattern
85- * @param callable $callback
86- * @return static
87- */
8866 public static function put ($ pattern , callable $ callback ): Route
8967 {
9068 return new static ($ pattern , 'PUT ' , $ callback );
9169 }
9270
93- /**
94- * Creates a new Route with the given pattern and callback for the method DELETE
95- *
96- * @param string $pattern
97- * @param callable $callback
98- * @return static
99- */
10071 public static function delete ($ pattern , callable $ callback ): Route
10172 {
10273 return new static ($ pattern , 'DELETE ' , $ callback );
10374 }
10475
105- /**
106- * Creates a new Route with the given pattern and callback for the method OPTIONS
107- *
108- * @param string $pattern
109- * @param callable $callback
110- * @return static
111- */
11276 public static function options ($ pattern , callable $ callback ): Route
11377 {
11478 return new static ($ pattern , 'OPTIONS ' , $ callback );
11579 }
11680
117- /**
118- * Creates a new Route with the given pattern and callback for the method PATCH
119- *
120- * @param string $pattern
121- * @param callable $callback
122- * @return static
123- */
12481 public static function patch ($ pattern , callable $ callback ): Route
12582 {
12683 return new static ($ pattern , 'PATCH ' , $ callback );
@@ -228,7 +185,7 @@ public function getPriority()
228185 * @param mixed $input
229186 * @param string $argumentName
230187 */
231- private function assertString ($ input , $ argumentName )
188+ private function assertStringOrObject ($ input , $ argumentName )
232189 {
233190 if (!is_string ($ input ) && !(is_object ($ input ) && method_exists ($ input , '__toString ' ))) {
234191 throw InvalidArgumentException::buildException ($ input , 'string ' , $ argumentName );
@@ -238,10 +195,10 @@ private function assertString($input, $argumentName)
238195 /**
239196 * Normalize the path pattern
240197 *
241- * @param string $inputPattern
198+ * @param string|ResourceType $inputPattern
242199 * @return string
243200 */
244- private function normalizePattern ($ inputPattern )
201+ private function normalizePattern ($ inputPattern ): string
245202 {
246203 $ pattern = '/ ' . ltrim ((string )$ inputPattern , '/ ' );
247204 $ patternParts = explode ('/ ' , $ pattern );
0 commit comments