1 | <?php |
||
24 | class Collection implements IteratorAggregate |
||
25 | { |
||
26 | /** |
||
27 | * Contains all routes |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $routes = []; |
||
32 | |||
33 | /** |
||
34 | * Contains all routes |
||
35 | * |
||
36 | * @var \Kambo\Router\Route\Builder |
||
37 | */ |
||
38 | private $routeBuilder; |
||
39 | |||
40 | /** |
||
41 | * Route constructor |
||
42 | * |
||
43 | * @param \Kambo\Router\Route\Builder $routeBuilder Builder which will be used for creating |
||
44 | * instance of the route object. |
||
45 | */ |
||
46 | 50 | public function __construct(Builder $routeBuilder) |
|
50 | |||
51 | /** |
||
52 | * IteratorAggregate: returns the iterator object. |
||
53 | * |
||
54 | * @return ArrayIterator |
||
55 | */ |
||
56 | 46 | public function getIterator() : ArrayIterator |
|
60 | |||
61 | /** |
||
62 | * Add route matched with GET method. |
||
63 | * Shortcut for createRoute function with preset GET method. |
||
64 | * |
||
65 | * @param mixed $route route definition |
||
66 | * @param mixed $handler handler which will be executed if the url match |
||
67 | * the route |
||
68 | * |
||
69 | * @return \Kambo\Router\Route\Route Created route |
||
70 | */ |
||
71 | 35 | public function get(string $route, $handler) : Route |
|
75 | |||
76 | /** |
||
77 | * Add route matched with POST method. |
||
78 | * Shortcut for createRoute function with preset POST method. |
||
79 | * |
||
80 | * @param mixed $route route definition |
||
81 | * @param mixed $handler handler which will be executed if the url match |
||
82 | * the route |
||
83 | * |
||
84 | * @return \Kambo\Router\Route\Route Created route |
||
85 | */ |
||
86 | 3 | public function post(string $route, $handler) : Route |
|
90 | |||
91 | /** |
||
92 | * Add route matched with DELETE method. |
||
93 | * Shortcut for createRoute function with preset DELETE method. |
||
94 | * |
||
95 | * @param mixed $route route definition |
||
96 | * @param mixed $handler handler which will be executed if the url match |
||
97 | * the route |
||
98 | * |
||
99 | * @return \Kambo\Router\Route\Route Created route |
||
100 | */ |
||
101 | 1 | public function delete(string $route, $handler) : Route |
|
105 | |||
106 | /** |
||
107 | * Add route matched with PUT method. |
||
108 | * Shortcut for createRoute function with preset PUT method. |
||
109 | * |
||
110 | * @param mixed $route route definition |
||
111 | * @param mixed $handler handler which will be executed if the url match |
||
112 | * the route |
||
113 | * |
||
114 | * @return \Kambo\Router\Route\Route Created route |
||
115 | */ |
||
116 | 1 | public function put(string $route, $handler) : Route |
|
120 | |||
121 | /** |
||
122 | * Add route which will be matched to any method. |
||
123 | * Shortcut for createRoute function with preset ANY method. |
||
124 | * |
||
125 | * @param mixed $route route definition |
||
126 | * @param mixed $handler handler which will be executed if the url match |
||
127 | * the route |
||
128 | * |
||
129 | * @return \Kambo\Router\Route\Route Created route |
||
130 | */ |
||
131 | 3 | public function any(string $route, $handler) : Route |
|
135 | |||
136 | /** |
||
137 | * Create a route in the collection. |
||
138 | * The data structure used in the $handler depends on the used dispatcher. |
||
139 | * |
||
140 | * @param mixed $method HTTP method which will be used for binding |
||
141 | * @param mixed $route route definition |
||
142 | * @param mixed $handler handler which will be executed if the |
||
143 | * url matchs the route |
||
144 | * |
||
145 | * @return \Kambo\Router\Route\Route Created route |
||
146 | */ |
||
147 | 42 | public function createRoute(string $method, string $route, $handler) : Route |
|
154 | |||
155 | /** |
||
156 | * Add a route to the collection. |
||
157 | * |
||
158 | * @param Kambo\Router\Route\Route $route route which will be added into |
||
159 | * collection |
||
160 | * |
||
161 | * @return self for fluent interface |
||
162 | */ |
||
163 | 1 | public function addRoute(Route $route) : Collection |
|
169 | } |
||
170 |