AD0-E722 practice question 6 of 10

In a custom module, an Architect wants to define a new xml configuration file. The module should be able to read all the xml configuration files declared in the system, merge them together, and use their values in PHP class. Which two steps should the Architect make to meet this requirement? (Choose two.)

Full set: 50 questions
Answer options
A: Inject a "reader" dependency for "Magento\Framework\Config\Data" in di.xml Correct answer
B: Write a plugin for \Magento\Framework\Config\Data::get() and read the custom xml files
C: Create a Data class that implements "\Magento\Framework\Config\Data"
D: Append the custom xml file name in "Magento\Config\Model\Config\Structure\Reader" in di.xml
E: Make a Reader class that implements '\Magento\Framework\Config\Reader\Filesystem" Correct answer
Correct Answer:
A. Inject a "reader" dependency for "Magento\Framework\Config\Data" in di.xml; E. Make a Reader class that implements '\Magento\Framework\Config\Reader\Filesystem"
Explanation

To implement a new, merged XML configuration in Magento, an Architect must first create a Reader class. This class, typically extending \Magento\Framework\Config\Reader\Filesystem, is responsible for discovering and reading all XML files of a specific name from every enabled module (Option E). Secondly, this Reader must be configured via di.xml to pass the parsed data into a data-handling object, which is an instance of \Magento\Framework\Config\Data or its subclass. This is accomplished by injecting the custom Reader as a dependency into the Data object's definition in di.xml (Option A). These two steps establish the core mechanism for reading, merging, and making the configuration data available for use. Why Incorrect Options are Wrong
B. Write a plugin for \Magento\Framework\Config\Data::get() and read the custom xml files A plugin on the get() method intercepts data retrieval. It is not the correct mechanism for the initial loading and merging of configuration files.
C. Create a Data class that implements "\Magento\Framework\Config\Data" This is not strictly required. A virtual type of the base \Magento\Framework\Config\Data class can be defined in di.xml to achieve the same result without creating a new PHP class file.
D. Append the custom xml file name in "Magento\Config\Model\Config\Structure\Reader" in di.xml This Reader is specifically for processing system.xml files. Modifying it for a different, custom configuration type is incorrect and would likely disrupt core system configuration. References
1. Adobe Commerce Developer Guide, "Create a custom configuration type": This official guide outlines the full process. Reference for E: The section "Create a config reader" explicitly states: "The configuration reader class is responsible for reading all configuration files... and must extend \Magento\Framework\Config\Reader\Filesystem." Reference for A: The section "Define the configuration object" provides an example di.xml where the custom Reader is injected as a constructor argument into the Data class: . This directly supports injecting the reader dependency.
2. Adobe Commerce Developer Guide, "Virtual types": This document explains how virtual types can be used to customize constructor arguments for a class without creating a subclass. Reference for why C is incorrect: "You can use virtual types to change the arguments of a specific injectable class." This confirms that a new Data class file is not mandatory; a virtual type of Magento\Framework\Config\Data can be configured with the custom Reader, making option C an optional (though common) practice rather than a required step.

Scroll to Top