ResourcePresenter
extends BaseResource
in package
An extendable controller to help provide a UI for a resource.
Tags
Table of Contents
Properties
- $forceHTTPS : int
- Should enforce HTTPS access for all methods in this controller.
- $helpers : array<int, string>
- Helpers that will be automatically loaded on class instantiation.
- $logger : LoggerInterface
- Instance of logger to use.
- $model : object|null
- $modelName : string|null
- $request : CLIRequest|IncomingRequest
- Instance of the main Request object.
- $response : ResponseInterface
- Instance of the main response object.
- $validator : ValidationInterface|null
- Once validation has been run, will hold the Validation instance.
Methods
- create() : ResponseInterface|string|void
- Process the creation/insertion of a new resource object.
- delete() : ResponseInterface|string|void
- Process the deletion of a specific resource object
- edit() : ResponseInterface|string|void
- Present a view to edit the properties of a specific resource object
- index() : ResponseInterface|string|void
- Present a view of resource objects
- initController() : void
- Constructor.
- new() : ResponseInterface|string|void
- Present a view to present a new single resource object
- remove() : ResponseInterface|string|void
- Present a view to confirm the deletion of a specific resource object
- setModel() : void
- Set or change the model this controller is bound to.
- show() : ResponseInterface|string|void
- Present a view to present a specific resource object
- update() : ResponseInterface|string|void
- Process the updating, full or partial, of a specific resource object.
- cachePage() : void
- How long to cache the current page for.
- forceHTTPS() : void
- A convenience method to use when you need to ensure that a single method is reached only via HTTPS. If it isn't, then a redirect will happen back to this method and HSTS header will be sent to have modern browsers transform requests automatically.
- validate() : bool
- A shortcut to performing validation on Request data.
- validateData() : bool
- A shortcut to performing validation on any input data.
- setValidator() : void
Properties
$forceHTTPS
Should enforce HTTPS access for all methods in this controller.
protected
int
$forceHTTPS
= 0
Number of seconds to set HSTS header
$helpers
Helpers that will be automatically loaded on class instantiation.
protected
array<int, string>
$helpers
= []
$logger
Instance of logger to use.
protected
LoggerInterface
$logger
$model
protected
object|null
$model
The model that holding this resource's data
$modelName
protected
string|null
$modelName
The model that holding this resource's data
$request
Instance of the main Request object.
protected
CLIRequest|IncomingRequest
$request
$response
Instance of the main response object.
protected
ResponseInterface
$response
$validator
Once validation has been run, will hold the Validation instance.
protected
ValidationInterface|null
$validator
Methods
create()
Process the creation/insertion of a new resource object.
public
create() : ResponseInterface|string|void
This should be a POST.
Return values
ResponseInterface|string|voiddelete()
Process the deletion of a specific resource object
public
delete([int|string|null $id = null ]) : ResponseInterface|string|void
Parameters
- $id : int|string|null = null
Return values
ResponseInterface|string|voidedit()
Present a view to edit the properties of a specific resource object
public
edit([int|string|null $id = null ]) : ResponseInterface|string|void
Parameters
- $id : int|string|null = null
Return values
ResponseInterface|string|voidindex()
Present a view of resource objects
public
index() : ResponseInterface|string|void
Return values
ResponseInterface|string|voidinitController()
Constructor.
public
initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) : void
Parameters
- $request : RequestInterface
- $response : ResponseInterface
- $logger : LoggerInterface
new()
Present a view to present a new single resource object
public
new() : ResponseInterface|string|void
Return values
ResponseInterface|string|voidremove()
Present a view to confirm the deletion of a specific resource object
public
remove([int|string|null $id = null ]) : ResponseInterface|string|void
Parameters
- $id : int|string|null = null
Return values
ResponseInterface|string|voidsetModel()
Set or change the model this controller is bound to.
public
setModel([object|string|null $which = null ]) : void
Given either the name or the object, determine the other.
Parameters
- $which : object|string|null = null
show()
Present a view to present a specific resource object
public
show([int|string|null $id = null ]) : ResponseInterface|string|void
Parameters
- $id : int|string|null = null
Return values
ResponseInterface|string|voidupdate()
Process the updating, full or partial, of a specific resource object.
public
update([int|string|null $id = null ]) : ResponseInterface|string|void
This should be a POST.
Parameters
- $id : int|string|null = null
Return values
ResponseInterface|string|voidcachePage()
How long to cache the current page for.
protected
cachePage(int $time) : void
Parameters
- $time : int
Tags
forceHTTPS()
A convenience method to use when you need to ensure that a single method is reached only via HTTPS. If it isn't, then a redirect will happen back to this method and HSTS header will be sent to have modern browsers transform requests automatically.
protected
forceHTTPS([int $duration = 31536000 ]) : void
Parameters
- $duration : int = 31536000
-
The number of seconds this link should be considered secure for. Only with HSTS header. Default value is 1 year.
Tags
validate()
A shortcut to performing validation on Request data.
protected
validate(array<string|int, mixed>|string $rules[, array<string|int, mixed> $messages = [] ]) : bool
Parameters
- $rules : array<string|int, mixed>|string
- $messages : array<string|int, mixed> = []
-
An array of custom error messages
Return values
boolvalidateData()
A shortcut to performing validation on any input data.
protected
validateData(array<string|int, mixed> $data, array<string|int, mixed>|string $rules[, array<string|int, mixed> $messages = [] ][, string|null $dbGroup = null ]) : bool
Parameters
- $data : array<string|int, mixed>
-
The data to validate
- $rules : array<string|int, mixed>|string
- $messages : array<string|int, mixed> = []
-
An array of custom error messages
- $dbGroup : string|null = null
-
The database group to use
Return values
boolsetValidator()
private
setValidator(array<string|int, mixed>|string $rules, array<string|int, mixed> $messages) : void
Parameters
- $rules : array<string|int, mixed>|string
- $messages : array<string|int, mixed>