-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Add autoloader root directory config #8387
Comments
For PHP 5.6+, the relevant file for the autoloader is not |
Thanks, I didn't know that. For me the main use case is the first one, however the second one was mentioned by some people in the linked issue. If it turns out to be solved already, that's great. |
What if you set vendor-dir to I'd rather avoid adding a new parameter for such a custom use case if it can be achieved with existing infrastructure. |
Hmm yeah no sorry re-reading the description I guess this isn't gonna work. I am not sure I fully understand what you are trying to achieve though, more details would be good to really see what the point is and whether it's something we want to support if it isn't yet. |
I find the arguments rather weak and lacking. In "modern" web development, one deploys build artifacts, not entire git repositories. So the structure of your git repository is irrelevant. This immediately solves both "issues" (separation of source and distribution files, and config files from build services and such). |
I've tried it and can confirm that that works. That leaves the first issue which I would like to solve I have a git repo of the following:
I would like to create (with any build system, I don't really care) a
But, by now, the path from "config": {
"autoloader-root-dir": "src/php/"
} and then autoloading would work in the build artifact directory. Why not just use Clearer now? I think the exact organization of the |
What you need to configure here is your webhosting's webroot to point to |
Thanks for the advice, I did not know that. However, unfortunately, this is not a good solution on its own - I can't set the webroot to |
Then put the build artifacts wherever you need, and make sure that's the web root, and that the web root contains an index.php which includes whatever path is needed so it finds vendor dir etc, even tho that should be in a separate directory. For example Symfony's standard distro has a web dir with app.php being the index file/front controller, you can see what's in the web dir, it should be only things that should be accessible by user browsers. And the web root should be web/ |
It baffles me this hasn't just been added yet. Just give people the flexibility instead of point towards web host configs. |
Yes, well, luckily we don't have to make decisions based on what baffles some individuals and what not. |
Current behaviour
composer.json
:Gives the following
vendor/composer/autoload_psr4.php
:Proposed behaviour
composer.json
:Would give the following
vendor/composer/autoload_psr4.php
:I.e. the generated file would look as if
composer.json
were in thesrc/php/
directory. Only descending the folder tree would be allowed, so you cannot do something like"autoloader-root-dir": "../somewhereElse/"
. The nameautoloader-root-dir
is tentative.Motivation
Built applications
In modern web development, codebases quite often use multiple languages, some of them compiled (typically something akin to TypeScript compiled to JavaScript). This means that the final application needs to be built. To cleanly separate the source files from the build artifacts, one would want to place all the source files into one directory (e. g.
src
) and have the built app in another one (e. g.dist
). However, thecomposer.json
file would typically be in the root of the repository - that is, not in thesrc
folder. Under the current behaviour, there is no way to do this, not have the final php files somewhere likedist/src/
and have a working autoloader. This RFC would enable that by setting"autoloader-root-dir": "src/"
.Separating configuration files from the application itself
When an app is deployed, sometimes it is undesirable to deploy configuration files such as
.travis-ci.yml
or similar. With this RFC, one could put the actual application in a dedicated directory (e. g.app/
), keep all the configuration files (includingcomposer.json
) in the root of the repo and still have a working autoloader by setting"vendor-dir": "app/vendor"
and"autoloader-root-dir": "app/"
.This issue is a continuation of the recent debate in #5198. I would be willing to take a try at a PR, if the feature is deemed appropriate for inclusion in composer.
The text was updated successfully, but these errors were encountered: