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龒龐龊龇鳰鳯鷲齛齗

鳥龶鼀鳤鳢齼鶁鳞龋黎麄齻鳚鳗龵鳓鷲鳒鳎鳤鳢龭龫鴵鴴鳍鳊鶐鳍鳴鳇鳅龋龭龫鶄鶃鳷鳄龋龙黱鵴鶢鹾鷑鳃鳁鹪龋鲾麄鳤鳢齻鳚鳗鲺鲶龭龫黷鹳麕鲳鳗鸫鲰鲯鲮黳龭龫鶄鶃鲪鲧龋龄齧鲯鲮鳤鳢龭龫鶄鶃鴦鴷黷鹳鲦鷈黎鳥龶鲳鳗齻鲥鲤鹱鲡鷜鲧龋鲟鲛鼨鳤鳢齻黷鹳鲗鲕齡鲑齑鷽龭龫龋鼙龶鷲鳁鹪齑鷽鶄鶃龋鳤鳢龭龫齑鷽鼛鴐齻黷鹳鲐

黨龯鲏鲋黷鹳麕鼨鼦鲇鲆鲛鲆鲅鲄龋鲃鲀鳥鶄鷙鳚鳗齻鱽鴞鱺鷜鱸鱶鲏鲋

本书共78小节:

评论 (写第一个评论)