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 skills of PHPer?

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

Share

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

This article introduces the relevant knowledge of "what are the Composer skills of PHPer". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Update only a single library

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

Composer update foo/bar

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

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 a message like this. For example, if you add or update details, such as the description of the library, the author, more parameters, or even just adding a space, it will change the md5sum of the file. Then Composer will warn you that the hash value is different from that recorded in composer.lock.

So what are we going to do? The update command can update the lock file, but if you just add some descriptions, you should not plan to update any libraries. In this case, just update nothing:

$composer update nothingLoading composer repositories with package informationUpdating dependenciesNothing to install or updateWriting lock fileGenerating autoload files

In this way, Composer does not update the library, but does update composer.lock. Note that nothing is not the keyword of the update command. It's just the result of not having the nothing package. If you type foobar, the result is the same.

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

Composer update-lock

two。 Install the library without editing composer.json

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

Composer require "foo/bar:1.0.0"

This method can also be used to quickly start a new project. The init command has the-- require option, and you can write composer.json automatically: (note that we use-n so that 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. It is convenient to use this command when cloning the library, so there is no need to search for the original URI.

4. Consider caching, dist package first

The Composer of the last year will automatically archive the dist package you downloaded. By default, the dist package is used for versions with tag added, such as "symfony/symfony": "v2.1.4", or wildcards or version ranges, "2.1.*" or "> = 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