Home > Article > Development Tools > 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!
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>
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:
<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>
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 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>
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:
<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.
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).
#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 命令允许你编辑 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>
选项:
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!