@@ -4,30 +4,27 @@ class ApplicationRoute {
4
4
5
5
// change name for :id/:action
6
6
const dynamical_segment = "_dynamical_segment_ " ;
7
- public $ locals = [];
7
+
8
8
public $ path ;
9
9
public $ match_rule ;
10
10
public $ method ;
11
11
public $ rule ;
12
12
public $ controller ;
13
13
public $ action ;
14
14
15
- public function __construct ($ method , $ rule , $ target = false , $ path = null ) {
15
+ final public function __construct ($ method , $ rule , $ target = false , $ path = null ) { // genişletilemez fonksiyon
16
16
$ this ->path = ($ path ) ? $ path : "" ;
17
17
18
18
// Dinamik denetleyici tanımlaması mı ? :id/:action gibi
19
19
if (strpos ($ rule , ": " )) {
20
20
21
- if ($ target ) {
22
-
23
- // Ör.: get("/users/show/:id", "users#show"); // controller: users, action:show
21
+ if (!$ target )
22
+ throw new Exception ("Dinamik route özelliğinde hedef (controller#action) belirtilmek zorundadır! → " . $ rule );
24
23
25
- list ($ controller , $ action ) = self ::_spliter_struct ($ target , "# " );
26
- self ::set ($ method , $ this ->path . $ rule , $ this ->path . preg_replace ("|:[\w]+| " , self ::dynamical_segment, $ rule ), $ controller , $ action );
24
+ // Ör.: get("/users/show/:id", "users#show"); // controller: users, action:show
27
25
28
- } else {
29
- throw new Exception ("Dinamik route özelliğinde hedef (controller#action) belirtilmek zorundadır! → " . $ rule );
30
- }
26
+ list ($ controller , $ action ) = self ::_spliter_struct ($ target , "# " );
27
+ self ::set ($ method , $ this ->path . $ rule , $ this ->path . preg_replace ("|:[\w]+| " , self ::dynamical_segment, $ rule ), $ controller , $ action );
31
28
32
29
} elseif (strpos ($ rule , "/ " ) !== false ) {
33
30
@@ -53,6 +50,7 @@ public function __construct($method, $rule, $target = false, $path = null) {
53
50
}
54
51
}
55
52
53
+ // route şablon yapılarını, parçalama yapar
56
54
private static function _spliter_struct ($ subject , $ delimiter ) {
57
55
// düzenli karakterler için `\\` karakteri ile öncele
58
56
$ delimiter = "\\" . $ delimiter ;
@@ -61,7 +59,7 @@ private static function _spliter_struct($subject, $delimiter) {
61
59
return [$ rota [1 ], $ rota [2 ]];
62
60
}
63
61
64
- public function set ($ method , $ match_rule , $ rule , $ controller , $ action ) {
62
+ private function set ($ method , $ match_rule , $ rule , $ controller , $ action ) {
65
63
$ this ->method = strtoupper ($ method );
66
64
$ this ->match_rule = $ match_rule ;
67
65
$ this ->rule = $ rule ;
0 commit comments