Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
RestBaseController Class Reference

Abstract base class for Rest controllers. More...

+ Inheritance diagram for RestBaseController:

Public Member Functions

 __construct ()
 Constructor initialize $view variable.
 
 index ()
 Default action.
 
 isValid ($action)
 Returns True if access to the controller is allowed To be override in sub classes.
 
 onInvalidControl ()
 Called if isValid () returns false To be override in sub classes.
 
 connect ()
 Realize the connection to the server.
 
 initialize ()
 Method called before each action Can be override in derived class.
 
 finalize ()
 Method called after each action Can be override in derived class.
 
 _errorHandler ($e)
 
 _setResponseCode ($value)
 
 _get ($condition='1=1', $include=false, $useCache=false)
 Returns a list of objects from the server.
 
 _getAll ()
 Returns all the instances from the model $resource.
 
 _getOne ($keyValues, $include=false, $useCache=false)
 Get the first object corresponding to the $keyValues.
 
 _format ($arrayMessage)
 
 _getManyToOne ($ids, $member, $include=false, $useCache=false)
 
 _getOneToMany ($ids, $member, $include=false, $useCache=false)
 
 _getManyToMany ($ids, $member, $include=false, $useCache=false)
 
 _update (... $keyValues)
 Update an instance of $model selected by the primary key $keyValues Require members values in $_POST array.
 
 _add ()
 Insert a new instance of $model Require members values in $_POST array.
 
 _getRelationShip ($id, $member)
 Returns an associated member value(s).
 
 _delete (... $keyValues)
 Delete the instance of $model selected by the primary key $keyValues.
 
- Public Member Functions inherited from Controller
 loadView (string $viewName, $pData=null, bool $asString=false)
 Loads the view $viewName possibly passing the variables $pdata.
 
 loadDefaultView ($pData=null, bool $asString=false)
 Loads the default view (controllerName/actionName) possibly passing the variables $pdata.
 
 getDefaultViewName ()
 Returns the default view name for this controller/action i.e ControllerName/actionName.html for the action actionName in ControllerName If there is an activeTheme @activeTheme/ControllerName/actionName.html
 
 forward (string $controller, string $action='index', $params=[], bool $initialize=false, bool $finalize=false)
 Loads the controller $controller and calls its $action method by passing the parameters $params.
 
 redirectToRoute (string $routeName, $parameters=[], bool $initialize=false, bool $finalize=false)
 Redirect to a route by its name.
 
 getView ()
 Returns the associated view instance.
 
- Public Member Functions inherited from RestControllerUtilitiesTrait
 _validateInstance ($instance, $members, $excludedValidators=[])
 

Static Public Member Functions

static _getApiVersion ()
 
static _getTemplateFile ()
 Returns the template for creating this type of controller.
 

Protected Member Functions

 checkPermissions ($action, $datas=null)
 To override in derived classes.
 
 requireAuth ($action)
 Returns true if $action require an authentification with token.
 
 refreshToken ()
 Refresh an active token.
 
- Protected Member Functions inherited from RestControllerUtilitiesTrait
 getDatas ()
 
 getRequestParam ($param, $default)
 
 operate_ ($instance, $callback, $status, $exceptionMessage, $keyValues)
 
 generatePagination (&$filter, $pageNumber, $pageSize)
 
 updateOperation ($instance, $datas, $updateMany=false)
 
 addOperation ($instance, $datas, $insertMany=false)
 
 _getResponseFormatter ()
 
 getResponseFormatter ()
 To override, returns the active formatter for the response.
 
 _getRequestFormatter ()
 
 getRequestFormatter ()
 To override, returns the active formatter for the request.
 
 _getRestServer ()
 
 getRestServer ()
 To override, returns the active RestServer.
 
 _setValuesToObject ($instance, $values=[])
 Updates $instance with $values To eventually be redefined in derived classes.
 
 updateManyToOne ($manyToOneRelations, $members, $className, $instance, $values)
 
 getInclude ($include)
 
 addError ($code, $title, $detail=null, $source=null, $status=null)
 
 hasErrors ()
 
 displayErrors ()
 
 getAssociatedMemberValues_ ($ids, $getDatas, $member, $include=false, $useCache=false, $multiple=true)
 
 addViolation (ConstraintViolation $violation)
 
 getPrimaryKeysFromDatas ($datas, $model)
 
 getCondition ($condition)
 

