Skip to content

Commit 291740d

Browse files
author
Gökhan Demir
authored
Update ApplicationRoute.php
1 parent fc2d8df commit 291740d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Diff for: lib/ApplicationRoute.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,27 @@ class ApplicationRoute {
44

55
// change name for :id/:action
66
const dynamical_segment = "_dynamical_segment_";
7-
public $locals = [];
7+
88
public $path;
99
public $match_rule;
1010
public $method;
1111
public $rule;
1212
public $controller;
1313
public $action;
1414

15-
public function __construct($method, $rule, $target = false, $path = null) {
15+
final public function __construct($method, $rule, $target = false, $path = null) { // genişletilemez fonksiyon
1616
$this->path = ($path) ? $path : "";
1717

1818
// Dinamik denetleyici tanımlaması mı ? :id/:action gibi
1919
if (strpos($rule, ":")) {
2020

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);
2423

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
2725

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);
3128

3229
} elseif (strpos($rule, "/") !== false) {
3330

@@ -53,6 +50,7 @@ public function __construct($method, $rule, $target = false, $path = null) {
5350
}
5451
}
5552

53+
// route şablon yapılarını, parçalama yapar
5654
private static function _spliter_struct($subject, $delimiter) {
5755
// düzenli karakterler için `\\` karakteri ile öncele
5856
$delimiter = "\\" . $delimiter;
@@ -61,7 +59,7 @@ private static function _spliter_struct($subject, $delimiter) {
6159
return [$rota[1], $rota[2]];
6260
}
6361

64-
public function set($method, $match_rule, $rule, $controller, $action) {
62+
private function set($method, $match_rule, $rule, $controller, $action) {
6563
$this->method = strtoupper($method);
6664
$this->match_rule = $match_rule;
6765
$this->rule = $rule;

0 commit comments

Comments
 (0)