PHP Класс 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
Показать файл
Открыть проект
Примеры использования класса
Открытые свойства
Открытые методы
Метод |
Описание |
|
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. |
|
Приватные методы
Метод |
Описание |
|
__construct ( string $config_name ) : WPDKConfig |
Create a WPDKConfig instance |
|
Описание методов
config()
статический публичный Метод
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 |
Результат |
WPDKConfig |
|
defaults()
публичный Метод
This is an override method
delta()
публичный статический Метод
Do a delta compare/combine from two tree object config
resetToDeafult()
публичный Метод
Reset the configuration to head and update
Update on database this configuration from root pointer.
Описание свойств
$class_name публичное свойство
public string $class_name |
Результат |
string |
|
$config_name публичное свойство
Unique name for this config
public string $config_name |
Результат |
string |
|