Home>Article>Development Tools> Recommend six little-known Composer commands

Recommend six little-known Composer commands

步履不停
步履不停 Original
2019-06-26 18:25:20 3430browse

Recommend six little-known Composer commands

Composer is a dependency management tool for PHP. If you are a PHP developer, then you probably use it every day and frequently run the commandsrequire,installandupdate. Maybe you didn't realize it, but we can use some otherComposer commandsto make it easier to use.

There are many commands you can use, but today I will share 6 commands that I use and that help me every day.

show

Let’s talk about theshowcommand first. It allows you to view all installed packages for your project (including dependencies), as well as view descriptions of related packages. All this information can be found in the Composer lock file (composer.lock), but using theshowcommand is a relatively simpler and more convenient way to view package information.

To list all installed packages with their version numbers and descriptions, just useshow:

composer show

Sometimes this information is presented in the form of a dependency tree It will be easier to understand if you view it. You can pass--treeor-tParameters:

composer show -t

If you want to filter the returned packages, you can use wildcards to pass an extra character String parameters*:

composer show 'symfony/*'

This will return all installed symfony packages. Pay attention to the quotation marks here. If you are using the bash shell, you do not need to add these quotation marks, but if you are using zsh and you do not need the quotation marks, a ‘no matches found’ error will be reported.

If you want to see information about a specific package, the full package name is required:

composer show laravel/framework

This will show you the version installed, its license and dependencies, and where it is installed locally and other information.

why

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

composer why vlucas/phpdotenv

whywhy is an alias for the depends command, but personally I find it easier to remember using 'why'. You can view this information in a dependency tree using the--treeor-tflag:

composer why vlucas/phpdotenv -t

why-not

Sometimes, one or Multiple installed packages will prevent the package from being installed or updated. In order to check which installation packages we can use thewhy-notcommand (aliasprohibits). For example, Laravel recently released a new 5.8 version of the framework; we can use thewhy-notcommand to check for any packages that are preventing us from updating thelaravel/frameworkpackage:

composer why-not laravel/framework 5.8

Similarly, we can view this information in the dependency tree using the--treeor-ttags:

composer why-not laravel/framework 5.8 -t

outdated

at Before using thecomposer updatecommand, you may want to check the installed packages to see which ones can be upgraded. This can be done using theoutdatedcommand.

composer outdated

This command is one of the aliases ofcomposer show -lo.

According to the semantic version, color code is returned to indicate the status of each package:

  • Green:The current installation package is the latest version
  • Yellow:There are upgradeable updates, but there may be incompatible modifications.
  • Red:There are minor version upgrades available (usually bug fixes)

If you want to highlight minor upgrades, you can useoutdatedcommand, with--minor-onlyor-mParameters:

composer outdated -m

Status

I find myself using # all the time ##install,updatecommand parameters--prefer-sourceto 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. Thestatuscommand provides a convenient method.

You can use the

--verboseor-vparameters to view locally modified packages and files:

composer status -v
I found that using the verbose tag is the most useful way to use this command.

License

Finally, it is very useful to know the license of each package you install. Composer has a convenient

licensescommand for querying the complete list of licenses:

composer licenses

For more related composer tutorial articles, please visit the

composer usage tutorialcolumn!

The above is the detailed content of Recommend six little-known Composer commands. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What is php composer? Next article:What is php composer?