42. 配置系统Configuration(四):配置schema与类型化

龶龲龮龫龩龦龢龡 schema 龐龢龡龏龍龋龈龄龃龀齽齻齷齵齲龢龡龏龍齯龋龈龄齫齧龏龍齣齟齜龏龍齚龋龈龄龢龡齙齗齖齕齒 schema 齎齋齈齅龄齄齃齯龃龶龢龡龏龍 Drupal\Core\Config\Config 龫鼢鼞鼝鼚龦齵齲鼘齯鼕鼒龃 齻鼏鼎

Drupal\Core\Config\Config:: getSchemaWrapper ()

龢龡龏龍龫齯 schemaWrapper 黹黵黱齚齜龢龡龏龍齯龋龈龄齫齧龏龍龃黮 getSchemaWrapper() 鼕鼒黬黩黦黥黤龃黠黟黜黵默鼎 protected 龃龶龢龡龏龍齯齈黔龫黬黤齜鼕鼒黐黌龢龡齫齧齯龋龈黉黈龃龶黅黄齖龫黁黌麽鼏鼕鼒麺麹黟麽龶麷黦齵齲龢龡龏龍齯龋龈龄齫齧龏龍鼎

$typedConfigManager = \Drupal::service("config.typed");
//获取类型化配置管理器 
$name = "system.site";
//示例一个配置对象 
$data = \Drupal::configFactory()->getEditable($name)->getRawData();
//实时获取配置对象中储存的数据,配置对象如果被修改,得到的是修改后的值
$definition = $typedConfigManager->getDefinition($name);
//得到配置类型的插件定义,也就是schema配置文件中的内容,但经过递归合并,暂未处理动态类型
$data_definition = $typedConfigManager->buildDataDefinition($definition, $data);
//构建返回类型化数据对象的定义对象,因为schema定义中type属性允许动态内容
//(如[%parent.%parent.%type].third_party.[%key]),所以需要传递配置对象的数据参数
$typed_data = $typedConfigManager->create($data_definition, $data);
//创建类型化对象,最终我们得到了一个类型化配置数据对象

齻鹯鸇鸄鸀鹩鹥龢龡齯鷾鷺鹙黟麽黤麽鼏鷹鷶鼕鼒鼎

$typedConfigManager = \Drupal::service("config.typed");
//获取类型化配置管理器 
$name = "system.site";
//示例一个配置对象 
$typed_data = $typedConfigManager->get($name); 
//从类型化配置管理器中直接获取配置对象的类型化数据对象,但配置值是来自配置储存服务的

默鷞鷚鷖鷔龃麽鼏麽龢龡齈鷐龋龈鷩鷏鷍鼎

        $typedConfigManager=\Drupal::service("config.typed");
        $definition=$typedConfigManager->getDefinition("config_entity");
        print_r($definition);
        exit();

齵齲齯齎齋鷆齚鼎

Array
(
    [label] => Mapping
    [class] => Drupal\Core\Config\Schema\Mapping
    [definition_class] => \Drupal\Core\TypedData\MapDataDefinition
    [mapping] => Array
        (
            [uuid] => Array
                (
                    [type] => string
                    [label] => UUID
                )

            [langcode] => Array
                (
                    [type] => string
                    [label] => Language code
                )

            [status] => Array
                (
                    [type] => boolean
                    [label] => Status
                )

            [dependencies] => Array
                (
                    [type] => config_dependencies
                    [label] => Dependencies
                )

            [third_party_settings] => Array
                (
                    [type] => sequence
                    [label] => Third party settings
                    [sequence] => Array
                        (
                            [type] => [%parent.%parent.%type].third_party.[%key]
                        )

                )

            [_core] => Array
                (
                    [type] => _core_config_info
                )

        )

    [type] => config_entity
)

鶻鶺鼎鷴龋龈龄龢龡齙齗齖龫齵齲齎齋鹷 third_party_settings 鶶龫齯鶲鶯龋龈齯鹁鹀鶫鶩鹎鶦鶥鹫鶡鶟龃鶝鶜鶘鶖鶕鷩齎齋龫齯鼎

[type] => [%parent.%parent.%type].third_party.[%key]

齜鶒鶎齯鶡鶟鶊鶇齚龶龋龈龄龏龍麕麒齜鶃鶶齯龋龈龄齫齧龏龍鹷黐黌齯龃鹙黱齚 $typed_data->get($name) , 黠龫鸒齫 name 黟麽齚黤鵿鵼鵻齯鵷鼚齫鵴鵲鵱齯鵭鵩鵨龃龀鷆龶龋龈龄龢龡齙齗齖齯 buildDataDefinition 鼕鼒龫黐黌鶡鶟鹅齗龃鸕鵦齯鵥鵢麋鸒齫 $data 齚龏鵟齯龢龡鹡

