Skip to content

Conversation

@Vinai
Copy link
Contributor

@Vinai Vinai commented Jun 25, 2015

Using custom configuration files requires a number of class implementations.
Most of these can be satisfied by using generic implementations found within the Magento\Framework\Config namespace and injectable parameters.

  • Magento\Framework\Config\DataInterface => Magento\Framework\Config\Data
  • Magento\Framework\Config\ReaderInterface => Magento\Framework\Config\Reader\Filesystem
  • Magento\Framework\Config\ConverterInterface => Magento\Framework\Config\Converter\Dom

The one that is missing is a generic implementation of the schema locator interface Magento\Framework\Config\SchemaLocatorInterface
The implementation always is very simple, it only returns the names of the schema files. Not a lot of work but just another bit of annoying boilerplate to write.

This PR adds a generic schema locator implementation.
Here is an example di.xml how that might be used:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Example\DiConfig\Controller\Index\Index">
        <arguments>
            <argument name="config" xsi:type="object">Example\DiConfig\Model\ConfigData\Virtual</argument>
        </arguments>
    </type>
    <virtualType name="Example\DiConfig\Model\ConfigData\Virtual"
                 type="Magento\Framework\Config\Data">
        <arguments>
            <argument name="reader" xsi:type="object">Example\DiConfig\Model\Config\Reader\Virtual</argument>
            <argument name="cacheId" xsi:type="string">example_config</argument>
        </arguments>
    </virtualType>
    <virtualType name="Example\DiConfig\Model\Config\Reader\Virtual"
                 type="Magento\Framework\Config\Reader\Filesystem">
        <arguments>
            <argument name="converter" xsi:type="object">Example\DiConfig\Model\Config\Converter\Virtual</argument>
            <argument name="schemaLocator" xsi:type="object">Example\DiConfig\Model\Config\SchemaLocator\Virtual</argument>
            <argument name="fileName" xsi:type="string">example.xml</argument>
        </arguments>
    </virtualType>

    <virtualType name="Example\DiConfig\Model\Config\Converter\Virtual"
                 type="Magento\Framework\Config\Converter\Dom"/>

    <virtualType name="Example\DiConfig\Model\Config\SchemaLocator\Virtual"
                 type="Magento\Framework\Config\GenericSchemaLocator">
        <arguments>
            <argument name="moduleName" xsi:type="string">Example_DiConfig</argument>
            <argument name="schema" xsi:type="string">example.xsd</argument>
        </arguments>
    </virtualType>
</config>

No custom class implementations are required anymore to use custom configuration files. Of course they still should be used if it makes sense though, mostly for the DataInterface to provide readable getters.

…locator

Using custom configuration files requires a number of class implementations.
Most of these can be satisfied by using generic implementations found within
the Magento\Framework\Config namespace and injectable parameters.

* Magento\Framework\Config\DataInterface
  => Magento\Framework\Config\Data
* Magento\Framework\Config\ReaderInterface
  => Magento\Framework\Config\Reader\Filesystem
* Magento\Framework\Config\ConverterInterface
  => Magento\Framework\Config\Converter\Dom

The one that is missing is a generic implementation of the schema locator
interface Magento\Framework\Config\SchemaLocatorInterface

This PR adds such a generic implementation.
@piotrekkaminski
Copy link
Contributor

Thanks Vinai!

@vrann
Copy link
Contributor

vrann commented Jul 14, 2015

@Vinai thanks, this might be helpful feature.

@magento-team magento-team merged commit dd4e82a into magento:develop Jul 17, 2015
@Vinai Vinai deleted the generic-schema-locator branch July 18, 2015 10:23
magento-team pushed a commit that referenced this pull request Aug 16, 2017
Fixed issues:
- MAGETWO-70571 There is no possibility to activate DEBUG logging in production mode
- MAGETWO-70806 The Recently Viewed widget UI issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants