You can do it with a custom autoloader, since PHP can handle multiple autoloaders!
composer custom autoloader without adding autoload in composer.json
-
19-07-2023 - |
Vra
I'm refering to https://getcomposer.org/doc/01-basic-usage.md#autoloading
Probably all of the composer-users will add this into the composer.json to make it load custom namespaces:
{
"autoload": {
"psr-4": {"Acme\\": "src/"}
}
}
In my case my folder structure is completely the same as the namespaces, so \hello\world would refer to a class inside \hello\world. So, is there a way to tell composer he should search inside the directory with the same names like the namespaces, without telling it inside the composer.json? It's unnecessary expense!
Oplossing 2
Ander wenke
No, you can't do that.
If you want to use long paths resembling the exact namespace structure of your class, you can always use PSR-0 instead, which forces you to use these long directory names. But note that this has some slight drawbacks - traversing longer paths takes slightly more time.