@@ -13,11 +13,6 @@ class Route
1313 */
1414 protected $ name ;
1515
16- /**
17- * @var array<string>
18- */
19- protected $ controller = [];
20-
2116 /**
2217 * @var string
2318 */
@@ -26,13 +21,18 @@ class Route
2621 /**
2722 * @var array<string>
2823 */
29- protected $ vars = [];
24+ protected $ controller = [];
3025
3126 /**
3227 * @var array<string>
3328 */
3429 protected $ methods = [];
3530
31+ /**
32+ * @var array<string>
33+ */
34+ protected $ vars = [];
35+
3636 public function __construct (string $ name , string $ path , array $ controller , array $ methods = ['GET ' , 'POST ' ])
3737 {
3838 $ this ->name = $ name ;
@@ -41,16 +41,11 @@ public function __construct(string $name, string $path, array $controller, array
4141 $ this ->methods = $ methods ;
4242 }
4343
44- public function hasVars (): bool
45- {
46- return $ this ->getVarsNames () !== [];
47- }
48-
4944 public function match (string $ path , string $ method ): bool
5045 {
5146 if (
5247 in_array ($ method , $ this ->getMethods ()) &&
53- preg_match ('#^ ' . $ this ->generateRegex () . '$#sD ' , $ this -> trimPath ($ path ), $ matches )
48+ preg_match ('#^ ' . $ this ->generateRegex () . '$#sD ' , self :: trimPath ($ path ), $ matches )
5449 ) {
5550
5651 $ values = array_filter ($ matches , function ($ key ) {
@@ -77,12 +72,6 @@ public function getPath(): string
7772 return $ this ->path ;
7873 }
7974
80- public function addVar (string $ key , string $ value ): self
81- {
82- $ this ->vars [$ key ] = $ value ;
83- return $ this ;
84- }
85-
8675 public function getController (): array
8776 {
8877 return $ this ->controller ;
@@ -104,11 +93,6 @@ public function getMethods(): array
10493 return $ this ->methods ;
10594 }
10695
107- private function trimPath (string $ path ): string
108- {
109- return '/ ' . rtrim (ltrim (trim ($ path ), '/ ' ), '/ ' );
110- }
111-
11296 private function generateRegex (): string
11397 {
11498 $ regex = $ this ->path ;
@@ -118,4 +102,20 @@ private function generateRegex(): string
118102 }
119103 return $ regex ;
120104 }
105+
106+ public function hasVars (): bool
107+ {
108+ return $ this ->getVarsNames () !== [];
109+ }
110+
111+ public function addVar (string $ key , string $ value ): self
112+ {
113+ $ this ->vars [$ key ] = $ value ;
114+ return $ this ;
115+ }
116+
117+ private static function trimPath (string $ path ): string
118+ {
119+ return '/ ' . rtrim (ltrim (trim ($ path ), '/ ' ), '/ ' );
120+ }
121121}
0 commit comments