/**
* @param string $method : GET / POST / PUT / DELETE...
* @param string $endpoint
* @param string $callable
* @param string $name
* @param boolean $needToken
* @param array $needRole
* @param array $params
* @param array $bodies
* @return Route
*/
public function add($method, $endpoint, $callable, $name = null, $needToken = null, $needRole = [], $params = [], $bodies = [])
Parameters of this function :
Num |
Param name |
Description |
Example |
Require |
1 |
Method / Type |
The type of the route like GET, POST, PUT, DELETE... |
$router->add("POST", ...) |
Yes |
2 |
Endpoint |
The endpoint of the route |
$router->add(..., "/users", ...) |
Yes |
3 |
Callable |
The name of the controller followed by a slash and method (function) name |
$router->add(..., "User#getAll", ...) |
Yes |
4 |
Name |
The name / title of the route which will be in the documentation |
$router->add(..., "Get list of Users", ...) |
Yes |
5 |
Need token |
If the user require a token to call the route |
$router->add(..., true, ...) |
No |
6 |
Need role |
The role(s) required to call the route |
$router->add(..., [">" => 2, "<=" => 4], ...) |
No |
7 |
Parameters |
The parameters in the URL |
$router->add(..., ["id" => Int], ...) |
No |
8 |
Bodies |
The body sent by POST, PUT... |
$router->add(..., ["*password" => "String"], ...) |
No |
$router->add('GET', '/users', "User#getAll", "Get all User");
$router->add('POST', '/users', "User#add", "Add a new User", true, [
'>' => 2,
'<=' => 5
], [], [
'*email' => '',
'*password' => 'String',
'name' => 'String',
'age' => 'Int',
]);
$router->add('PUT', '/users/:id', "User#edit", "Edit a User", true, [], [
'id' => 'Int'
]);
$router->add('DELETE', '/users/:id', "User#delete", "Delete a User", true, [], [
'id' => 'Int'
]);
$router->group('/users', function (Group $group) {
$group->add('GET', '/:slug-:id', "User#index", "Just index", true, [], [
'slug' => 'String'
]);
}, null, [], [ // Params of routes in this group
'id' => 'Int',
]);