該命令用於建立 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