magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Eliminate XSD relative paths

Open alankent opened this issue 11 years ago • 3 comments

Currently XSD path references are file paths using ../../.. notation. This is not desirable. Relative paths impose physical file location constraints on your component, as well as for the component where the XML-schema resides. It denies flexibility of how you can deploy your component. There is also a separate plan to make it easier to locate modules in places other than under app/code (e.g. under 'vendor' as well), in which case the physical location of the XSD file cannot be guaranteed.

The plan is to move to absolute paths (possibly a URN) that the code knows how to resolve to a XSD on the file system. An approach based on just the filename (such as "layout.xsd") may also be possible.

Some have proposed it be a URL where the file is hosted publicly somewhere such as GitHub. This is not proposed. Instead it is proposed that developers are required to configure their development environment to map the XSD references to physical file locations.

Stage 1 of this work would be to propose a strategy friendly with the PHP code in developer mode using XSD files to validate XML files. This should be reviewed and signed off by the Magento team before implementation (to avoid wasted effort).

Stage 2 would be to implement the changes required.

For example, any module can introduce a new XSD for its own configuration that another module may then want to replace/extend. For example, one approach is to use something like urn:magento:xsd:Vendor:Module:v1.0:layout.xsd so the vendor/module name is in the path. Then the XSD reference is relative to the home directory of a module, wherever it is. The XML parsing library would need to be extended to map this form of schema reference to the actual filename of the XSD file.

Consideration should also be give to tools like PHP Storm and how easy it will be to configure them. Can PHP Storm import the equivalent of a SGML CATALOG file for mapping URIs to physical file locations?

alankent avatar Jan 30 '15 22:01 alankent

internal ticket MAGETWO-33621 and related comment.

There is no perfect solution here. We could host but questions arise on versioning, support for community schemas and this creates unnecessary complexities at this time. We could change to a URN but then action is required for every XSD in PHPStorm. We would also need to add support for the URN based resolution for our static tests. The relative path works for code within the app/code and we suspect that is how development of an extension will typically start. This is when validation against the XSD is most critical. When an extension is hosted in a separate repo, versioned and published independently the relative path is a problem but the user can configure PHPStorm to map to the schema in the project and validation can occur. In light of these details, I recommend no action at this time.

TexanHogman avatar Feb 20 '15 15:02 TexanHogman

Done now I belive? Just adding this note so it can be closed.

JamesAnelay avatar Nov 12 '15 23:11 JamesAnelay

Yes, this was done before merchant beta dropped. Also there is a command in the CLI tool to generate the meta data PHPStorm needs to follow the URNs.

davidalger avatar Nov 13 '15 01:11 davidalger