Share composer tips

藏色散人
Release: 2019-09-07 13:55:43
forward
2334 people have browsed it

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
Copy after login

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.
Copy after login

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
Copy after login

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
Copy after login

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"
Copy after login

3. Derivation is easy

When initializing, you tried create -project command?

composer create-project doctrine/orm path 2.2.0
Copy after login

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"
}
}
Copy after login

The above is the detailed content of Share composer tips. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template