Today, Magento 2 uses relative file paths for XSD references. Apart from being ugly, this imposes directory structure restrictions. For example, if we want to put Composer packages under ‘vendor’ in the future, the relative paths would break. So we are looking towards using absolute paths for the XSD references. The question is what is the best way to achieve this.
A common approach is to use a real HTTP based URL that can be resolved. That way tools can go fetch the XSD referenced by the URL. There are however negatives
- You need to host this at a URL that will never change. Doable, but it does impose restrictions while developing XSDs. (Possible example, http://magento.com/xsd/2.0.0/layout.xsd. Hoping GitHub never goes away, you could do a GitHub based URL instead.)
- It can cause problems while an XSD is under development. If the XSD is in your Git repo, you can version it with your system (which is particularly useful during the development phase).
- There is a risk that your installation may be downloading the file when you don’t expect it. We ship the file with Magento, ideally tools should fetch it from the local file system for speed. I have encountered (non-Magento) sites where production was being slowed down due to mis-configuration and the XSD file was being downloaded repetitively.
- It can represent a denial of service attack on whoever hosts the file. Remember there are a lot of Magento sites out there. All of them hitting the central XSD file can add up if it is not cached properly.
There are several solutions.
- Use a URN. We come up with our own scheme and have a path that looks something like Vendor/Module/file.xsd (maybe plus a version number).
- Use a URL, but don’t actually make it resolvable. That is, it looks like a URL but if you type it into a web browser nothing will be downloaded.
- Don’t include a path (just use “layout.xsd”) and have tools map that to the real file path. (This is the old idea of a “SYSTEM” path for DTDs.)
Having been bitten by production issues in the past with the XSD schema references hitting the internet by personal bias is away from using a HTTP based identifier, but I will admit I may just be jaded. Having the path also be resolved by your local installation does help while XSD’s are not yet stable. But what is your opinion? Please vote or leave a comment if you have practical experience you think is relevant.
Oh, and those who want to read up on what PHP Storm supports, try https://www.jetbrains.com/idea/help/referencing-dtd-or-schema.html. It would be nice if we could ship with Magento the mapping file from URIs to local file paths to reduce the developer setup effort. Like a CATALOG file from the good old days of SGML.