Composer 常用命令总结(三)
init(初始化)
该命令用于创建 composer.json 文件,并进行基础信息配置:
$ composer init
可以配置Package name、Description、Author、Minimum、Package Type、License、dependencies 及 dev dependencies 信息。
完成后配置文件内容如下:
{
"name": "test/test",
"description": "test init",
"type": "library",
"license": "License Description",
"authors": [
{
"name": "mayanlong",
"email": "json_vip@163.com"
}
],
"require": {}
}
search(搜索)
根据名称搜索相关的包,成功后会列出符合的相关包的信息,本处以搜索 monolog 为例:
$ composer search monolog
monolog/monolog Sends your logs to files, sockets, inboxes, databases and various web services
kdyby/monolog Integration of Monolog into Nette Framework
show(详情)
根据包的名称,列出包的相关信息,本处以查看 monolog/monolog 为例:
$ composer show -all monolog/monolog
name : monolog/monolog
descrip. : Sends your logs to files, sockets, inboxes, databases and various web services
keywords : log, logging, psr-3
versions : dev-master, 2.0.x-dev, 1.x-dev, 1.21.0, 1.20.0, 1.19.0, 1.18.2, 1.18.1, 1.18.0, 1.17.2, 1.17.1, 1.17.0, 1.16.0, 1.15.0, 1.14.0, 1.13.1, 1.13.0, 1.12.0, 1.11.0, 1.10.0, 1.9.1, 1.9.0, 1.8.0, 1.7.0, 1.6.0, 1.5.0, 1.4.1, 1.4.0, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.2, 1.0.1, 1.0.0, 1.0.0-RC1
想查看更多信息,就亲自将该命令复制到命令行执行吧。
install (安装)
我们先在 composer.json 配置中添加一个 monolog/monolog 依赖库,如下:
{
"name": "test/test",
"description": "test init",
"type": "library",
"license": "License Description",
"authors": [
{
"name": "mayanlong",
"email": "json_vip@163.com"
}
],
"require": {
"monolog/monolog": "1.21.*",
}
}
然后通过如下命令进行安装依赖
$ composer install
update (更新)
如果我们新增或者删除了某个依赖,可以通过如下命令进行更新
$ composer update
require (申明依赖)
我们也可以用命令直接添加依赖,执行该命令后将自动下载,命令如下:
$ composer require symfony/http-foundation