Packagist
The PHP Package Repository
Composer 提供php專案開發時,套件、函式庫的相依性管理,也提供函式庫函式的下載安裝,Composer 取用套件時預設的來源庫( Repository )就是Packagist,我們可以在Packagist 尋找適合的套件應用在我們的專案裡,或者參考這些套件的開源碼。如同GitHub一樣,Packagist也提供付費版本的 private packagist。
How to submit packages?
我們也可以貢獻自己開發的開源函式庫套件,原則上您需要建立一組Packagist帳號,並綁定GitHub帳號,並依照Composer專案宣告方式製作套件(如下),並push到Packagist即可。
先為您的套件取一個獨一無二的名稱 ( Vendor name / project name )
這是很重要的步驟,因為之後無法再修改,以下是取名原則的參考:
// Monolog is a library, so the vendor name and package name are the same.
monolog/monolog
// That could be the name of a drupal module (maintained/provided by monolog,
// if the drupal team did it, the vendor would be drupal).
monolog/monolog-drupal-module
// Acme is a company or person here, they can name their package with a common name (Email).
// As long as it's in their own vendor namespace it does not conflict with anyone else.
acme/email
產生一個composer.json
composer.json檔描述一個專案相依引用的套件名稱、版本範圍、套件,以及自動載入的PSR標準等,相同地在自己開發的套件也需要產生composer.json來描述,格式如下:
{
"name": "monolog/monolog", "type": "library", "description": "Logging for PHP 5.3", "keywords": \["log","logging"\], "homepage": "https://github.com/Seldaek/monolog", "license": "MIT", "authors": \[ { "name": "Jordi Boggiano", "email": "[email protected]", "homepage": "http://seld.be", "role": "Developer" } \], "require": { "php": ">=5.3.0" }, "autoload": { "psr-0": { "Monolog": "src" } }
}