On Wed, Jul 3, 2024 at 11:11 PM Mike Schinkel <m...@newclarity.net> wrote:
> >> import 'file.php v1.0.0'; > > > > Where will PHP be able to get the version number in a performant manner? > > > > A question for another day. > > Frankly if your proposal hinges on using version numbers to differentiate > then I think it is not something you can postpone answering. > > If there is not a good answer then the approach you are exploring is moot, > at least as far as I can see. > > So I've had more time to mull this over, and some research, and I think I have an approach. First, instead of 'import', use 'require_module'. The parsing rules for require_module differ from require how the file is parsed, a subject for another time. Also, it's parallel to what is to follow. Speaking of new functions, let's start with these spl_set_include_ini_map('importmap.ini'); spl_set_include_json_map('importmap.json") The json file is pretty much identical to the JavaScript importmaps. The ini file looks like this root = "/absolute/path/to/application/root" [imports] square = "./path/to/square.js" circle = "./path/to/circle.js" other/ = "./path/to/other/" [scopes] \A[square] = './path/to/square/in/namespace/A/a.js' Whichever format is used is a matter of personal preference. The file can be, and likely should be, written by composer or some future package manager. The root attribute in the map sets the root for all relative paths given in the map. Imports are the standard imports for the project. The token on the left maps to the target on the right. Import maps affect all includes. Import map tokens are considered before anything use on the include resolution rules. So `include 'square'` would bring in '/absolute/path/to/application/root/path/to/square.js' given the ini file above. An import token ending in / is a prepend and the path it maps to must also end in a slash. So `require_module 'other/triangle.php' will map to '/absolute/path/to/application/root/path/to/other/triangle.php' given the ini file above. Scopes have a namespace followed by the token in brackets. Scopes only affect require_module as the other include mechanisms do not pay attention to namespaces. When in that namespace the specified file will be loaded instead of the default outlined in imports. The import map system is inspired by but not exactly like JavaScript's https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap This approach gets whatever RFC that comes out of this proposal out of the business of trying to design a package manager.