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
파일 보기
프로젝트 열기: wpxtreme/wpdk
1 사용 예제들
공개 프로퍼티들
공개 메소드들
메소드 |
설명 |
|
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. |
|
비공개 메소드들
메소드 상세
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 |
|
This is an override method
Do a delta compare/combine from two tree object config
Reset the configuration to head and update
Update on database this configuration from root pointer.
프로퍼티 상세
public string $class_name |
리턴 |
string |
|
Unique name for this config
public string $config_name |
리턴 |
string |
|