7天成为Magento系统架构师,现在开始学习Magento全栈开发!
模块配置文件概览
Magento 早期版本中使用的 config.xml 配置文件的职责现在分为几个文件,位于不同的模块目录中。 Magento 的多个配置文件仅在模块请求特定配置类型时按需加载。
您可以使用这些文件(也称为配置类型)来自定义模块行为的特定方面。
多个模块可以声明影响相同配置类型(例如事件)的配置文件,并且这些多个配置文件被合并。
以下是本主题中使用的常用术语:
配置对象——负责定义和验证配置类型的 Magento 库或类。例如,config.xml 的配置对象是 Magento\Framework\App\Config。
配置阶段——阶段被定义为主要、全局和区域。每个阶段确定何时加载配置类型并与同名配置类型合并。例如,module.xml 文件与其他 module.xml 文件合并。有关更多信息,请参阅配置加载和合并。
配置范围——作为配置阶段的补充,范围定义了配置类型模型。例如,adminhtml 是一个区域作用域,在阶段加载其他模块的 adminhtml 配置。有关更多信息,请参阅模块和区域。
配置加载和合并
本节讨论如何加载和合并配置文件。
Magento 如何加载配置文件
Magento 按以下顺序加载配置文件(所有路径都相对于您的 Magento 安装目录):
主要配置 (app/etc/di.xml)。该文件用于引导 Magento。
来自模块的全局配置(<您的组件基础目录>//-/etc/.xml)。从所有模块中收集某些配置文件并将它们合并在一起。 来自模块的区域特定配置(<您的组件基础目录>/<供应商名称>/<组件类型>-<组件名称>/etc/<区域>/.xml)。从所有模块中收集配置文件并将它们合并到全局配置中。某些特定于区域的配置可以覆盖或扩展全局配置。
在哪里
是您的组件所在的基本目录。典型值为 app/code 或 vendor 相对于 Magento 安装目录。
是组件的供应商名称;例如,Magento 的供应商名称是 magento。
是以下之一:
模块-:扩展或模块。
主题-:主题。
语言-:语言包。
目前,主题位于 /app/design/frontend 或 /app/design/adminhtml 下。
:在 composer.json 中定义的组件名称。
配置文件合并
配置文件中的节点根据其完全限定的 XPath 进行合并,该 XPath 在 $idAttributes 数组中定义了一个特殊属性,声明为它的标识符。对于嵌套在同一父节点下的所有节点,此标识符必须是唯一的。
Magento 的合并算法如下:
如果节点标识符相等(或者如果没有定义标识符),则节点中的所有基础内容(属性、子节点和标量内容)都将被覆盖。
如果节点标识符不相等,则该节点是父节点的新子节点。
如果原始文档有多个节点具有相同的标识符,则会因为标识符无法区分而引发错误。
配置文件合并后,生成的文档包含原始文件中的所有节点。
请注意,您可以使用 \Magento\Framework\Config\Reader\Filesystem 类来调试和理解配置文件加载器和合并配置过程背后的逻辑。
配置类型、对象和接口
以下部分提供了有关配置类型、它们对应的配置对象以及可用于处理这些对象的接口的信息:
配置类型和对象
配置接口
配置类型和对象
下表显示了每种配置类型以及与之相关的 Magento 配置对象。
Configuration file | Description | Stage | Configuration object |
---|
address_formats.xml | Address format declaration | primary, global | \Magento\Customer\Model\Address\Config |
acl.xml | Access Control List | global | \Magento\Framework\Acl\AclResource\Provider |
analytics.xml | Advanced reporting | primary, global | \Magento\Analytics\Model\Config\Reader |
cache.xml | Cache type declaration | primary, global | \Magento\Framework\Cache\Config\Data |
catalog_attributes.xml | Catalog attributes configuration | global | \Magento\Catalog\Model\Attribute\Config\Data |
config.php and env.php | Deployment configuration | These files are readable/writeable by the internal config processor. | Has no object, cannot be customized |
config.xml | System configuration | primary, global | \Magento\Framework\App\Config |
communication.xml | Defines aspects of the message queue system | global | \Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Communication |
crontab.xml | Configures cron groups | global | \Magento\Cron\Model\Config\Data |
cron_groups.xml | Specifies cron group options | global | \Magento\Cron\Model\Groups\Config\Data |
db_schema.xml | Declarative schema | global | Magento\Framework\Setup\Declaration\Schema |
di.xml | Dependency injection configuration | primary, global, area | \Magento\Framework\ObjectManager\Config |
eav_attributes.xml | Provides EAV attributes configuration | global | \Magento\Eav\Model\Entity\Attribute\Config |
email_templates.xml | Email templates configuration | global | \Magento\Email\Model\Template\Config\Data |
esconfig.xml | Elasticsearch locale stopwords config | global | \Magento\Elasticsearch\Model\Adapter\Index\Config\EsConfig |
events.xml | Event/observer configuration | global, area | \Magento\Framework\Event |
export.xml | Export entity configuration | global | \Magento\ImportExport\Model\Export\Config |
extension_attributes.xml | Extension attributes | global | \Magento\Framework\Api\ExtensionAttribute\Config |
fieldset.xml | Defines fieldsets | global | \Magento\Framework\DataObject\Copy\Config\Reader |
indexer.xml | Declares indexers | global | \Magento\Framework\Indexer\Config\Reader |
import.xml | Declares import entities | global | \Magento\ImportExport\Model\Import\Config |
menu.xml | Defines menu items for admin panel | adminhtml | \Magento\Backend\Model\Menu\Config\Reader |
module.xml | Defines module config data and soft dependency | primary, global | \Magento\Framework\Module\ModuleList\Loader |
mview.xml | MView configuration | primary, global | \Magento\Framework\Mview\Config\Data |
payment.xml | Payment module configuration | primary, global | \Magento\Payment\Model\Config |
persistent.xml | Magento_Persistent configuration file | global | \Magento\Persistent\Helper\Data |
pdf.xml | PDF settings | global | \Magento\Sales\Model\Order\Pdf\Config\Reader |
product_options.xml | Provides product options configuration | global | \Magento\Catalog\Model\ProductOptions\Config |
product_types.xml | Defines product type | global | \Magento\Catalog\Model\ProductTypes\Config |
queue_consumer.xml | Defines the relationship between an existing queue and its consumer | global | \Magento\Framework\MessageQueue\Consumer\Config\Xml\Reader |
queue_publisher.xml | Defines the exchange where a topic is published. | global | \Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Publisher |
queue_topology.xml | Defines the message routing rules, declares queues and exchanges | global | \Magento\Framework\MessageQueue\Topology\Config\Xml\Reader |
reports.xml | Advanced reports | global | \Magento\Analytics\ReportXml\Config |
resources.xml | Defines module resource | global | \Magento\Framework\App\ResourceConnection\Config\Reader |
routes.xml | Route configuration | area | Magento\Framework\App\Route\Config |
sales.xml | Defines sales total configuration | global | \Magento\Sales\Model\Config\Data |
search_engine.xml | Provides search engine configuration | global | Magento\Search\Model\SearchEngine\Config |
search_request.xml | Defines catalog search configuration | global | \Magento\Framework\Search\Request\Config |
sections.xml | Defines actions that trigger cache invalidation for private content blocks | frontend | SectionInvalidationConfigReader |
system.xml | Defines options for system configuration page | adminhtml | \Magento\Framework\App\Config |
validation.xml | Module validation configuration file | global | \Magento\Framework\Validator\Factory |
view.xml | Defines Vendor_Module view config values | global | \Magento\Framework\View\Config |
webapi.xml | Configures a web API | global | \Magento\Webapi\Model\Config |
webapi_async.xml | Defines REST custom routes | global | \Magento\WebapiAsync\Model\ServiceConfig |
widget.xml | Defines widgets | global | \Magento\Widget\Model\Config\Reader |
zip_codes.xml | Defines zip code format for each country | global | \Magento\Directory\Model\Country\Postcode\Config\Data |
配置接口
您可以使用 Magento\Framework\Config 下的接口与配置文件进行交互。
如果您创建新的配置类型,也可以使用这些接口。
Magento\Framework\Config 提供以下接口:
Framework\Config\ConverterInterface,它将 XML 转换为配置的内存中数组表示。
Framework\Config\DataInterface,检索指定范围内的配置数据。
Framework\Config\FileResolverInterface,它标识了 Magento\Framework\Config\ReaderInterface 要读取的文件的位置。
Framework\Config\ReaderInterface,它从存储中读取配置数据,并选择从中读取的存储。
即文件系统、数据库、其他存储根据合并规则合并配置文件,并用验证模式对配置文件进行验证。
Framework\Config\SchemaLocatorInterface,用于定位 XSD 架构。
Framework\Config\ScopeListInterface,它返回范围列表。
Framework\Config\ValidationStateInterface,它检索验证状态。
如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。