Simple explanation
composer install
-If you have composer.lock files, install them directly, otherwise install the latest expansion pack and dependencies from Composer.json;
composer update
-Install the latest expansion packs and dependencies from Composer.json;
composer update vendor/package
-From the Composer.json or the corresponding package configuration, and update to the latest;
composer require new/package
-Add installation new/package
, you can specify the version, such as: Composer require new/package ~2.5.
Process
Next, we will introduce several daily production processes to facilitate the understanding.
Process one: New project flow
- Create
composer.json
, and add dependencies to the extension package;
- Run
composer install
, install the expansion pack and generate it composer.lock
;
- Commit
composer.lock
to the code version controller, such as: git;
Process two: Project collaborators install existing projects
- After cloning the project, the root directory runs directly
composer install
from the composer.lock
installed 指定版本
expansion pack and its dependencies;
This process applies to deployment of production environment code.
Process three: Add a new expansion pack for a project
- Use
composer require vendor/package
add expansion packs;
- Commit the updated
composer.json
and composer.lock
to the code version controller, such as: git;
About the Composer.lock file
composer.lock
The file maintains a version record (see) that is dependent on each code, commits to the version controller, and works together to composer install
ensure consistency of the code versions that are running in the team's developer environment and the online production environment.
About installation methods for expansion packs
So, ready to add an extension package, install, update, require three commands can be used to install the expansion package, choose which is the right one?
The answer is: Use the composer require
command
In addition, after you manually modify the Composer.json Add Expansion pack, composer update new/package
you can specify the way to update the extension package, but also the correct installation, but this method is not recommended, because once you forget to finalize the extension package name, you will enter the state of perdition, do not give yourself a hole.
The above concepts are confusing to both novice and veteran, primarily remembering this concept:
Existing projects are newly added and expanded, and are used in composer require new/package
this way to install.
Finish.
"Go" to the correct Composer expansion pack installation method