mapping龐sequence鼎

龶龢龡鵝鵙龫鵕鵒鵎齫齧龋龈龃鹎鸇齚黥黤龋龈龄鵴鹝鵋鵉齯鼎

Drupal\Core\TypedData\Plugin\DataType\Map

Drupal\Core\TypedData\Plugin\DataType\ItemList

鶻鶺鸇鸗鷆鵃麹鵂鴿龃mapping龐sequence鴻龶龢龡鵝鵙龫黥黤龃鵃麹齚鼎

\Drupal\Core\Config\Schema\Mapping

\Drupal\Core\Config\Schema\Sequence

鵃麹鴹齚龋龈龄齫齧龏龍鼎鴶鴵龐鶲鶯齯龋齈黔龃黮mapping龐sequence齚鴴龏龢龡鵝鵙齯鴳鴱齈黔龃鴯鴭龦鸇鴫龋龃齈黔龦鷭鴨鼎Drupal\Core\Config\Schema\TypedConfigInterface

Schema鴥齎齋鼎

龢龡龏龍齯schema齎齋齚黟鴡齯龃齻鹯龢龡龏龍鶦鶥龏鵟齎齋schema龃龀齽鴟鴝鷾鷺鼏麕麒龋龈龏龍鹷鴙鴖undefined龋龈鹅齗龃齕齒龲鹗麕麒齲齯龋龈龏龍齚Drupal\Core\Config\Schema\Undefined龋齯齈齅龃齜龋龈龄龢龡龏龍黟麽黥黤齻鼏鼕鼒齵齲鶘鹲齯鹡鼎

$typed_data->getValue();

黮齚龶鴑鴐鴍鴉鹷龃鶦鶥齎齋龢龡schema齯龢龡龏龍齚麽config_object龋龈黐黌鹅齗龃鸮鴄鶘鹲齯龢龡黩鹕鴀鶥langcode龐_core黹黵

鳾鳻鳷龢龡龏龍鹷鳶齎齋龦schema黟麽黥黤齻鼏鼕鼒鼎

$typedConfigManager=\Drupal::service("config.typed");

$typedConfigManager –>hasConfigSchema($name); //鷆鸳鸲鳯鳬鹡

Undefined龐ignore龋龈齯鳪鳧鼎

鵃麹鴻齚鳤鵷齯鶺齋鸇鴫龃齻鵭鳣鶺鳡龃麎麋鳤鵷鹉齎齋龃麎麋鳤鵷鳞鳜鸇鸄鸀龋龈龃黮齚齈黔龲齄鳙鳕鴫龃鸮鴄黥黤鼕鼒鳓鳕鴫鳐鳎龡ignore龋龈龶鶥鳍鷾鷺鼏鳊鶥黤龃鳇齻龶鳄鳃schema齎齋鶥鲿黵鹷龃齻鹯齚鹉齎齋龃鵷鼚schema齎齋鸇齕齒龃鸘鸗鷞黈龃齻鹯鷍鲾鲻鲸齚ignore龋龈龀齽鳄鳃鷆齕齒

鲴龮黱鲰鲮齲鵕鲪龃麽鹤齯鲦鲤龫鲡鷆鲟鲞鲰鲮龢龡鴍鴉鲚鲘鵦鲚鳇鲖鲕龃龢龡鵝鵙鳊鲑龃龐黠鵃鵴鹝鶥鲐鲏鹐龃鲍鹤鲰鲮齯鲦鲤鲊鲉龢龡黩鹕鹷鲆鲤鸇鲃鲂鱿黤龢龡鵝鵙鱻鱸龃齻齚鲂鱿鲰鲮龢龡鵝鵙鳷鴐黩鹕鱴鶜麽鲴龮鲆鲤齯鱱鱭鹔鱫鶲鱸龃鱪鱧鼢鲰鲮齯黩鹕鱦鱤齗鱢齈鷐龢龡龃鼏龮鷆鲏鹐齈鷐鵝鵙龃鲰鲮龢龡齈鷐鼕鳣齯黩鹕鱠

默龦鱜鱚黩鹕鹷鼢鼞鱙鱘鱧鱘鱔鱑龃鱏鱎鲴鵝鶯鲦鲤齯鱋鳯鱊鶲鱇鱆鱜鱚

本书共71小节:

评论 (写第一个评论)