Вопрос

I see that in Magento 2 all the xml (config, system, layout files, ...) files have a xsd associated for validation. This seams nice. Now you know what you are allowed to put in each file.

But I see that there are 2 validation schemas for each type of file.
Let's take system.xml for example.
The schema used inside the files is app/code/Magento/Backend/etc/system_file.xsd but there is also app/code/Magento/Backend/etc/system.xsd
I found a reference to system.xsd in Magento\Backend\Model\Config\SchemaLocator and it is declared as _schema and system_file.xsd is called _perFileSchema.

The difference between the 2 files are minor.
Just some label differences and on one tag there is a minoccurs="1" while on the other is minoccurs="0"

When is the _schema file used? In this example system.xsd.

Это было полезно?

Решение

Schema is for validation of merged configuration (configuration taken from xml files of all modules)

Per file schema is for validation of separate xml files.

The reason for this separation is that there are situations when constraints for each separate file are softer than for merged configuration. This might happen because merged configuration should be totally valid and ready for use by application while separate xml file is allowed to provide only part of required nodes/attributes that will only make sense when merged with all other config files so per-file schema should allow for this.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top