Controllers - aPisC/phroper GitHub Wiki

Controllers are inherited from Phroper/Controller class.

Custom controllers have to be defined in Controllers namespace, and the requests to /api/:controller/ url will be redirected to the specified controller, for example a request to /api/auth/login will be handled by the Auth.php file in the Controllers namespace. Controller has an internal router and can redirect all incoming request by sub-urls and request methods.

Registering handlers

registerHandler($url, $handler= null, $method = 'GET', $priority = 0)

This function will register a handler function to the internal router. If the handler is null, it will be replaced with the function of controller that has the same name as the $url parameter. In the handler function you have to take care of response sending. Controller will automatically test if the user has permission for the registered handler.

registerJsonHandler($url, $handler= null, $method = 'GET', $priority = 0)

This functioin will register a handler just like the registerHandler function, but the return values and exceptions of the handler will be sent as JSON.

Permission handling

The controller will test if the user has permission to the registered handler before executing it. The prermission name is auto-generated from the request metdhod, the controller name and the url. For example to use the list/:id url of the AuthUser controller with GET method, the user needs to have get.auth-user.list.:id permission.

The list of all available route permissions can be listed with te getAvailablePermissions function.