PHP Class WPDKConfig
## Overview
You rarely (never) instantiate WPDKConfig object directly. Instead, you instantiate subclasses of the
WPDKConfig class.
### Getting started
Write a your own custom class and extends WPDKConfig. For example:
class MySettings extends WPDKConfig {
}
You have to implement two methods. The first method is static:
class MySettings extends WPDKConfig {
const CONFIGURATION_NAME = 'mysetting-config';
static function config() {
$config = parent::config( self::CONFIGURATION_NAME, __CLASS__ );
return $config;
}
}
If you have sub branch, implements defaults() method to create these classes:
class MySettings extends WPDKConfig {
public $my_setting_branch;
static function config() {
$config = parent::config( self::CONFIGURATION_NAME, __CLASS__ );
return $config;
}
function defaults() {
$this->my_setting_branch = new MySettingsBranch();
}
}
class MySettingsBranch extends WPDKConfigBranch {
public $number_of_seat;
function __construct() {
$this->number_of_seat = 10; // Deafaul value
}
}
### Developing
When you are in develop your settings change and the store object on db could be different from last develop version.
So, just add a simple static method
doDelta() for merge and combine the last onfly version with stored version.
This method usually is called on activation of plugin. In this way you can align the configuration setting just
deactive and re active your plugin.
class MySettings extends WPDKConfig {
public $my_setting_branch;
static function config() {
$config = parent::config( self::CONFIGURATION_NAME, __CLASS__ );
return $config;
}
function defaults() {
$this->my_setting_branch = new MySettingsBranch();
}
static function doDelta() {
parent::delta( self::CONFIGURATION_NAME, __CLASS__ );
}
}
class MySettingsBranch extends WPDKConfigBranch {
public $number_of_seat;
function __construct() {
$this->number_of_seat = 10; // Deafaul value
}
}
### Reset to default
To reset to default all config use
MySettings::config()->resetToDefault();
### Reset to default a branch
To reset to default a single branch use
MySettings::config()->my_setting_branch->defaults();
MySettings::config()->update();
See WPDKConfigBranch class for detail
Mostra file
Open project: wpxtreme/wpdk
Class Usage Examples
Public Properties
Public Methods
Method |
Description |
|
config ( string $config_name, string $class_name ) : WPDKConfig |
Return an singleton instance of WPXtremeConfig subclass as specified in param inputs. This method create a
single instance of parent/subclasses named $class_name. |
|
defaults ( ) |
This is an override method |
|
delta ( string $config_name, string $class_name ) |
Do a delta compare/combine from two tree object config |
|
resetToDeafult ( ) |
Reset the configuration to head and update |
|
update ( ) |
Update on database this configuration from root pointer. |
|
Private Methods
Method |
Description |
|
__construct ( string $config_name ) : WPDKConfig |
Create a WPDKConfig instance |
|
Method Details
config()
static public method
Return an singleton instance of WPXtremeConfig subclass as specified in param inputs. This method create a
single instance of parent/subclasses named $class_name.
static public config ( string $config_name, string $class_name ) : WPDKConfig |
$config_name |
string |
Unique string id |
$class_name |
string |
Class name |
return |
WPDKConfig |
|
This is an override method
delta()
public static method
Do a delta compare/combine from two tree object config
resetToDeafult()
public method
Reset the configuration to head and update
Update on database this configuration from root pointer.
Property Details
$class_name public_oe property
public string $class_name |
return |
string |
|
$config_name public_oe property
Unique name for this config
public string $config_name |
return |
string |
|