| 1 | <?php |
||
| 9 | class CRouteBasic |
||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Properties |
||
| 14 | * |
||
| 15 | */ |
||
| 16 | private $name; // A name for this route |
||
| 17 | private $rule; // The rule for this route |
||
| 18 | private $action; // The controller action to handle this route |
||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | /** |
||
| 23 | * Set values for route. |
||
| 24 | * |
||
| 25 | * @param string $rule for this route |
||
| 26 | * @param callable $action callable to implement a controller for the route |
||
| 27 | * |
||
| 28 | * @return $this |
||
| 29 | */ |
||
| 30 | public function set($rule, $action) |
||
| 31 | { |
||
| 32 | $this->rule = $rule; |
||
| 33 | $this->action = $action; |
||
| 34 | |||
| 35 | return $this; |
||
| 36 | } |
||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * Check if the route matches a query |
||
| 42 | * |
||
| 43 | * @param string $query to match against |
||
| 44 | * |
||
| 45 | * @return boolean true if query matches the route |
||
| 46 | */ |
||
| 47 | public function match($query) |
||
| 48 | { |
||
| 49 | if ($this->rule === $query) { |
||
| 50 | return true; |
||
| 51 | } |
||
| 52 | return false; |
||
| 53 | } |
||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | /** |
||
| 58 | * Handle the action for the route. |
||
| 59 | * |
||
| 60 | * @return mixed |
||
| 61 | */ |
||
| 62 | public function handle() |
||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * Set the name of the route. |
||
| 71 | * |
||
| 72 | * @param string $name set a name for the route |
||
| 73 | * |
||
| 74 | * @return $this |
||
| 75 | */ |
||
| 76 | public function setName($name) |
||
| 77 | { |
||
| 78 | $this->name = $name; |
||
| 79 | return $this; |
||
| 80 | } |
||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | /** |
||
| 85 | * Get the rule for the route. |
||
| 86 | * |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | public function getRule() |
||
| 93 | } |
||
| 94 |