该命令用于建立 composer.json 文件,并进行基础信息配置:html
$ composer init
能够配置Package name、Description、Author、Minimum、Package Type、License、dependencies 及 dev dependencies 信息。git
完成后配置文件内容以下:github
{ "name": "test/test", "description": "test init", "type": "library", "license": "License Description", "authors": [ { "name": "mayanlong", "email": "json_vip@163.com" } ], "require": {} }
根据名称搜索相关的包,成功后会列出符合的相关包的信息,本处以搜索 monolog 为例:web
$ 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
根据包的名称,列出包的相关信息,本处以查看 monolog/monolog 为例:json
$ 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
想查看更多信息,就亲自将该命令复制到命令行执行吧。composer
咱们先在 composer.json 配置中添加一个 monolog/monolog 依赖库,以下:socket
{ "name": "test/test", "description": "test init", "type": "library", "license": "License Description", "authors": [ { "name": "mayanlong", "email": "json_vip@163.com" } ], "require": { "monolog/monolog": "1.21.*", } }
而后经过以下命令进行安装依赖ui
$ composer install
若是咱们新增或者删除了某个依赖,能够经过以下命令进行更新命令行
$ composer update
咱们也能够用命令直接添加依赖,执行该命令后将自动下载,命令以下:code
$ composer require symfony/http-foundation
本文首发于马燕龙我的博客,欢迎分享,转载请标明出处。 马燕龙我的博客:http://www.mayanlong.com 马燕龙我的微博:http://weibo.com/imayanlong 马燕龙Github主页:https://github.com/yanlongma