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.)
- Write a plugin for \Magento\Framework\Config\Data::get() and read the custom xml files
- Append the custom xml file name in "Magento\Config\Model\Config\Structure\Reader" in di.xml
- Create a Data class that implements "\Magento\Framework\Config\Data'
- Inject a "reader" dependency for "Magento\Framework\Config\Data" in di.xml
- Make a Reader class that implements "\Magento\Framework\Config\Reader\Filesystem"
Answer(s): C,E
Explanation:
Based on web searches, it seems that Magento uses different classes and interfaces to interact with configuration files, such as Data, Reader, and Converter12. According to the documentation1, Data is a class that provides access to configuration data using a scope. Reader is an interface that reads configuration data from XML files. Converter is an interface that converts XML data into an array representation. Based on these definitions, I would say that two possible steps that the Architect should make to meet the requirement are:
C. Create a Data class that implements "\Magento\Framework\Config\Data" E. Make a Reader class that implements "\Magento\Framework\Config\Reader\Filesystem" These steps would allow the custom module to read all the XML configuration files declared in the system, merge them together, and use their values in PHP class.
The Architect should make two steps to meet this requirement: C) Create a Data class that implements "\Magento\Framework\Config\Data". This class will be responsible for reading and merging the custom xml configuration files and providing access to their values. The Data class should extend \Magento\Framework\Config\Data and use the constructor to inject the Reader class and the cache type. E) Make a Reader class that implements "\Magento\Framework\Config\Reader\Filesystem". This class will be responsible for loading and validating the custom xml configuration files from different modules. The Reader class should extend \Magento\Framework\Config\Reader\Filesystem and use the constructor to specify the file name, schema file, and validation state of the custom xml configuration files. Option A is incorrect because writing a plugin for \Magento\Framework\Config\Data::get() will not define a new xml configuration file, but rather modify the existing one. Option B is incorrect because appending the custom xml file name in "Magento\Config\Model\Config\Structure\Reader" in di.xml will not define a new xml configuration file, but rather add it to the system configuration structure. Option D is incorrect because injecting a "reader" dependency for "Magento\Framework\Config\Data" in di.xml will not define a new xml configuration file, but rather use an existing one.
Reference:
https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/XSD-XML-validation.html
Reveal Solution Next Question