1. 程式人生 > >composer 常用命令總結

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": "
[email protected]
" } ], "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": "[email protected]"
        }
    ],
    "require": {
        "monolog/monolog": "1.21.*",
    }
}

然後通過如下命令進行安裝依賴

$ composer install

update (更新)

如果我們新增或者刪除了某個依賴,可以通過如下命令進行更新

$ composer update   

require (申明依賴)

我們也可以用命令直接新增依賴,執行該命令後將自動下載,命令如下:

$ composer require symfony/http-foundation