Open aleksandr-yulin opened 5 years ago
/cc @phalcon/zephir-team
I'd probably call the key namespace-paths
instead of autoload
, since we're not actually implementing an autoloader. But I like this approach:
{
"extension-name": "my_ext_name",
"namespace-paths": {
"VendorName\\ProjectName": "lib",
"VendorName\\ProjectName2": "lib2" // https://github.com/phalcon/zephir/issues/1883
}
...
}
Any PR should, of course, add the namespace-paths
key and logic, not replace the existing namespace
key and logic. That probably means refactoring the existing logic to support either convention, but as long as both the new and old ways are supported simultaneously, that's perfectly fine.
I agree with @danhunsaker
Something like that ?
./vendor/bin/zephir init Mylib\\First lib
"namespace": "",
"namespace-paths": {
"Mylib\\First\\": "lib"
},
"name": "mylib_first",
lib-path/
ext/
kernel/
lib/
config.json
But which solution would be good for the name of the extension if there are several?
"namespace": "",
"namespace-paths": {
"Mylib\\First\\": "lib",
"Mylib\\Second\\": "lib2"
},
"name": "mylib_first",
in this case will be created two or one extension?
Always one extension, no matter how many namespaces.
Also, if namespace-paths
is used, namespace
should not be.
Yep, but how about this issue #1883 ? I thought that they wanted to make two extensions from one project
Also, if namespace-paths is used, namespace should not be.
I thought something like that for compatibility:
private function checkDirectory()
{
$namespace = $this->config->get('namespace');
$namespaces = $this->config->get('namespace-paths');
if (empty($namespaces) && !empty($namespace)) {
if (is_string($namespace) === false) {
throw new Exception(
sprintf('Invalid namespace config param, expected string, got %s',
is_object($namespace) ? get_class($namespace) : gettype($namespace)
)
);
}
$namespaces[$namespace] = $namespace;
}
Ah. Missed that detail, somehow. In that case, I have a slightly different idea.
{
"extensions": {
"mylib_first": {
"namespace": "Mylib\\First\\",
"path": "lib"
},
"mylib_second": {
"namespace": "Mylib\\Second\\",
"path": "lib2"
}
},
...
}
And of course if extensions
is used, name
and namespace
are not. Or maybe anything in extensions
is used to override values in the root level of the structure? Allowing most/all settings available in the root to be overridden for any one extension, but otherwise apply to everything? Hard to think of a scenario where name
and namespace
wouldn't need to be unique across extensions...
Hard to think of a scenario where name and namespace wouldn't need to be unique across extensions...
Yep, but it is possible. The simple solution is refuse to using name
and namespace
on root level. Or we add path
on root level too...
"namespace": "Mylib\\First\\",
"name": "mylib_first",
"path": "lib",
// if extensions not empty then root level was ignored
"extensions": {
"mylib_first": {
"namespace": "Mylib\\First\\",
"path": "lib"
},
"mylib_second": {
"namespace": "Mylib\\Second\\",
"path": "lib2"
}
},
What the difference extension-name
and name
into config file? May Be used one?
I'd prefer not adding path
to the root options; we can auto populate the value using the current logic internally, if we need to, but it shouldn't be configurable by the user at that level.
and what to do with the configuration of dependencies?
such as constants-sources
, prototype-dir
, extra-sources
, requires
and etc...
they may be different for extensions
have a suggestion:
1) add path
to the root level form resolve this issue(for resolve this exception)
2) for multi extensions use its own configuration file
root-path/
ext/
kernel/
lib-first/
config.json
lib-second/
config.json
I have no idea how to do it otherwise
What say we support all config options in extensions.*
the same as we do at the root, except of course for the few that don't make sense nested (extensions
itself, for example), and use the top-level versions as defaults that propagate down unless overridden? And then, just for the sake of conciseness, allow each extensions
value to either be an object ({...}
) or a string path to the additional config file for that extension ("lib-first/config.json"
).
Also, I retract my previous statement about not supporting path
at the root level. May as well try to be consistent. (What I said earlier about computing it internally is still valid. Even if we didn't let users set something directly themselves, we would still set it internally in our own data structures. 'Not in the JSON' isn't the same as 'not in the array'.)
From documentation
How about organize class autoload in
config.json
likecomposer.json
? Composer can provide classes from any path:So why not do something like this:
Pretty project folder structure
Exist project folder structure
If you approve this, i can provide request for this issue in future