PHP Class FOF30\Model\Model

A generic MVC model implementation
Mostrar archivo Open project: akeeba/fof Class Usage Examples

Protected Properties

Property Type Description
$_ignoreRequest boolean Should we ignore request data when trying to get state data not already set in the Model?
$_savestate boolean Should I save the model's state in the session?
$_state_set boolean Are the state variables already set?
$container FOF30\Container\Container The container attached to the model
$name string The model (base) name
$state string A state object

Public Methods

Method Description
__call ( string $name, mixed $arguments ) : static Magic caller; allows to use the name of model state keys as methods to set their values.
__construct ( Container $container, array $config = [] ) Public class constructor
__get ( string $name ) : static Magic getter; allows to use the name of model state keys as properties. Also handles magic properties: $this->input mapped to $this->container->input
__set ( string $name, mixed $value ) : static Magic setter; allows to use the name of model state keys as properties
clearState ( ) : static Clears the model state, but doesn't touch the internal lists of records, record tables or record id variables. To clear these values, please use reset().
getClone ( ) Clones the model object and returns the clone
getContainer ( ) : Container Returns a reference to the model's container
getHash ( ) : string Returns a unique hash for each view, used to prefix the state variables to allow us to retrieve them from the state later on.
getIgnoreRequest ( ) : boolean Gets the ignore request flag. When false, getState() will try to populate state variables not already set from same-named state variables in the request.
getName ( ) : string Method to get the model name
getState ( string $key = null, mixed $default = null, string $filter_type = 'raw' ) : mixed Get a filtered state variable
populateSavestate ( ) : static Public setter for the _savestate variable. Set it to true to save the state of the Model in the session.
savestate ( boolean $newState ) : static Sets the model state auto-save status. By default the model is set up to save its state to the session.
setIgnoreRequest ( boolean $ignoreRequest ) Sets the ignore request flag. When false, getState() will try to populate state variables not already set from same-named state variables in the request.
setState ( string $property, mixed $value = null ) : mixed Method to set model state variables
tmpInstance ( ) Returns a temporary instance of the model. Please note that this returns a _clone_ of the model object, not the original object. The new object is set up to not save its stats, ignore the request when getting state variables and comes with an empty state.

Protected Methods

Method Description
populateState ( ) : void Method to auto-populate the model state.
triggerEvent ( string $event, array $arguments = [] ) : void Triggers an object-specific event. The event runs both locally –if a suitable method exists– and through the object's behaviours dispatcher and Joomla! plugin system. Neither handler is expected to return anything (return values are ignored). If you want to mark an error and cancel the event you have to raise an exception.

Private Methods

Method Description
internal_getState ( string $property = null, mixed $default = null ) : object Method to get model state variables

Method Details

__call() public method

Magic caller; allows to use the name of model state keys as methods to set their values.
public __call ( string $name, mixed $arguments ) : static
$name string The state variable key
$arguments mixed The state variable contents
return static

__construct() public method

You can use the $config array to pass some configuration values to the object: state stdClass|array. The state variables of the Model. use_populate Boolean. When true the model will set its state from populateState() instead of the request. ignore_request Boolean. When true getState will not automatically load state data from the request.
public __construct ( Container $container, array $config = [] )
$container FOF30\Container\Container The configuration variables to this model
$config array Configuration values for this model

__get() public method

Magic getter; allows to use the name of model state keys as properties. Also handles magic properties: $this->input mapped to $this->container->input
public __get ( string $name ) : static
$name string The state variable key
return static

__set() public method

Magic setter; allows to use the name of model state keys as properties
public __set ( string $name, mixed $value ) : static
$name string The state variable key
$value mixed The state variable value
return static

clearState() public method

Clears the model state, but doesn't touch the internal lists of records, record tables or record id variables. To clear these values, please use reset().
public clearState ( ) : static
return static

getClone() public method

Clones the model object and returns the clone
public getClone ( )

getContainer() public method

Returns a reference to the model's container
public getContainer ( ) : Container
return FOF30\Container\Container

getHash() public method

Returns a unique hash for each view, used to prefix the state variables to allow us to retrieve them from the state later on.
public getHash ( ) : string
return string

getIgnoreRequest() public method

Gets the ignore request flag. When false, getState() will try to populate state variables not already set from same-named state variables in the request.
public getIgnoreRequest ( ) : boolean
return boolean

getName() public method

The model name. By default parsed using the classname or it can be set by passing a $config['name'] in the class constructor
public getName ( ) : string
return string The name of the model

getState() public method

Get a filtered state variable
public getState ( string $key = null, mixed $default = null, string $filter_type = 'raw' ) : mixed
$key string The state variable's name
$default mixed The default value to return if it's not already set
$filter_type string The filter type to use
return mixed The state variable's contents

populateSavestate() public method

Public setter for the _savestate variable. Set it to true to save the state of the Model in the session.
public populateSavestate ( ) : static
return static

populateState() protected method

This method should only be called once per instantiation and is designed to be called on the first call to the getState() method unless the model configuration flag to ignore the request is set.
protected populateState ( ) : void
return void

savestate() public method

Sets the model state auto-save status. By default the model is set up to save its state to the session.
public savestate ( boolean $newState ) : static
$newState boolean True to save the state, false to not save it.
return static

setIgnoreRequest() public method

Sets the ignore request flag. When false, getState() will try to populate state variables not already set from same-named state variables in the request.
public setIgnoreRequest ( boolean $ignoreRequest )
$ignoreRequest boolean

setState() public method

Method to set model state variables
public setState ( string $property, mixed $value = null ) : mixed
$property string The name of the property.
$value mixed The value of the property to set or null.
return mixed The previous value of the property or null if not set.

tmpInstance() public method

Returns a temporary instance of the model. Please note that this returns a _clone_ of the model object, not the original object. The new object is set up to not save its stats, ignore the request when getting state variables and comes with an empty state.
public tmpInstance ( )

triggerEvent() protected method

EXAMPLE Component: com_foobar, Object name: item, Event: onBeforeSomething, Arguments: array(123, 456) The event calls: 1. $this->onBeforeSomething(123, 456) 2. $his->behavioursDispatcher->trigger('onBeforeSomething', array(&$this, 123, 456)) 3. Joomla! plugin event onComFoobarModelItemBeforeSomething($this, 123, 456)
protected triggerEvent ( string $event, array $arguments = [] ) : void
$event string The name of the event, typically named onPredicateVerb e.g. onBeforeKick
$arguments array The arguments to pass to the event handlers
return void

Property Details

$_ignoreRequest protected_oe property

Should we ignore request data when trying to get state data not already set in the Model?
protected bool $_ignoreRequest
return boolean

$_savestate protected_oe property

Should I save the model's state in the session?
protected bool $_savestate
return boolean

$_state_set protected_oe property

Are the state variables already set?
protected bool $_state_set
return boolean

$container protected_oe property

The container attached to the model
protected Container,FOF30\Container $container
return FOF30\Container\Container

$name protected_oe property

The model (base) name
protected string $name
return string

$state protected_oe property

A state object
protected string $state
return string