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
Deprecation: Since 0.6.2 - Use WPDKConfiguration instead
Author: =undo= ([email protected])
Datei anzeigen Open project: wpxtreme/wpdk Class Usage Examples

Public Properties

Property Type Description
$class_name string External Class name
$config_name string Unique name for this config

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

defaults() public method

This is an override method
public defaults ( )

delta() public static method

Do a delta compare/combine from two tree object config
public static delta ( string $config_name, string $class_name )
$config_name string Unique string id
$class_name string Class name

resetToDeafult() public method

Reset the configuration to head and update
public resetToDeafult ( )

update() public method

Update on database this configuration from root pointer.
public update ( )

Property Details

$class_name public_oe property

External Class name
public string $class_name
return string

$config_name public_oe property

Unique name for this config
public string $config_name
return string