ARouter  0.1.0
Annotation based router for your projects
Argument resolvers

Argument resolvers are designed to map data from incoming Request to controller method parameters using annotations.

Cookie argument resolver

CookieValue Annotation allows to bind cookie value to method parameter.

You can see how method parameter $user is assigned to a $_COOKIE['user'] in next example:

@CookieValue (for="user")
public function sayHello($user) {}

If the name of cookie is different from argument name (e.g. $_COOKIE['user_value']) use next syntax:

@CookieValue (for="user", from="user_value")
public function sayHello($user) {}

Request body resolver

RequestBody annotation allows to bind a method parameter to the body of web request.

You can see how method parameter $json is assigned to a JSON web request body in next example:

@RequestBody (for="json")
public function something($json) { $decoded_json = json_decode($json); }

Request header resolver

RequestHeader annotation allows to bind a method parameter to the request header.

You can see how method parameter $userAgent is assigned to a 'User-Agent' header in next example:

@RequestHeader (for="userAgent", from="User-Agent")
public function something($userAgent) {}

Request parameter resolver

RequestParam annotation allows to bind a method parameter to a web request parameter.

You can see how method parameter $page is assigned to a request parameter from 'example.com/list?page=2' URL in next example:

@RequestParam (for="page")
public function list($page) { print "Current page is $page" }

If the name of request parameter is different from method parameter name (example.com/list?pageNum=2) you can use next syntax:

@RequestParam (for="page", from = "pageNum")
public function list($page) { print "Current page is $page" }

If request parameter is a file you should typehint method parameter with UploadedFileInterface interface.

Session attribute resolver

SessionAttribute annotation allows to bind a session attribute to method parameter.

You can see how method parameter $user is assigned to a $_SESSION['user'] in next example:

@SessionAttribute (for="user")
public function sayHello($user) {}

If the name of session attribute is different from parameter name (e.g. $_SESSION['user_value']) use next syntax:

@SessionAttribute (for="user", from="user_value")
public function sayHello($user) {}

Request object resolver

Method parameter of 'RequestInterface' type like

public function hello(RequestInterface $r){}

will be resolved to incoming HTTP Request object.