Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Composer tips PHP developers should know?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what Composer tips PHP developers should know". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "what Composer tips PHP developers should know"!

1. Update only a single library

Just want to update a particular library, not all of its dependencies, is simple:

composer update foo/bar

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.

Damn, what's wrong? Don't panic! If you edit composer.json, you should see something like this. For example, if you add or update details such as the library description, author, more parameters, or even just add a space, it changes the md5sum of the file. Composer will then warn you that the hash value differs from that recorded in composer.lock.

So what do we do? The update command updates the lock file, but if you add only a few descriptions, you probably don't intend to update any libraries. In this case, just update nothing:

$ composer update nothingLoading composer repositories with package information Updating dependencies Nothing to install or update Writing lock file Generating autoload files

This way, Composer does not update the library, but composer.lock. Note that nothing is not a keyword in the update command. Just nothing this package causes results. If you type foobar, the result is the same.

If your Composer version is new enough, you can use the--lock option:

composer update --lock2. Install the library without editing composer.json

You may find it too much trouble to modify composer.json every time you install a library, so you can simply use the require command.

composer require "foo/bar:1.0.0"

This method can also be used to quickly open a new project. The init command has the--require option, which automatically writes composer.json: (note that we use-n so we don't have to answer questions)

$ composer init --require=foo/bar:1.0.0 -n$ cat composer.json{ "require": { "foo/bar": "1.0.0" }}3. Derivation is easy.

Have you tried the create-project command during initialization?

composer create-project doctrine/orm path 2.2.0

This automatically clones the repository and checks out the specified version. This command is handy when cloning libraries, eliminating the need to search for the original URI.

4. Consider caching, dist packages first

Composer for the last year automatically archives dist packages you downloaded. By default, dist packages are used for tagged versions, such as "symfony/symfony": "v2.1.4", or wildcards or version intervals,"2.1.* "or">=2.2,=2.2,

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report