pclib  3.3.0
Lightweight PHP framework
ApiController Class Reference

Controller for the application REST API with bearer authorisation, post/get methods, returning json. More...

Inheritance diagram for ApiController:
Controller BaseObject

Public Member Functions

 run ($action)
 Call action method of the controller, feeding it with required parameters. More...
 
 getToken ()
 Return authorisation token from request Authorization header. More...
 
 error ($message, $httpStatus=500,... $args)
 Exit with http status code and json message. More...
 
- Public Member Functions inherited from Controller
 init ()
 Called before every action. More...
 
 action ($rs)
 Call route $rs and return result of the controller's action. More...
 
 template ($path, $data=[])
 Create template $path, populated with $data. More...
 
 redirect ($route)
 Redirect to $route.
 
 model ($tableName, $id=null)
 Return model for table $tableName.
 
 selection ($from=null)
 Return orm\Selection class.
 
 authorize ($perm='')
 Check if user has permission $perm. More...
 
 outputJson (array $data, $code='')
 Output json data and exit. More...
 
- Public Member Functions inherited from BaseObject
 loadDefaults ($className=null)
 Load default parameters of class $className into object instance.
 
 setProperties (array $defaults)
 Set public properties of object from the array. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $publicMethods = []
 List of public methods. More...
 
 $publicApi = false
 Set if whole controller is public - do not use athorisation.
 
- Data Fields inherited from Controller
 $name
 Name of the controller without postfix.
 
 $action
 Name of the called action without postfix.
 
 $authorizeRedirect = 'user/signin'
 authorize() fallback when user is not logged in.
 
 $allowDashInAction = true
 Convert url action some-thing into someThingAction() call.
 
- Data Fields inherited from BaseObject
 $serviceLocator
 var function() Return service object when requested with service().
 

Protected Attributes

 $token
 var system\AuthToken
 
 $request
 var Request
 
- Protected Attributes inherited from Controller
 $app
 var App Link to application
 
 $ACTION_POSTFIX = 'Action'
 Each action method name must have following postfix. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults (... $args)
 Set or retireve default parameters of the object. More...
 
- Protected Member Functions inherited from BaseObject
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Detailed Description

Controller for the application REST API with bearer authorisation, post/get methods, returning json.

Create your REST controllers as ancestors of ApiController.

See also
App::run()
AuthToken

Member Function Documentation

◆ error()

error (   $message,
  $httpStatus = 500,
  $args 
)

Exit with http status code and json message.

Parameters
string$message
int$httpStatus

Reimplemented from Controller.

◆ getToken()

getToken ( )

Return authorisation token from request Authorization header.

Returns
string $token

◆ run()

run (   $action)

Call action method of the controller, feeding it with required parameters.

Parameters
Action$actioncalled action.

Reimplemented from Controller.

Field Documentation

◆ $publicMethods

$publicMethods = []

List of public methods.

Non-public methods without valid token will be rejected.


The documentation for this class was generated from the following file: