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

龰髻骑鵰麨骐鶶鼋麫龨鹺鼚髻鴁鹬鹩骐齁鵽鴄龝鸐鸌龖龓龑龗鰜鷯

本书共78小节:

评论 (写第一个评论)