-
Notifications
You must be signed in to change notification settings - Fork 175
Hook English
cayman edited this page Jun 14, 2016
·
3 revisions
-
The implement of a hook is the same as API
/** * @path("/") hook for / */ class HookAuth { /** * @route({"*","/"}) * @param({"token", "$._COOKIE.token"}) * @param({"user", "$._cur_user"}) */ function fetchAppName($token, &$user){ $user = $this->getUserByToken($token); } }
-
Put hook class file in your-project-dir/apis/hooks
-
config phprs\Router
{ "phprs\\Router": { "properties": { "hooks":["HookAuth"] } } }
-
More info
-
Hook is called before api, by order of config, if route matched.
-
Reqeust can be modified in hook too, such as
$._GET, $ ._POST. -
Hook can be breaked, which means the follow api will not be called. Use:
@return({"break", 1})
or@return({"break", $is_break})
-