使用Composer时文件太多了?

There is something I don't understand about the use of Composer. To be clear, I am working on Windows 10 and from a wampstack package.

Inside ..wampstck..\php I rubbed out any existing folder \vendor

For one project I downloaded checkdomain/holiday from Packagist. I then moved \vendor to apache2\htdocs and finally transferred it, and the other files, via FTP to an external website where everything worked OK.

Then I did exactly the same proceedure for another package phpmailer/phpmailer. However in this case \vendor contained files not only for the mailer, but also for the earlier checkdomain/holiday which I hadn't touched for several weeks.

It seems that \vendor now contains sub-folders \composer, \phpmailer and \checkdomain. The latter two sub-folders contain a file composer.json which clearly contain material relating to that project and to nothing else.

\vendor\composer however contains a file called installed.json which refers to phpmailer, checkdomain (and, in truth, to every other package which I have looked at)

I have two questions :

  1. If I rubbed out the folder \C:....\php\vendor before I called down a new package from Packagist by writing at the Command prompt>composer require phpmailer/phpmailer, then how did the system know anything about, and that it should download, the \checkdoain package.

  2. I clearly have information going out to the web site which the project does not need. I FTP \vendor to the website, but it contains a folder \composer which has this file called installed.json which contains information about previous projects and cannot be needed.

Your project's dependency, class map, and other definitions are stored in your project's composer.json file. When you are in your project root and you type composer require package that composer.json file is updated with the new requirements. To answer your first question, this dependency probably still exists in your project's composer.json file or it exists as a dependency to phpmailer in their composer.json file.

The currently installed packages are tracked in composer.lock, so you can copy composer.lock and composer.json to a new environment and type composer install to install the same package versions. Ideally, you would do this instead of copying the vendor folder to a new environment (provided you have more than FTP access).

I think you're overthinking this whole thing, just let Composer manage the packages and don't try to manage files manually. The point of Composer is to manage packages and their dependencies for you. To answer your second question, why does it matter if you transfer a few extra small files? Just seems like you're creating an unnecessary headache for yourself.

In short, don't delete or modify files in the vendor directory. The way you remove a dependency is through the command line tool: composer remove package or editing composer.json and updating with composer update.

One thing you can do to make your vendor folder easier to deploy to a web server is package the entire vendor folder into a .phar file. https://github.com/mpyw/comphar. This allows you to have a faster deploy when copying via ftp or something else. Also it will eat less of your file limits on your web host.