41. 配置系统Configuration(三):配置schema与类型化

龸龵龱龯龫龧龤龣龡龸龝龜龚龗龕龫龧龤龔龑龏龎龋龉龅龁 API 龣龡齶齳齰齮齭齫龝龤龣龡齨齧龏齥齢齠齟齞龯齜齚龏龝齖齠龗齔龏龸齓齑齍龝齉齈齄齀鼼鼸鼷

龅龁龎龋龱

鼵鼳鼰鼮齖鼬鼫鼩龝鼨鼥龏鼢龎鼟鼛齜龅龝鼚鼗鼖鼒鼎鼌鼋鼢鼇鼄龝鼁黿黽鼇鼄黹鼗鼖黵鼢黳龤黱黰龝黭黩黨龎黦黣黡黠龝黡齰黝黜黚黖龏鼰鼮龝黒黏黍黌黊黇黅黿黃鼰鼮黂麾龏鼨鼥麺鼥麶麲鼗鼒麱鼎鼢麯麬龝黿鼢麨麧龏黊麥黒黌麡龯龅麝鼰鼮麙龝齖麗齠龅龁龏龎龋龝黳麕麒麑麐麾麎龅鼟鼋龏黵鼢黳龤龅龁龎龋龝麌麋麇齫黅麃麂黏黏鼋鼋麁鹿龏龎龋鹻鹺鹸鹵鹴鹱麾鹯鼌鼋鼢龅龁龎龋龝鹫鹨鹧鹣齀鹢鹡鹟鹝鹚龝麾鹙龎龋麗齑鹘龅龁龏鹗鹓鹻鹐鹍鹊鹫鹉鹚龝鹈鼋鼨鹆麗鹂鸿鸽鸺鼼鹙龝鹂鸶鼖鸵龅龁鸱鸭鸪鸧鸦鸥鸥鼷 drupal 黡鸐鹙鸎鸊龏龎龋龉鸇黊龝龔鸃鷿麾齀鹱龅龁龎龋龱

黳龤龎龋龱

php 鷼龵鷺鷶鹙黳龤龏龅龁龎龋龝 drupal 龯鷲黳麕齚黡鼎黠鸇黊鹙龔鸃黂鷰龏黳龤龅龁龎龋龝龎龋龉龅龁鷭鷪鷧鹴鹙黿黽黳龤龎龋龝齀鷥麥龏鷡鹉鷺鷶鷠鷞龝黳龤龎龋麾龱 boolean email integer float string uri mapping sequence 龝鷁黅鶿齀 oop 鷥麥龏鷡鹉鶻龯龝麇龎龋龉鷭鷪鷺鷶龏龎龋龎鸇鶷龉鼁鶴鼷

鶲鶰鶬鶪龎龋龱

鷥黳龤龎龋龏鼎鼢鶲鶰鶬鶪龝齀鶦鶥鷼鹝鹐鹣鸧鸦鶡鸥鸥

鶝鶛鶬鶪龎龋龱

齀龸麑鷺鶗龏龎龋鷭鶛鼁麂龏麁龎鶝鶛龎龋龝麎龅鼟鼋龏鶲鶰黳龤龎龋鶖龁龅鶕鸪鼢龎麃麂鹙龅鶕鶔鼵龏麁鼢龎龋龝齀 mapping sequence 鷡鹉黡鸐鷭鶛龝鸶麱鼇鼄鶑麂鶍黰龝鶍黰鶊鶑麂鼫鼩鼋鶇龏鼰鼮鼎鶅

鶃齀齚鵿鼵龎龏龎龋鵼鹧麾鵹鼢鹗鵵龎龋龱

Undefined 龱鵲鵯鵮鹟鹝龎龋龝鵬麾鵨鶦鹟龎龋龏龅龁鹺鹸鶍鵧鵤龎龋鵠

Ignore 龱鵲鵯鵝鼟鵛鵗鷞龅龁龎龋龏鵔鵐齀鵤龎龋鶥鵍鵲鵯

drupal 龔鸃鷿鷥龅龁龎龋龏鵉鵇齠鵄龯 Schema 鵁鷪鷿龏龝龎龋鵉鵇鹙龅龁鴽鶑龝鴼鼒龅龁龏鼇鴻鴹龝麇龎龋龉龅龁鷭鷪鴸鴴鸇黊龅龁龏龎龋龉鵗鷞龝 Schema 鹣鸧鸦麎鹫鹉鸪鴳鹉鸪鹿鴯鸪麂鴮鸪鼛鴭鸪鴬鼸鸪鴪鴧龝黿麙麎鴣鵇鷡鴟龝鸧鸦麎鴝鹫鹉鴙龝鹫鹉鵁鷪齀 yml 鴳鹉鴒鶻龝鶻鵄龯鹫鹨鴎鴋鴊龏 config\schema 鴅鴄鷿龝齶齀 schema 鴂麎鵁鷪鴁麋鳾鹻鼟齠鶬鶪鴁鹚鼷龯鳼鳹龱 core\ config\schema 鷿齠龔鸃鴋鴊鷺鷶龏龅龁龎龋龝齖鳷鳴鹙黳龤龎龋龝鹟鹝黳龤龎龋麋鹣齀鷞齫鷭鶛鳰齜鷁龎龋龝鼎鳬鹟鹝鹙鼎黃龎龋龝齖鼬麗鹣齀鷞鵤龎龋鹢鹡鷭鶛鳫麡鳰齜鷁黝鼵黝鶝鳪龏龅龁龎龋鼷

龯鵧鳨龔鸃鷿龝鳦鼎黃鵧鳨鷥麥鶿鹣齀鳣齜鹟鹝麎鼎鼢龅龁龎龋龝鸶鳠鵬麾鹟鹝齈鳣鳝麎 Undefined 龎龋龝鳚鹱鶴鳙鳙鸶鳖鹟鹝鵧鳨龎龋龝鳕齟齞鵧鳨 Schema 鵁鷪鼷

schema 鹟鹝龱

鹫鹉 Schema 鵁鷪 yml 鴳鹉鴒鶻龯鹫鹨龏 config\schema 鴅鴄鷿龝鳑鳐鳏鳋鸇鳇龝鳅鴁鷡鹉麎龱

鹫鹨鴁 + 鶍龎鴁 + .schema.yml 鴙龝鸶 core.entity.schema.yml

鼎黃鹫鹉鵁鷪鷿鹣齀鹟鹝鼋黃鵧鳨鷥麥龏龎龋龝鵝鼟鷰鴧鶍龎鴁鵔鹣齀鲾鲼龝鸶龱 contact.schema.yml

鲹鲶龱 schema 麋鳾鼟齠鲳鲱龏龝鲯齠鼎鼢鳏鳋鸇鳇龝鲬 .yml 鶬鶪齠龗齔龏龝龔鸃齀龯鹫鹨龏 config\ schema 鴅鴄鷿鲨鵉 yml 龎龋鵁鷪龏鷡鹉鶴鲤鲡 schema 鵁鷪 龝鲞鷲鼟鴧龯鵤鴅鴄鹱鵄鳨齥齢鲛 schema yml 鵁鷪鼷

龯鹫鹨龏 config\install config\optional 鵁鷪鲙鷿鼎黃鵧鳨鵁鷪麗齠鼎黃鵧鳨鷥麥龝鼟鲘鶬鶪鴁龏鵁鷪鴁麗齠鵧鳨鷥麥鴁龝麱鵔黒齠鵤鵧鳨鷥麥龏龎龋鴁龝鼋黃鵧鳨鷥麥龏龎龋鹟鹝鹣齀鵄鳨龯鼎黃 schema 鵁鷪鷿黡鸐龝齀鵁鷪鴁鹻龎龋鴁鹚鴂麎 yml 鴳鹉龏鶖鲖鴁龝鵤鲖鴁龏鲓齠鼎黃龅鷭龝鵤龅鷭麗齠黿黃鵧鳨鷥麥龏龎龋鹟鹝龝龎龋鹟鹝麾鸶鹱黿黽鲖龱

Type 龱鵧鳨鷥麥鷿鲓龏龎龋龝鲍鹣齀齠黳龤龎龋黒鹣齀齠鳫麡龎龋龝鸎鸊鲊麋

Label 龱鲓鵉鵇龝齫鼟鼎鹟麗齠鵧鳨鵲鶰龏 label

Translatable 龱鵲鶥鵤龎龋齠齉鹣鸧鸦龝鲓麎 true 鹐鼟鲅鳨龝鼟鲅鳨鹺鹸麎鼟鹣鸧鸦

Nullable 龱鵲鶥鲓齠齉鹣齀麎 null 龝鸶鼟鲅鳨龝鹺鹸鼟鵛麎 NULL

Class 龱鷞鼒鷧鹴鵤龎龋龏龎龋龎 鱽鱹鹟龎鴁龝鲊龎龋龉龅龁 API

definition_class 龱鵤龎龋鹟鹝龎龏鱽鱹鹟龎鴁龝鲊龎龋龉龅龁 API

translation context 龱鸧鸦齚鹱鵁龝鹣鱰龏龝鲊龤龔龑龏鸧鸦龣龡

mapping 龱鸶鳠龎龋鵨鶦鹟麎 type: mapping 龝鱭鹣鵛麾鵤黰鲖龝齜鲓麎鱫鱪龅鷭

sequence 龱鸶鳠龎龋鵨鶦鹟麎 mapping sequence 鵔龝鵤鲖龏鲓麎鱩龑龅鷭鹻鴒鶻鱥麱龎龋龏鱫鱪鹚

type 鴼鶡龏鲓鱡黚鶝鳪龝齠鼎黃麝鱟鱞鲓龝鸶鳠鵮鹟鹝 type 鴼鶡龝齖鼬齜 鲓麎鵤龎龋鼖鱛 龏龎龋鴁龝鱚鱖鷰鴧鵨鲅鳨龝鲓麎龔鸃鷿鶻龯龏鹟鹝龎龋鹻鴎鱔鳨鱓鱒龝龯麱鼎鹫鹉鵁鷪鷿鹣鵄龯龤龎龋鹟鹝龸黒鹣齀龯麋龝黒鹣齀鶻龯鼒鼟麱鹫鹉鵁鷪鷿鹚龝龔鸃鱑鱎龎龋鹟鹝鵔鳣齀鷲麎鱌龁黡鸐鹟鹝龏鱊麶鶛齶龝鷠鷞鸶鹱鶛齶鷡鱆龱

NestedArray::mergeDeepArray([$merge, $definition ], TRUE)

龅鷭鶛齶鲊龤龔龑龅鷭鰱鴂龣龡龝 $definition 麎鵝龸鹟鹝龝 $merge 鵲鵯 type 鴼鶡鶦鹟龏龎龋鹟鹝龝鸶鳠麾麱鴁鲖齈鵝龸鹟鹝鰰鰭 $merge 鹟鹝龝黂齀鵝龸鹟鹝齠鰪龕龏龝鶛齶鰱鴂鼎鰧鱊麶鶗黳龤龎龋鹻黳龤龎龋鵬麾 type 鴼鶡鹚龝鱊麶鶛齶麋 type 鴼鶡鲓麎鼖鱛龝鶛齶鵯鶷鸶鹱龱

string:
  label: 'String'
  class: '\Drupal\Core\TypedData\Plugin\DataType\StringData'
label:
  type: string
  label: 'Label'
  translatable: true

龯鱑鱎 label 龎龋龏鹟鹝鵔黍鰣鶗龱

label:
  type: label 
  label: 'Label'
  translatable: true
  class: '\Drupal\Core\TypedData\Plugin\DataType\StringData'
  definition_class: '\Drupal\Core\TypedData\DataDefinition'

齜鷿鸶鳠鶛齶麋鵬麾 definition_class 鰠龝黍鵨鰟黜鹺鹸鲓龝鸶齚黂鵯鼷

麾鵔鵐鰜黽龎龋鹟鹝龏 type 鲓鱌鰛鼒鰚鷥麥龏龎龋鹐鵧鳨龅龁鷿龏鰜鵧鳨鲓龝黒麗齠鰘 type 龏鱎鲓鼟齠鰗鰖龏龝鼁齠鷰鴧鰕鸐鵔鶖龁鱌鰛黡鸐鼛鰒龝黿鰐麎鸵鰖龎龋龝鸵鰖龎龋齠龯 type 鴼鶡鲓鷿鷠鷞鹗鹟龏鰍鶕鴁龝鷞鶗龏鰍鶕鴁齀鷡鳴鰌鳷鳴龝鹣齀麾鼋黃鷡鳴鰌鰋龝龯鶰黃鷡鳴鰌鷿鸶鳠麾鼋黃鰍鶕鴁鹣齀鷞鰇鰌鶍鰄龝 鷡鳴鰌鷿鼟鹣齀麾鰍鶕齀麎龏齥齢龝鸶龱 type: '[%parent.%parent. %t ype].third_party.[%key]'

鰍鶕鴁麾鵹鼵龎龱



鵧鳨龅龁鷿龏鰜鼎鵧鳨鲖鴁龱鸶



[%parent.field_type]



鷿龏



field_type



龝鵲鵯鵧鳨龅鷭鷿齚鼎鯺龅鷭鷿龏



field_type



鲖龏鲓

鹗鵵鯶鷞鰍鶕龱

%parent 鯶鷞鶗龅鷭鷿龏齚鼎麒鯺

%type 龗齔鴎 %parent 鯵鷞龝鵲鵯鰜鼎麒鯺龅鷭龏龎龋龝鲹鲶龯鷿鳴鰌麙 %type type 齠鼟鼎鹿龏鵹鼢鰍鶕龎龋

%key 龤龎龋龅龁龯鰚麒龅鷭鷿龏鲖鴁龝龯鱫鱪龎龋龎鷿黒麗齠 $parent->getName()

龸鵁鷺鶗鸶鳠鶦鹟鹙 Type 鴼鶡龏鲓龝齖鼬黍鲡鶗齫黡鸐鹟鹝鶛齶龝鸶鳠鲡鼟鶗鷥鵗龏龎龋鹟鹝龝鳣黡鸐鯭鯪鲤鲡龝鱌龁鲓龏麒鯺黡鸐龝鸶鹱龱

鸶鳠鲤鲡龏龎龋麎龱 breakpoint.breakpoint.module.toolbar.narrow 龯鲡鼟鶗龏鹆鯥鹱龝鱌鯡鯞鯚鼎鹱鲓龱

        breakpoint.breakpoint.module.toolbar.*
        breakpoint.breakpoint.module.*.*
        breakpoint.breakpoint.module.*
        breakpoint.breakpoint.*.*.*
        breakpoint.breakpoint.*
        breakpoint.*.*.*.*
        breakpoint.*

龎龋鴁齠麾鴮齈龏龝齀鰇鰌鶍麒鯺龝黒鹣齀鷠鷞鯕鰌龝鸶龱

鲤鲡 block.settings.system_menu_block:footer 龯鲡鼟鶗龏鹆鯥鹱龝鱌鯡鯞鯚鼎鹱鲓龱

        block.settings.system_menu_block:*
        block.settings.*:*
        block.settings.*
        block.*.*:*
        block.*

麇鷲黒鹣齀鳙鳰鹟鹝龎龋鴁龏鵔鵐龝鹣齀鷞鯒鰌鯐龎龋龏鱚鵧鱟龝黿鹿鹣齀鹟鹝鼎鼵龎龏鵧鳨龎龋龝鯭鯪鰒鱆鲊龱

Drupal\Core\Config\TypedConfigManager:: getFallbackName($name)

Schema 鵁鷪鯉鯇龏鳏鳋鸇鳇龱

麾鼎黃鸽龏鯆鯂鹿鹉鴟鼒鮿鮼鮸鴂龝龯鯉鯇 Schema 鵁鷪鵔鮶鹟鮳鮯齀鹱鮮齈龱

1 龱龯 Schema 鵁鷪龏鮩鮥鳷鮢鼎黃鲹鮠龝鰘鶥鵤鵁鷪龏鼎黽鴻鴹

2 龱龯鹟鹝鷿鷠鷞鮢鹝鮜鮚龏鲹鮠龝麾鵔鵐 label 鮘鶲鮗龝鹣齀鮖鵼鮒黜鲹鮠鰘鶥

3 龱麝鱟鱞鷠鷞鶰鰌龝鼟鴧鷞鮍鯶鰌

4 label 鲓鷞鶰鯶鰌鳷鳴龝鳕鴟鲯麾鼎黃鶰鮆黒黿鼬鯐

5 龱龅鷭鲖鴎 type 鲓鼟鴧鷠鷞鯶鰌龝鮁鼟鵛麾魾鴳

6 龱鸶鳠魹龋魸鵨魷龉麎麝鱟鱞龝齖鼬鷠鷞鶰鯶鰌鳷鮢

7 龱鲹鲶鸐魳黡龝魱魭 yaml 鴳鹉魪魧

黝鼋鹣齀鲤鳙魣魢鰘鶥鷿龏鯆鯂魡魝

鵝鹟鹝鸽鹫鹉鵁鷪麋龝龔鸃齠鸶鳖鲤鲡齫黅龏魜龝黿黃麗齠 schema 鵧鳨鴒鶻魛龚鴧魙麂龏魖鴂鼷

Schema 鵧鳨鴒鶻魛龚龱

鷞齀鲡鶗龔鸃鷿鵨魓鷞龏鹫鹨鸪龣龡鸪鹵鹴鵧鳨龏鵧鳨 schema 鵁鷪

齢魑 id config.storage. schema

龎龱 Drupal\Core\Config\ExtensionInstallStorage

齀龯魓鷞龏鹫鹨鸪龣龡鸪鹵鹴鵧鳨鷿 config\schema 鴅鴄鲨鵉 yml 鵁鷪龏鷡鹉鲤鲡鵧鳨 schema 鵁鷪鼷

鹺鹸鷿鵁魡魝鹵鹴鹆鯥鹱麾鸶鹱 schema 鵁鷪鹻鱚魎 schema 鵧鳨鴒鶻魛龚龏 getAllFolders() 鷡鱆魌鯭龝鵤鷡鱆鲯魌鯭鵨魓鷞鹫鹨龏 schema 鵁鷪龝鲖鴁麎鵁鷪鴁龝鲓麎鵁鷪鳼鳹鹚龱

Array
(
    [core.data_types.schema] => core/config/schema
    [core.entity.schema] => core/config/schema
    [core.extension.schema] => core/config/schema
    [core.menu.schema] => core/config/schema
    [automated_cron.schema] => core/modules/automated_cron/config/schema
    [block.schema] => core/modules/block/config/schema
    [block_content.schema] => core/modules/block_content/config/schema
    [ckeditor.schema] => core/modules/ckeditor/config/schema
    [color.schema] => core/modules/color/config/schema
    [comment.schema] => core/modules/comment/config/schema
    [comment.views.schema] => core/modules/comment/config/schema
    [contact.schema] => core/modules/contact/config/schema
    [contact.views.schema] => core/modules/contact/config/schema
    [contextual.views.schema] => core/modules/contextual/config/schema
    [datetime.schema] => core/modules/datetime/config/schema
    [dblog.schema] => core/modules/dblog/config/schema
    [dblog.views.schema] => core/modules/dblog/config/schema
    [editor.schema] => core/modules/editor/config/schema
    [field.schema] => core/modules/field/config/schema
    [field.views.schema] => core/modules/field/config/schema
    [field_ui.schema] => core/modules/field_ui/config/schema
    [file.schema] => core/modules/file/config/schema
    [file.views.schema] => core/modules/file/config/schema
    [filter.schema] => core/modules/filter/config/schema
    [history.views.schema] => core/modules/history/config/schema
    [image.data_types.schema] => core/modules/image/config/schema
    [image.schema] => core/modules/image/config/schema
    [language.schema] => core/modules/language/config/schema
    [link.schema] => core/modules/link/config/schema
    [locale.schema] => core/modules/locale/config/schema
    [menu_ui.schema] => core/modules/menu_ui/config/schema
    [node.schema] => core/modules/node/config/schema
    [node.views.schema] => core/modules/node/config/schema
    [options.schema] => core/modules/options/config/schema
    [path.schema] => core/modules/path/config/schema
    [rdf.data_types.schema] => core/modules/rdf/config/schema
    [rdf.schema] => core/modules/rdf/config/schema
    [search.schema] => core/modules/search/config/schema
    [search.views.schema] => core/modules/search/config/schema
    [shortcut.schema] => core/modules/shortcut/config/schema
    [system.schema] => core/modules/system/config/schema
    [taxonomy.schema] => core/modules/taxonomy/config/schema
    [taxonomy.views.schema] => core/modules/taxonomy/config/schema
    [text.schema] => core/modules/text/config/schema
    [tour.schema] => core/modules/tour/config/schema
    [update.schema] => core/modules/update/config/schema
    [user.schema] => core/modules/user/config/schema
    [user.views.schema] => core/modules/user/config/schema
    [views.access.schema] => core/modules/views/config/schema
    [views.area.schema] => core/modules/views/config/schema
    [views.argument.schema] => core/modules/views/config/schema
    [views.argument_default.schema] => core/modules/views/config/schema
    [views.argument_validator.schema] => core/modules/views/config/schema
    [views.cache.schema] => core/modules/views/config/schema
    [views.data_types.schema] => core/modules/views/config/schema
    [views.display.schema] => core/modules/views/config/schema
    [views.entity_reference.schema] => core/modules/views/config/schema
    [views.exposed_form.schema] => core/modules/views/config/schema
    [views.field.schema] => core/modules/views/config/schema
    [views.filter.schema] => core/modules/views/config/schema
    [views.pager.schema] => core/modules/views/config/schema
    [views.query.schema] => core/modules/views/config/schema
    [views.relationship.schema] => core/modules/views/config/schema
    [views.row.schema] => core/modules/views/config/schema
    [views.schema] => core/modules/views/config/schema
    [views.sort.schema] => core/modules/views/config/schema
    [views.style.schema] => core/modules/views/config/schema
    [bartik.schema] => core/themes/bartik/config/schema
    [seven.schema] => core/themes/seven/config/schema
)



龔鸃龯龧鱎黿黽



schema



鵁鷪鵔龝黍鷠鷞



yaml



鱩龑龉魑龝鹺鹸鷠鷞鷭鷪鷺鷶龏鱩龑龉魑龱



Drupal\Component\Serialization\Yaml

鲬龯鬼鰇鵧鳨鵁鷪鷿黒鹣齀鬹鵼鶦鹟 yaml 鱩龑龉魑

鲖鴁麎龱 yaml_parser_class

鸶龱 $settings[' yaml_parser_class ']=鴙 鱽鱹鹟龎鴁 鴙;

鵤鬵鵛龯鴋鴊鷺鷶龏 Drupal\Core\Serialization\Yaml 鷿鸇黊龱 $class = Settings::get('yaml_parser_class')

 

鵧鳨鷥麥鬴鶻龱

龯鵧鳨鷥麥 Drupal\Core\Config\Config 鬰鷞鼖鬬龏 save 鷡鱆黡鸐鬴鶻鵔龝黍黡鸐龅龁鸱鸭鴎龎龋魷龉龝魎鬫鸶鹱龱

鬪龕鸱鸭鵧鳨鴁龝龗齔麾鰇鰌鸪鼟鬨魎 250 麝鱟龝鼟鮢 ?: * < > " ' / \ 鷠鷞鸶鹱鷡鱆

public static function validateName($name)

鵧鳨 schema 龏鹆鯥鹱龝鶖龁鵧鳨 schema 魷龉鵧鳨鲓龏龎龋龝鷠鷞鸶鹱鷡鱆龱

protected function castValue($key, $value)

鵬麾鵧鳨 schema 齈黡鸐黳龤龏鵧鳨鲓鸱鸭龝鲓麐鹣齀麎 null 鸪魡鶕鹐龅鷭龝鷠鷞鸶鹱鷡鱆龱

protected function validateValue($key, $value)

鬘龸龯鲅鳨鵧鳨鲓鵔龝鵧鳨龅鷭龏鲖鴁黒黍鵨鸱鸭龝鼟鵛鮢麾鰇鰌龝鷠鷞鸶鹱鷡鱆龱

protected function validateKeys(array $data)

齀齚魎鬫龏 castValue 鷡鱆齠鳣鵧鳨龅鷭鷿龏魡鶕龅龁鹐 NULL 鱌龁鵧鳨 schema 鷿龏鲅鹟魷龉麎鷥鵗龏 php 黳龤龅龁龎龋龝黒麗齠鬔鸐鹙 Drupal\Core\TypedData\PrimitiveInterface 鷿龏 getCastedValue() 鷡鱆龝黿鹿鵧鳨鴻鴹龅鷭鬒魎龎龋鬎鬋麋鶊鱩龑龉鬴鶻鶗龅龁鬈 config 鵲鷿龝鵤鵲鷿鬴鶻龏鵧鳨鴻鴹龅鷭麐鳷鮢魡鶕龅龁龎龋鼷

鹣齠龔鸃齠鸶鳖鬆鵧鳨鷥麥鴎龎龋龉龅龁鷭鷪鴽鶛鬅鶴鵗鷞龏魜鬄黿麗齠龎龋龉鵧鳨鬃鼼魑龏魖鴂鼷

龎龋龉鵧鳨鬃鼼魑龱

鶖龁鵧鳨 schema 鹟鹝鳣鵧鳨鷥麥鷿龏鵧鳨龅鷭魷龉麎龎龋龉龅龁鷥麥龝黿鹿麗鹣齀齀龎龋龉龅龁鷥麥鶴鰱鴂鵧鳨龅龁鹙龝鵤魛龚鹟鹝鸶鹱龱

 config.typed:
    class: Drupal\Core\Config\TypedConfigManager
    arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery', '@module_handler']
    tags:
      - { name: plugin_manager_cache_clear }

龯鸇黊齚龝鵤魛龚鸇髹齠鼎黃髵鷪鬃鼼魑鹻鲊龤龔龑龏髵鷪龣龡髳鹚龝鹢髯鼖龎龋龉龅龁鬃鼼魑龝鳣鵧鳨 schema 鹟鹝鵝鯐髵鷪鳙髭龝鳦鼎黃 Schema 鹟鹝鶿齠鼎黃髵鷪龎龋龝龎龋鴁麗齠髵鷪 ID 龝鳦鼎黃 Schema 鵁鷪鶿鱚魎髵鷪髪鲱鲡鶗龝 schema 鹟鹝麗齠髵鷪鹟鹝龝鴎鱖鴮髵鷪鬃鼼魑鼟麱龏齠鷁齶鼟齀鮠鵁鴂麎髵鷪黌黊髪鲱龝鼁齠齀 Schema 鵧鳨鴒鶻魛龚鴂麎黌黊髪鲱龝鹟鹝龏黌黊龎麎龱

Drupal\Core\Config\Schema\ ConfigSchemaDiscovery

鵤髵鷪鬃鼼魑鷿 $this->getDefinitions() 鱎鰣龏髵鷪鹟鹝龅龁麎鼎黃龅鷭龝鲖鴁麎鵧鳨龎龋鴁龝鲓麎鷥鵗龏 schema 鹟鹝龅鷭龝髩鶻龯龅龁鬈鵲 cache_discovery 鷿 cid typed_config_definitions 髥鴅龏 data 麝鰋麙龝鹱髡麋鷠鷞鹱龑鬫鱩鲤鳙龱

$a=file_get_contents("cache_discovery-typed_config_definitions.bin");
$a=unserialize($a);
print_r(array_keys($a));
print_r($a);

龯龔鸃鷿鵁鹺鹸鹵鹴鹆鯥鹱龝鹟鹝鹙鹯鼌鼋鼢鵧鳨鷥麥龅龁龎龋龝黒鹣齀鷠鷞鸶鹱鷡鹉鲤鳙龱

鲤鳙鵬麾鬒魎鹫鹨髞黰鸺鼼龏鹟鹝龝黒麗齠髝鹫鹉鵁鷪鷿龧鱎龏鹟鹝龝龯髜鲱魑鷿鬔鸐龱

        $discovery = new \Drupal\Core\Config\Schema\ConfigSchemaDiscovery(\Drupal::service("config.storage.schema"));
        print_r($discovery->getDefinitions());
        exit();

鲤鳙鬒魎鹫鹨髞黰鸺鼼魎龏鹟鹝龝龯髜鲱魑鷿鬔鸐龱

$c=\Drupal::service("config.typed");
$a=$c->getDefinitions();
print_r(array_keys($a));
print_r($a);
exit();

鵤龎龋龉鵧鳨鬃鼼魑龏龣鴧鷡鱆鬵鵛鸶鹱龱

public function getDefinition ($base_plugin_id, $exception_on_invalid = TRUE)

鱚魎龎龋鴁鹻黒麗齠髵鷪 id 鹚鰣鶗鱊麶鶛齶麋龏龎龋鹟鹝龅鷭龝龎龋鴁髚鬒魎鯭鯪鸺鼼龝鲬龅鷭鷿齨齧龏鸵鰖龎龋鷿龏鰍鶕髖鵮黡鸐體髐龝鸶鳠龎龋鼟鶻龯龝齈魌鯭 undefined 龏鹟鹝

public function buildDataDefinition(array $definition, $value, $name = NULL, $parent = NULL)

鱌龁 getDefinition 鷡鱆魌鯭龏鴽鳠龝髎齟龎龋龉龅龁鷭鷪鷰鴧龏龅龁鹟鹝龎龝麾鷲鹟鹝龎鷥麥麗鹣齀髎齟龎龋龎龅龁鷥麥鹙龝鲞麎龎龋鹟鹝鷿鹣齀鮢麾鸵鰖龎龋龝齜鲓鹣鵛鱌鰛鼒鵧鳨龅龁龝黂齀鷁鷰鴧鳣鵧鳨龅龁鼎齶髊齰鼷

public function get($name)

鰧鳚鶖龁鵧鳨鷥麥鴁魌鯭龎龋龉龅龁鷥麥龝鵤鷡鱆龏鸇黊鴎鵧鳨鷥麥鷿鰣鶗 schemaWrapper 鴼鶡 龏鷡鱆鼎鹿龝黂鼟麱龏齠鵧鳨鷥麥鷿龏 schemaWrapper 鴼鶡鳣鳷鮢鸇鵔鵧鳨龅龁鼷

鲹鲶龱龯鹺鹸鹆鯥鹱鹻髝齢魑鷿鱑鱎魛龚龏鹆鯥鹱鹚龎龋龉鵧鳨鬃鼼魑鵬麾鲹齰鮶髃鬃鼼魑龝齫鲯齠鶖龁 schema 鴻鴹魷龉鵧鳨龎龋龝鸶麾鷰髀鹣齀骾鸵鲹齰鼷

鵤鬃鼼魑黍鬔鸐 config_ schema _info 髞黰齀骽黏鹫鹨骼骻龎龋 schema 鹟鹝龅龁龝黒麗齠鬔鸐鹫鹨鹟鹝龏 hook_ config_schema_info _alter() 髞黰骷龅龝鵤鰱鴂鼟骽黏鮒黜鹐鹍骶鶃 schema 鹟鹝鰠龝鲬鹣齀骼骻

魣魢鰘鶥龱

鼎鸪 drupal 龏鵧鳨 schema 骰鶗鹙 Kwalify 鰠鴅 龏魓黌龝鵤鰠鴅骭骩龱 http://www.kuwata-lab.com/kwalify/ yaml json 鷥鼒鴽鶑龉龅龁鶴鰘鹈鶲鶰龝黨龎鹣龧鶡鴎鹣鼼鼸鶡鹈鸽龝鲬鴎 xml 鱥鹂骤骣 DTD 黿鹿龏麯麬龝鵬麾鹫鹉龝鲞鷲 Kwalify 鰠鴅鳰黊鹙龝麎鼸骡鵤骞龡鼁麡龝齫齠鼎黃 yaml json 鴳鹉龏鼸骜鸪 schema 鸱鸭鸪龅龁骘鹟魖骖鼷

骒鸪 鵧鳨 schema 骑骭鵁骍鼟鲬验鳰鹙鼸鮠鹧验鳰鹙鼎黽魖骖龝骊骩麎 https://www.drupal.org/node/1905070

鵿鸪 鵧鳨鵁鷪鯆鯂魡魝龝骑鷡骊骩龱

https://www.drupal.org/docs/develop/coding-standards/configuration-file-coding-standards

龤髳骅鵔麗骃鶗黿麙龝鹱鼎髳鳣鹢鹡骃鼸鵧鳨龔鸃鷿龎龋龉龏鰕鷞

本书共63小节:

评论 (写第一个评论)