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 commands?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail what the composer command has, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

Composer is a dependency management tool for PHP. If you are a PHP developer, you probably use it daily and run the commands require, install, and update frequently. Perhaps you don't realize it, but we can use some other Composer commands to make it easier to use.

It has many commands to use, but today I'm going to share 6 commands that I use and help every day.

show

Let's start with the show command. It allows you to view all installed packages for your project (including dependencies), as well as to view descriptions of related packages. All of this information can be found in the Composer lock file (composer.lock), but using the show command is a relatively simple and convenient way to view package information.

To list all installed packages with their version numbers and descriptions, simply use show:

composer show

Sometimes it's easier to understand this information by viewing it as a dependency tree, which can be accessed via the--tree or -t parameter:

composer show -t

If you want to filter the returned packages, you can pass an extra string parameter *: using wildcards

composer show 'symfony/*'

This will return all installed symfony packages. Note the quotes here, if you are using bash shell, you don't need these quotes, but if you are using zsh you will get a 'no matches found' error if you don't use quotes.

To view information about a particular package, you need the full package name:

composer show laravel/framework

This will show you the version of the installation, its licenses and dependencies, and where it is installed locally.

why

If you want to know why a particular package is installed, you can use the why command to determine which dependencies require it:

composer why vlucas/phpdotenv

Why is an alias for the depends command, but personally I find it easier to remember using 'why'. You can view this information in the dependency tree using the--tree or-t flag:

composer why vlucas/phpdotenv -t

why-not

Sometimes, one or more installed packages will prevent the installation or update of the package. To check which packages are installed, we can use the why-not command (alias prohibits). For example, Laravel version 5.8 of the framework; we can use the why-not command to check for any packages that prevent us from updating the laravel/framework package:

composer why-not laravel/framework 5.8

Similarly, we can view this information in the dependency tree using the--tree or-t tag:

composer why-not laravel/framework 5.8 -t

outdated

Before using the composer update command, you may want to check which packages are installed and which can be upgraded. This can be done using the outdated command.

composer outdated

This command is one of the aliases for composer show -lo.

Returns colored code indicating the status of each package, based on the semantic version:

Green: The current installation package is the latest version Yellow: Upgradable updates, but possibly incompatible modifications. Red: minor version upgrades available (usually bug fixes)

If you want to highlight minor upgrades, you can use the updated command with the--minor-only or-m argument:

composer outdated -m

state

I often find myself using the parameter--prefer-source of the install, update command to handle source code installation dependencies. Then, if I modify any of these dependencies, I need a way to quickly check which packages have been modified. The status command provides a convenient method.

You can use the--verbose or-v parameter to view locally modified packages and files:

composer status -v

I found using the verbose tag to be the most useful way to use this command.

license

Finally, it is useful to know the license for each package you install. Composer has a handy licenses command for querying the complete list of licenses:

composer licenses

About "composer command what" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

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

Internet Technology

Wechat

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

12
Report