44
55namespace DevCoder ;
66
7+ use DevCoder \Traits \RouteTrait ;
8+
79/**
810 * Class Route
911 * @package DevCoder
1012 */
1113final class Route
1214{
15+ use RouteTrait;
16+
1317 /**
1418 * @var string
1519 */
@@ -21,9 +25,9 @@ final class Route
2125 private $ path ;
2226
2327 /**
24- * @var array<string>
28+ * @var mixed
2529 */
26- private $ parameters = [] ;
30+ private $ handler ;
2731
2832 /**
2933 * @var array<string>
@@ -33,27 +37,27 @@ final class Route
3337 /**
3438 * @var array<string>
3539 */
36- private $ vars = [];
40+ private $ attributes = [];
3741
3842 /**
3943 * Route constructor.
4044 * @param string $name
4145 * @param string $path
42- * @param array $parameters
43- * $parameters = [
46+ * @param mixed $handler
47+ * $handler = [
4448 * 0 => (string) Controller name : HomeController::class.
4549 * 1 => (string|null) Method name or null if invoke method
4650 * ]
4751 * @param array $methods
4852 */
49- public function __construct (string $ name , string $ path , array $ parameters , array $ methods = ['GET ' ])
53+ public function __construct (string $ name , string $ path , $ handler , array $ methods = ['GET ' ])
5054 {
5155 if ($ methods === []) {
5256 throw new \InvalidArgumentException ('HTTP methods argument was empty; must contain at least one method ' );
5357 }
5458 $ this ->name = $ name ;
5559 $ this ->path = $ path ;
56- $ this ->parameters = $ parameters ;
60+ $ this ->handler = $ handler ;
5761 $ this ->methods = $ methods ;
5862 }
5963
@@ -70,7 +74,7 @@ public function match(string $path, string $method): bool
7074 return is_string ($ key );
7175 }, ARRAY_FILTER_USE_KEY );
7276 foreach ($ values as $ key => $ value ) {
73- $ this ->vars [$ key ] = $ value ;
77+ $ this ->attributes [$ key ] = $ value ;
7478 }
7579 return true ;
7680 }
@@ -87,9 +91,17 @@ public function getPath(): string
8791 return $ this ->path ;
8892 }
8993
90- public function getParameters (): array
94+ /**
95+ * @deprecated use getHandler()
96+ */
97+ public function getParameters ()
98+ {
99+ return $ this ->getHandler ();
100+ }
101+
102+ public function getHandler ()
91103 {
92- return $ this ->parameters ;
104+ return $ this ->handler ;
93105 }
94106
95107 public function getMethods (): array
@@ -103,13 +115,32 @@ public function getVarsNames(): array
103115 return reset ($ matches ) ?? [];
104116 }
105117
118+ /**
119+ * @deprecated use hasAttributes()
120+ */
106121 public function hasVars (): bool
122+ {
123+ return $ this ->hasAttributes ();
124+ }
125+
126+ public function hasAttributes (): bool
107127 {
108128 return $ this ->getVarsNames () !== [];
109129 }
110130
131+ /**
132+ * @deprecated use getAttributes()
133+ */
111134 public function getVars (): array
112135 {
113- return $ this ->vars ;
136+ return $ this ->getAttributes ();
137+ }
138+
139+ /**
140+ * @return array<string>
141+ */
142+ public function getAttributes (): array
143+ {
144+ return $ this ->attributes ;
114145 }
115146}
0 commit comments