Skip to content
cayman edited this page Jun 14, 2016 · 3 revisions
  1. 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);
         }
    }
  2. Put hook class file in your-project-dir/apis/hooks

  3. config phprs\Router

    {
    "phprs\\Router": {
        "properties": {
            "hooks":["HookAuth"] 
        } 
    }
    }
  4. More info

    1. Hook is called before api, by order of config, if route matched.

    2. Reqeust can be modified in hook too, such as $._GET, $._POST.

    3. Hook can be breaked, which means the follow api will not be called. Use:

      @return({"break", 1})or @return({"break", $is_break})

Clone this wiki locally