search
HomeDevelopment ToolscomposerDon't you know how to use these composer commands? Collect quickly!

You need to know these composer commands! Below, composer uses the tutorial column to introduce commonly used composer commands to you. I hope it will be helpful to friends in need!

Don't you know how to use these composer commands? Collect quickly!

#Composer is a dependency management tool for PHP. If you are a PHP developer, then you probably use it every day and run the commands require, install and update frequently. In case you didn't realize it, we can use some other Composer commands to 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 the show command 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 the show command is a relatively simpler and more convenient way to view package information.

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

composer show

Sometimes put these It will be easier to understand if the information is viewed in the form of a dependency tree. You can pass the --tree or -t parameter:

composer show -t

If you want to filter the returned package, you can pass an additional string argument using wildcards *:

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, you need the full package name:

composer show laravel/framework

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

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

why 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 package from being installed or updated. To check which packages are installed, we can use the why-not command (alias prohibits). For example, Laravel 5.8 version 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
Again, we can view this information in the dependency tree using the --tree or -t flag:

composer why-not laravel/framework 5.8 -t
outdated

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

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

Return coloring codes to indicate the status of each package according to the semantic version:

Green: 当前安装包已是最新版本

Yellow: 有可升级的更新, 但可能有不兼容的修改。

Red: 有可用的小版本升级 (一般是bug修复)

If you want to highlight small upgraded versions, you can use the outdated command with -- minor-only or -m parameter:

composer outdated -m

status

I find that I often use the parameters of the install and update commands - -prefer-source to handle dependencies installed from source. 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 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 licenses command for querying the complete list of licenses:

composer licenses

For more composer-related technical articles, please visit composertutorialcolumn!

The above is the detailed content of Don't you know how to use these composer commands? Collect quickly!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
Composer: A Comprehensive Guide to PHP Package ManagementComposer: A Comprehensive Guide to PHP Package ManagementMay 11, 2025 am 12:17 AM

Composer is a PHP dependency management tool that manages project dependencies through composer.json file. 1. Use composerinit to initialize the project. 2. Add dependencies such as composerrequireguzzlehttp/guzzle. 3. Advanced usage includes configuring private repositories and using script hooks. 4. Common errors such as dependency conflicts can be debugged through the composerwhy-not command. 5. Performance optimization is recommended to use composerinstall-prefer-dist and periodically update dependencies.

Composer in Action: Automating Dependency ResolutionComposer in Action: Automating Dependency ResolutionMay 10, 2025 am 12:22 AM

Composer simplifies dependency management of PHP projects through automated dependency parsing. 1) Read composer.json to resolve dependency requirements; 2) Build a dependency tree to handle version conflicts; 3) Download and install dependencies from Packagist to the vendor directory; 4) Generate composer.lock to ensure dependency consistency, thereby improving development efficiency.

AI and Composer: Enhancing Code Quality and DevelopmentAI and Composer: Enhancing Code Quality and DevelopmentMay 09, 2025 am 12:20 AM

In Composer, AI mainly improves development efficiency and code quality through dependency recommendation, dependency conflict resolution and code quality improvement. 1. AI can recommend appropriate dependency packages according to project needs. 2. AI provides intelligent solutions to deal with dependency conflicts. 3. AI reviews code and provides optimization suggestions to improve code quality. Through these functions, developers can focus more on the implementation of business logic.

What Defines a Composer: Understanding the RoleWhat Defines a Composer: Understanding the RoleMay 08, 2025 am 12:07 AM

Composers are people who express emotions, tell stories or express ideas by creating musical works, whose roles include conceiving musical structures, choosing instrument combinations, and working with other musicians. 1) Composers will go through four stages of conception, creation, modification and improvement during the creative process; 2) They need to master musical theories, such as harmony, counterpoint and melody, to ensure the quality and effect of the work.

Composer: Installing, Updating, and Managing DependenciesComposer: Installing, Updating, and Managing DependenciesMay 07, 2025 am 12:07 AM

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json and composer.lock files. 1. Install Composer: Run a specific command and move composer.phar to the system path. 2. Update Composer: Use composelself-update command. 3. Dependency management: add dependencies through the composerrequire command, automatically update relevant files and download packages.

AI-Powered Composer: Code Generation and AnalysisAI-Powered Composer: Code Generation and AnalysisMay 06, 2025 am 12:11 AM

AI plays an important role in code generation and analysis: 1) generate code through machine learning and NLP, such as GitHub’s Copilot; 2) perform code analysis, identify bugs and optimization suggestions, such as SonarQube; 3) improve development efficiency and code quality, but requires manual review and optimization.

Composer: AI-Powered Tools and IntegrationsComposer: AI-Powered Tools and IntegrationsMay 05, 2025 am 12:11 AM

Composer itself does not include AI capabilities, but can be enhanced by AI tools. 1) AI can analyze composer.json files, and it is recommended to optimize dependencies and predict version conflicts. 2) AI-driven platforms such as GitHubCopilot can provide real-time code suggestions to improve development efficiency. When using AI tools, you need to verify and adjust them in combination with actual situations.

The Attributes of a Successful ComposerThe Attributes of a Successful ComposerMay 04, 2025 am 12:13 AM

The key traits of a successful composer include: 1) rich creativity and imagination, 2) solid mastery of technical skills and tools. These traits are similar to creative and structured thinking in programming, helping composers realize creativity and optimize their work in music creation.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools