PHP Class Xpressengine\Config\ConfigManager

### app binding : xe.config 로 바인딩 되어 있음 XeConfig Facade 로 접근 가능 ### 등록 php XeConfig::add('head.child', ['key1' => 'val1', 'key2' => 'val2']); 또는 XeConfig::set('head.child', ['key1' => 'val1', 'key2' => 'val2']); ### 반환 config 정보를 객체의 반환, 특정 키에대한 값의 반환 두가지 를 지원 합니다. php 객체 반환 $config = XeConfig::get('head.child'); 값의 반환 $val = XeConfig::getVal('head.child.key1'); 특정 키에 값이 설정되어있지 않은경우 반환 받고 싶은 값이 있다면 두번째 인자에 포함시키면 됩니다. $val = XeConfig::getVal('head.child.key1', 'default'); 객체 반환시 만일 존재 하지 않는 경우 부모를 참조하는 객체로 반환 받을 수 있습니다. php 'head.child' 의 값을 참조 $config = XeConfig::getOrNew('head.child.unknown'); ### 수정 패키지에서는 몇가지 형태의 수정방식을 제공합니다. php 지정된 키에 해당하는 값만 수정 XeConfig::set('head.child', ['key2' => 'new value']); 전체에 대한 수정 (다음과 같은 경우 'key2' 를 제외한 모든 값이 사라집니다.) XeConfig::put('head.child', ['key2' => 'new value']); 객체에 의한 수정 XeConfig::modify($config); 수정시 자손에 해당 하는 모든 하위 노드의 값도 일괄적으로 수정할 수 있습니다. php XeConfig::set('head.child', ['key2' => 'new value'], true); 필터를 작성하면 true 인 경우에 해당하는 자손만 수정 됩니다. XeConfig::set('head.child', ['key2' => 'new value'], true, function ($config) { return substr($config->name, 0, 4) != 'desc'; }); #### 객체의 사용 ConfigEntity 객채는 배열 처럼 사용 가능합니다. php $val = $config['key']; loop foreach ($config as $key => $val) { do something }
Author: XE Developers ([email protected])
Mostrar archivo Open project: xpressengine/xpressengine Class Usage Examples

Protected Properties

Property Type Description
$closures array closure list
$repo Xpressengine\Config\ConfigRepository repository instance
$validator Validator validator instance

Public Methods

Method Description
__construct ( Xpressengine\Config\ConfigRepository $repo, Validator $validator ) constructor
add ( string $group, array $collection, string $siteKey = 'default' ) : ConfigEntity create new config
children ( ConfigEntity $config ) : array get next level configs
get ( string $group, boolean $create = false, string $siteKey = 'default' ) : ConfigEntity returns config object by target name
getOrNew ( string $group, string $siteKey = 'default' ) : ConfigEntity if not exists, create new entity object by target name
getPureVal ( string $key, mixed $default = null, string $siteKey = 'default' ) : mixed returns config pure value
getVal ( string $key, mixed $default = null, boolean $pure = false, string $siteKey = 'default' ) : mixed returns config value
modify ( ConfigEntity $config ) : ConfigEntity modify config information
move ( ConfigEntity $config, string | null $to = null ) : ConfigEntity Move entity hierarchy to new parent or root
put ( string $group, array $collection, boolean $toDesc = false, callable $filter = null, string $siteKey = 'default' ) : ConfigEntity config change
remove ( ConfigEntity $config ) : void remove config
removeByName ( string $name, string $siteKey = 'default' ) : void remove config by group name
set ( string $group, array $collection, boolean $toDesc = false, callable $filter = null, string $siteKey = 'default' ) : ConfigEntity multiple set config values
setVal ( string $key, mixed $value, boolean $toDesc = false, callable $filter = null, string $siteKey = 'default' ) : void set config value

Protected Methods

Method Description
bindClosure ( ConfigEntity &$config ) : void binding registered closure to config
build ( ConfigEntity $config ) : ConfigEntity build config object
convey ( ConfigEntity $config, callable $filter = null, array $items = null ) : void convey to descendants
share ( ConfigEntity $config, string $item, mixed $value ) : ConfigEntity shared when closure value
validating ( ConfigEntity $config ) : void validation config

Private Methods

Method Description
parseKey ( string $key ) : array parse a key into group and item
setAncestors ( ConfigEntity $config ) : ConfigEntity ancestors setter
sort ( array $configs, string $flag = 'asc' ) : array sort list

Method Details

__construct() public method

constructor
public __construct ( Xpressengine\Config\ConfigRepository $repo, Validator $validator )
$repo Xpressengine\Config\ConfigRepository repository instance
$validator Validator validator instance

add() public method

create new config
public add ( string $group, array $collection, string $siteKey = 'default' ) : ConfigEntity
$group string the name of target
$collection array entity value list
$siteKey string site key
return ConfigEntity

bindClosure() protected method

binding registered closure to config
protected bindClosure ( ConfigEntity &$config ) : void
$config ConfigEntity config instance
return void

build() protected method

build config object
protected build ( ConfigEntity $config ) : ConfigEntity
$config ConfigEntity config instance
return ConfigEntity

children() public method

get next level configs
public children ( ConfigEntity $config ) : array
$config ConfigEntity config instance
return array

convey() protected method

convey to descendants
protected convey ( ConfigEntity $config, callable $filter = null, array $items = null ) : void
$config ConfigEntity config instance
$filter callable filter function
$items array item key list
return void

get() public method

returns config object by target name
public get ( string $group, boolean $create = false, string $siteKey = 'default' ) : ConfigEntity
$group string the name of target
$create boolean if not exists, create new entity object
$siteKey string site key
return ConfigEntity

getOrNew() public method

if not exists, create new entity object by target name
public getOrNew ( string $group, string $siteKey = 'default' ) : ConfigEntity
$group string the name of target
$siteKey string site key
return ConfigEntity

getPureVal() public method

returns config pure value
public getPureVal ( string $key, mixed $default = null, string $siteKey = 'default' ) : mixed
$key string the name of target including entity name
$default mixed if not exists, be return
$siteKey string site key
return mixed

getVal() public method

returns config value
public getVal ( string $key, mixed $default = null, boolean $pure = false, string $siteKey = 'default' ) : mixed
$key string the name of target including entity name
$default mixed if not exists, be return
$pure boolean Do not see the parents
$siteKey string site key
return mixed

modify() public method

modify config information
public modify ( ConfigEntity $config ) : ConfigEntity
$config ConfigEntity config entity instance
return ConfigEntity

move() public method

Move entity hierarchy to new parent or root
public move ( ConfigEntity $config, string | null $to = null ) : ConfigEntity
$config ConfigEntity config object
$to string | null parent name
return ConfigEntity

put() public method

config change
public put ( string $group, array $collection, boolean $toDesc = false, callable $filter = null, string $siteKey = 'default' ) : ConfigEntity
$group string the name of target
$collection array items and values to be set
$toDesc boolean descendants modify if true
$filter callable filter function
$siteKey string site key
return ConfigEntity

remove() public method

remove config
public remove ( ConfigEntity $config ) : void
$config ConfigEntity config instance
return void

removeByName() public method

remove config by group name
public removeByName ( string $name, string $siteKey = 'default' ) : void
$name string config group name
$siteKey string site key
return void

set() public method

multiple set config values
public set ( string $group, array $collection, boolean $toDesc = false, callable $filter = null, string $siteKey = 'default' ) : ConfigEntity
$group string the name of target
$collection array items and values to be set
$toDesc boolean descendants modify if true
$filter callable filter function
$siteKey string site key
return ConfigEntity

setVal() public method

set config value
public setVal ( string $key, mixed $value, boolean $toDesc = false, callable $filter = null, string $siteKey = 'default' ) : void
$key string the name of target including entity name
$value mixed the value to be set
$toDesc boolean descendants modify if true
$filter callable filter function
$siteKey string site key
return void

share() protected method

shared when closure value
protected share ( ConfigEntity $config, string $item, mixed $value ) : ConfigEntity
$config ConfigEntity config instance
$item string configure key
$value mixed configure value
return ConfigEntity

validating() protected method

validation config
protected validating ( ConfigEntity $config ) : void
$config ConfigEntity config instance
return void

Property Details

$closures protected_oe property

closure list
protected array $closures
return array

$repo protected_oe property

repository instance
protected ConfigRepository,Xpressengine\Config $repo
return Xpressengine\Config\ConfigRepository

$validator protected_oe property

validator instance
protected Validator,Xpressengine\Config $validator
return Validator