Class \Prado\Util\TDbParameterModule
This loads application parameters from a database. It adds the TMapLazyLoadBehavior to Application Parameters when the setAutoLoadField is set. The key and name fields, table, autoload field, and autoload values (both true and false values) are parameterized. Set them to your application specific values.
The following will load the options from a WordPress Database:
<module id="dbparams" class="Prado\Util\TDbParameterModule"
ConnectionID="DB" KeyField="option_name" ValueField="option_value" TableName="wp_options" Serializer="php"
autoLoadField="autoload" autoLoadValue="'yes'" autoLoadValueFalse="'no'"/>
This allows for setting and removal of application parameters into and from the database through set and remove, respectively. Arrays and Objects are serialized. The specific serializer can be chose to be 'php', 'json', or provide your own function or callable. Default to 'php'.
setting setSerializer to your own function that has the following format:
function mySerializerFunction($data, $encode) {...}
If $encode is true, then encode, otherwise decode, to text.
When getCaptureParameterChanges is true, the default, then this will route any changes to the Application Parameters after TPageService::onPreRunPage back to the TDbParameterModule and be saved to the database. This captures any changes when done by the page or user. These changes are restored when this module is loaded again.
When TPermissionsManager is a module in your app, there is one permission to control user access to its function:
- TDbParameterModule::PERM_PARAM_SHELL 'param_shell' enables the shell command to index, get and set database parameters.
The role and rule management functions only work when the TDbParameter Module is specified. The following gives user "admin" and all users with "Administrators" role the permission to access permissions shell and its full functionality:
<permissionrule name="param_shell" action="allow" users="admin" />
<permissionrule name="param_shell" action="allow" roles="Administrators" />
Class hierarchy
- \Prado\Util\TDbParameterModule implements IDbModule, IPermissions
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 4.2.0
public
|
attachParameterStorage(object $sender, null|mixed $param) : mixed
This attaches the TMapRouteBehavior on the Parameters.
|
public
|
attachTPageServiceHandler(object $sender, mixed $param) : mixed
TApplication::onBeginRequest Handler that adds {@see attachTPageBehaviors} to
TPageService::onPreRunPage. In turn, this attaches {@see attachTPageBehaviors}
to TPageService to then adds the page behaviors.
|
public
|
|
public
|
get(string $key[, bool $checkParameter = true ][, bool $setParameter = true ]) : mixed
Gets a specific parameter parameters into application.
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
set(string $key, mixed $value[, bool $autoLoad = true ][, mixed $setParameter = true ]) : mixed
Sets a parameter in the database and the Application Parameter.
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
setConnectionID(string $value) : mixed
Sets the ID of a TDataSourceConfig module.
The datasource module will be used to establish the DB connection that will be used by the user manager. |
public
|
setFromBehavior(string $key, mixed $value) : mixed
Sets a parameter in the database and the Application Parameter.
from changes to the Parameter through a TMapRouteBehavior. |
public
|
|
public
|
setSerializer(callable|string $value) : mixed
Serializer sets the type of serialization of objects and arrays in parameters
to and from the database. 'php' uses serialze and unserialize. 'json' uses
json_encode and json_decade. or you can provide your own callable to serialized
and unserialize objects and arrays.
|
public
|
|
public
|
|
protected
|
createDbConnection(string $connectionID) : TDbConnection
Creates the DB connection. If no ConnectionID is set, this creates a
sqlite3 database in the RuntimePath "sqlite3.params". If the
{@see getAutoLoadField} is not set, the default, then the autoLoadField
is set to "autoload" to enable the feature by default.
|
protected
|
|
protected
|
ensureTable() : mixed
checks for the table, and if not there and autoCreate, then creates the table else throw error.
|
protected
|
public
mixed
|
APP_PARAMETER_LAZY_BEHAVIOR
The name of the Application Parameter Lazy Load Behavior
|
'lazyTDbParameter'
|
public
mixed
|
APP_PARAMETER_SET_BEHAVIOR
The name of the Application Parameter Lazy Load Behavior
|
'setTDbParameter'
|
public
mixed
|
PERM_PARAM_SHELL
The permission for the cron shell
|
'param_shell'
|
public
mixed
|
SERIALIZE_JSON
|
'json'
|
public
mixed
|
SERIALIZE_PHP
|
'php'
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |