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龏龌龂龀鳺鳸鷰齠齟

鳲龴鼂鳮鳭齸鶄鳩龅黗麉齶鳦鳣龱鳠鷰鳜鳚鳮鳭龪龦鴽鴹鳙鳘鶔鳙鳼鳕鳓龅龪龦鶉鶈鳾鳒龅龙黱鵸鶡麂鷇鳏鳋鹱龅鳉麉鳮鳭齶鳦鳣鳇鳄龪龦黹鹹麝鳃鳣鸧鲿鲻鲹黵龪龦鶉鶈鲷鲳龅齼齪鲻鲹鳮鳭龪龦鶉鶈鴪鴿黹鹹鲯鶻黗鳲龴鳃鳣齶鲮鲫鹵鲨鷙鲳龅鲤鲠鼰鳮鳭齶黹鹹鲜鲛齧鲚齙鷺龪龦龅鼞龴鷰鳋鹱齙鷺鶉鶈龅鳮鳭龪龦齙鷺鼢鴕齶黹鹹鲗

黩龭鲖鲔黹鹹麝鼰鼬鲑鲏鲠鲏鲋鲊龅鲇鲃鳲鶉鷗鳦鳣齶鲂鴤鱿鷙鱻鱸鲖鲔

本书共88小节:

评论 (写第一个评论)