You must use these Composer commands!
The following is the tutorial column of composer to introduce you to the common commands of Composer. I hope it will be helpful to friends in need!
selfupdate
Update composer itself, please perform composer selfupdate frequently to keep Composer always the latest version .
<span style="font-size: 16px;">composer selfupdate<br/></span>
is equivalent to
<span style="font-size: 16px;">composer self-update<br/></span>
dumpautoload
when we change the composer.json file When autoloading, you need to execute composer dumpautoload to make the autoload take effect immediately. Without having to execute install or update commands.
<span style="font-size: 16px;">composer dumpautoload<br/></span>
is equivalent to
<span style="font-size: 16px;">composer dump-autoload<br/></span>
The dumpautoload command has two commonly used options:
- --optimize (-o): Convert PSR-0/4 autoloading to classmap for faster loading. This is particularly suitable for production environments, but may take some time to run, so it is not currently the default.
- --no-dev: Disable autoload-dev rules.
install
<span style="font-size: 16px;">composer install<br/></span>
is defined based on the composer.lock (lock file) or composer.json file in the current directory. Dependencies, install dependent packages.
The install command will first check whether the composer.lock lock file exists. If it exists, it will download the version specified in the composer.lock file, ignoring the definition in the composer.json file.
<span style="font-size: 16px;"># 查看 composer install 的帮助信息<br/>composer install -h<br/><br/># 只安装 require 中定义的依赖,而不安装 require-dev 中定义的依赖<br/>composer install --no-dev<br/></span>
update
If you want to update your dependency version, or you modify the dependency relationship in composer.json, you want composer To perform update operations as defined in the composer.json file, use the update command.
<span style="font-size: 16px;">composer update<br/></span>
require
require command is generally used to install new dependency packages and write dependencies into the composer.json file in the current directory. .
If dependencies are added or changed in the composer.json file, the modified dependencies will be installed or updated.
<span style="font-size: 16px;">composer require<br/></span>
You can also directly specify the dependency packages that need to be installed in the command.
<span style="font-size: 16px;">composer require barryvdh/laravel-ide-helper<br/></span>
Install the specified version of the dependency package.
<span style="font-size: 16px;">composer require barryvdh/laravel-ide-helper:1.0<br/></span>
--dev option corresponds to require-dev. If your dependency package is only used in the development environment, it is recommended to add the --dev option.
<span style="font-size: 16px;">composer require --dev barryvdh/laravel-ide-helper<br/></span>
create-project
You can use create-project to create a new project from an existing package.
It is equivalent to installing the dependencies of this package into its own vendor directory after executing the git clone command.
This command has several common uses:
- You can quickly deploy your application.
- You can check out any resource pack and develop patches for it.
- For multi-person development projects, you can use it to speed up application initialization.
<span style="font-size: 16px;"># 安装 Laravel 项目<br/>composer create-project --prefer-dist laravel/laravel blog 5.5.*<br/></span>
If no version number is specified, the latest version will be installed by default.
--prefer-dist: Install from dist when a package is available.
search
The search command can search for remote dependent packages. Usually it only searches for packages on packagist.org. You can simply enter your search terms.
<span style="font-size: 16px;">composer search monolog<br/></span>
--only-name (-N) option, only searches for the specified name (exact match).
show
#To list installed dependency packages, you can use the show command.
<span style="font-size: 16px;">composer show<br/></span>
List all dependent packages on the mirror site.
<span style="font-size: 16px;">composer show --all<br/></span>
If you want to view detailed information about a specified dependent package, you can enter the package name.
<span style="font-size: 16px;">composer show monolog/monolog<br/></span>
config
config 命令允许你编辑 Composer 的一些基本设置,无论是本地的 composer.json 还是全局的 config.json 文件。
查看 Composer 的全局配置信息:
<span style="font-size: 16px;">composer config -g --list<br/></span>
语法:config [options] [setting-key] [setting-value1] ... [setting-valueN]
setting-key 是配置选项的名称,setting-value1 是配置的值。可以使用数组作为配置的值(像 github-protocols),多个 setting-value 是允许的。
例如,全局配置 Composer 的国内镜像:
<span style="font-size: 16px;"># 推荐使用阿里云 Composer 全量镜像<br/>composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/<br/></span>
选项:
- --global (-g): 操作 $COMPOSER_HOME/config.json 全局配置文件。如果不指定该参数,此命令将影响当前项目的 composer.json 文件,或 --file 参数所指向的文件。
- --editor (-e): 使用文本编辑器打开 composer.json 文件。默认情况下始终是打开当前项目的文件。当存在 --global 参数时,将会打开全局的 config.json 文件。
- --unset; 移除由 setting-key 指定的配置选项。
- --list (-l): 查看当前配置选项的列表。当存在 --global 参数时,将会显示全局配置选项的列表。
- --file="..." (-f):在一个指定的文件上操作,而不是 composer.json。它不能与 --global 参数一起使用。
run-script
run-script 命令,可用来手动执行脚本,只需要指定脚本的名称即可。
假如,composer.json 中存在如下脚本。
<span style="font-size: 16px;">{<br/> "scripts": {<br/> "post-update-cmd": "MyVendor\\MyClass::postUpdate",<br/> "post-package-install": [<br/> "MyVendor\\MyClass::postPackageInstall"<br/> ],<br/> "post-install-cmd": [<br/> "MyVendor\\MyClass::warmCache",<br/> "phpunit -c app/"<br/> ]<br/> }<br/>}<br/></span>
运行所有 post-install-cmd 事件下定义的脚本:
<span style="font-size: 16px;">composer run-script post-install-cmd</span><br/>
更多composer技术文章,请访问composer栏目!
The above is the detailed content of You must use these Composer commands!. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)