Protected Attributes

 $config
 
 $model
 
 $contentType
 
 $restCache
 
 $useValidation = true
 
 $responseFormatter
 
 $requestFormatter
 
 $server
 
- Protected Attributes inherited from Controller
View $view
 
- Protected Attributes inherited from RestControllerUtilitiesTrait
 $errors
 

Detailed Description

Abstract base class for Rest controllers.

Ubiquity\controllers\rest$RestController This class is part of Ubiquity

Author
jcheron myadd.nosp@m.ress.nosp@m.mail@.nosp@m.gmai.nosp@m.l.com
Version
1.0.10

Definition at line 25 of file RestBaseController.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Constructor initialize $view variable.

Reimplemented from Controller.

Definition at line 50 of file RestBaseController.php.

Member Function Documentation

◆ _add()

_add ( )

Insert a new instance of $model Require members values in $_POST array.

Definition at line 278 of file RestBaseController.php.

◆ _delete()

_delete (   $keyValues)

Delete the instance of $model selected by the primary key $keyValues.

Parameters
array$keyValues

Definition at line 326 of file RestBaseController.php.

◆ _errorHandler()

_errorHandler (   $e)

Definition at line 138 of file RestBaseController.php.

◆ _format()

_format (   $arrayMessage)

Definition at line 210 of file RestBaseController.php.

◆ _get()

_get (   $condition = '1=1',
  $include = false,
  $useCache = false 
)

Returns a list of objects from the server.

Parameters
string$conditionthe sql Where part
boolean | string$includeif true, loads associate members with associations, if string, example : client.*,commands
boolean$useCache

Definition at line 154 of file RestBaseController.php.

◆ _getAll()

_getAll ( )

Returns all the instances from the model $resource.

Query parameters:

  • include: A string of associated members to load, comma separated (e.g. users,groups,organization...), or a boolean: true for all members, false for none (default: false).
  • filter: The filter to apply to the query (where part of an SQL query) (default: 1=1).
  • page[number]: The page to display (in this case, the page size is set to 1).
  • page[size]: The page size (count of instance per page) (default: 1).

Definition at line 175 of file RestBaseController.php.

◆ _getApiVersion()

static _getApiVersion ( )
static

Reimplemented in JsonRestController, and JsonApiRestController.

Definition at line 333 of file RestBaseController.php.

◆ _getManyToMany()

_getManyToMany (   $ids,
  $member,
  $include = false,
  $useCache = false 
)
Parameters
string$ids
string$member
string | boolean$includeif true, loads associate members with associations, if string, example : client.*,commands
boolean$useCache
Exceptions

Exception

Definition at line 249 of file RestBaseController.php.

◆ _getManyToOne()

_getManyToOne (   $ids,
  $member,
  $include = false,
  $useCache = false 
)
Parameters
string$ids
string$member
string | boolean$includeif true, loads associate members with associations, if string, example : client.*,commands
boolean$useCache

Definition at line 221 of file RestBaseController.php.

◆ _getOne()

_getOne (   $keyValues,
  $include = false,
  $useCache = false 
)

Get the first object corresponding to the $keyValues.

Parameters
string$keyValuesprimary key(s) value(s) or condition
boolean | string$includeif true, loads associate members with associations, if string, example : client.*,commands
boolean$useCacheif true then response is cached

Definition at line 195 of file RestBaseController.php.

◆ _getOneToMany()

_getOneToMany (   $ids,
  $member,
  $include = false,
  $useCache = false 
)
Parameters
string$ids
string$member
string | boolean$includeif true, loads associate members with associations, if string, example : client.*,commands
boolean$useCache
Exceptions

Exception

Definition at line 235 of file RestBaseController.php.

◆ _getRelationShip()

_getRelationShip (   $id,
  $member 
)

Returns an associated member value(s).

Query parameters:

  • include: A string of associated members to load, comma separated (e.g. users,groups,organization...), or a boolean: true for all members, false for none (default: true).
Parameters
string$idThe primary key value(s), if the primary key is composite, use a comma to separate the values (e.g. 1,115,AB)
string$memberThe member to load

Definition at line 303 of file RestBaseController.php.

◆ _getTemplateFile()

static _getTemplateFile ( )
static

Returns the template for creating this type of controller.

Returns
string

Reimplemented in JsonRestController, JsonApiRestController, and RestResourceController.

Definition at line 342 of file RestBaseController.php.

◆ _setResponseCode()

_setResponseCode (   $value)

Reimplemented from RestControllerUtilitiesTrait.

Definition at line 143 of file RestBaseController.php.

◆ _update()

_update (   $keyValues)

Update an instance of $model selected by the primary key $keyValues Require members values in $_POST array.

Parameters
array$keyValues

Definition at line 261 of file RestBaseController.php.

◆ checkPermissions()

checkPermissions (   $action,
  $datas = null 
)
protected

To override in derived classes.

Check if the datas in the authorization token allows access to the action. If the token is expired, this method is not used.

Parameters
$action
mixed$datasdatas in authorization token
Returns
bool

Definition at line 90 of file RestBaseController.php.

◆ connect()

connect ( )

Realize the connection to the server.

To override in derived classes to define your own authentication

Definition at line 115 of file RestBaseController.php.

◆ finalize()

finalize ( )

Method called after each action Can be override in derived class.

Reimplemented from Controller.

Definition at line 133 of file RestBaseController.php.

◆ index()

index ( )

Default action.

Reimplemented from Controller.

Definition at line 65 of file RestBaseController.php.

◆ initialize()

initialize ( )

Method called before each action Can be override in derived class.

Reimplemented from Controller.

Reimplemented in RestResourceController.

Definition at line 130 of file RestBaseController.php.

◆ isValid()

isValid (   $action)

Returns True if access to the controller is allowed To be override in sub classes.

Parameters
string$action
Returns
boolean

Reimplemented from Controller.

Definition at line 70 of file RestBaseController.php.

◆ onInvalidControl()

onInvalidControl ( )

Called if isValid () returns false To be override in sub classes.

Reimplemented from Controller.

Definition at line 107 of file RestBaseController.php.

◆ refreshToken()

refreshToken ( )
protected

Refresh an active token.

Exceptions

Ubiquity\exceptions\RestException

Definition at line 125 of file RestBaseController.php.

◆ requireAuth()

requireAuth (   $action)
protected

Returns true if $action require an authentification with token.

Parameters
string$action
Returns
boolean

Definition at line 100 of file RestBaseController.php.

Field Documentation

◆ $config

$config
protected

Definition at line 27 of file RestBaseController.php.

◆ $contentType

$contentType
protected

Definition at line 29 of file RestBaseController.php.

◆ $model

$model
protected

Definition at line 28 of file RestBaseController.php.

◆ $requestFormatter

$requestFormatter
protected

Definition at line 42 of file RestBaseController.php.

◆ $responseFormatter

$responseFormatter
protected

Definition at line 37 of file RestBaseController.php.

◆ $restCache

$restCache
protected

Definition at line 30 of file RestBaseController.php.

◆ $server

$server
protected

Definition at line 48 of file RestBaseController.php.

◆ $useValidation

$useValidation = true
protected

Definition at line 31 of file RestBaseController.php.


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