Home  >  Article  >  Development Tools  >  Easily overlooked knowledge about composer

Easily overlooked knowledge about composer

藏色散人
藏色散人forward
2020-02-19 17:10:391681browse

The following tutorial column of composer will introduce you to the easily overlooked knowledge about composer. I hope it will be helpful to friends in need!

Easily overlooked knowledge about composer

1.composer version number~ ^ *

(1) Package version: *

{
"require": {
    "monolog/monolog": "1.0.*"
}
}

1.0.* This means any slave Development branches starting with 1.0 will match 1.0.0, 1.0.2 or 1.0.20.

(2) Package version: ~

~1.2 is equivalent to >=1.2,7257b415a1bc097368dd949d3a0da72c=1.2.3 <1.3, which matches the first 2 digits 1.2

2.composer install

(1) If composer.lock already exists, read composer.lock to download dependencies.

(2) If there is no composer.lock file, read the composer.json file, process the dependencies, and install it into the vendor directory.

That is to say, if you have a copy of composer.lock locally, you can ensure that no matter how long it takes, you can pull the same dependencies.

So composer.lock should be placed in the git repository. This can ensure that everyone and every computer in your project, no matter what system, can pull the exact same dependencies to reduce Impact of potential dependencies on deployment.

3.composer update

Read the dependencies specified in composer.json, then pull the dependencies into the vendor directory, and write the exact version numbers of all pulled dependencies into composer .lock file.

(1)So when do you need to use composer update?

For example, when a new version released by an extension has new features we need, then we need to update the extension. When we update, we specify the specific updated extension name, such as composer update package instead of composer update directly. Because after direct composer update, all extensions will be updated, which is very risky.

4. Summary:

(1) composer update is updated according to composer.json, and writes the extended version number into composer.lock.

(2) composer install is updated according to composer.lock

(3) Use composer update less during the development process, composer install

should be used (4) If new To add a package, you can use: composer require "package name: version number"

For more composer-related technical articles, please visit the composer column: https://www.php .cn/tool/composer/

The above is the detailed content of Easily overlooked knowledge about composer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete