Home  >  Article  >  Development Tools  >  Share composer tips

Share composer tips

藏色散人
藏色散人forward
2019-09-07 13:55:112306browse

Composer is a tool used in PHP to manage dependencies. You can declare the external tool libraries you depend on in your project, and Composer will install these dependent library files for you. Below, the composer usage tutorial column will share with you some composer tips. I hope it will be helpful to friends in need!

Share composer tips

1. Only update a single library

composer update foo/bar

In addition, this technique can also be used to solve the "warning message problem". You must have seen this warning message:

Warning: The lock file is not up to date with the latest changes in composer.json, you may be getting outdated dependencies, run update to update them.

So what should we do? The update command can update the lock file, but if it only adds some descriptions, it should not update any libraries. In this case, just update nothing:

$ composer update nothing

In this way, Composer will not update the library, but it will update composer.lock. Note that nothing is not a keyword in the update command. There is just nothing this package causes. If you type foobar, the result is the same.

If the Composer version you are using is new enough, you can use the --lock option directly:

composer update --lock

2. Install the library without editing composer.json

You may find it too troublesome to modify composer.json every time you install a library, then you can use the require command directly

composer require "foo/bar:1.0.0"

3. Derivation is easy

When initializing, you tried create -project command?

composer create-project doctrine/orm path 2.2.0

This will automatically clone the repository and check out the specified version. This command is very convenient to use when cloning a library, as there is no need to search for the original URI.

4. If you want to download domestic mirrors, you need to add this code

"repositories": {
"packagist": {
  "type": "composer",
  "url": "https://packagist.phpcomposer.com"
}
}

The above is the detailed content of Share composer tips. 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