Learning Install GitHub Project By Composer
動態Badges (poser.pugx.org), (*2)
, (*3)
靜態Badges (shields.io), (*4)
$ cd ~/work/github/ $ git clone git@github.com:marshung24/my-composer.git
$ cd ~/work/github/my-composer $ composer init
$ git add ./ $ git commit -m 'init package' $ git push origin master
最后一步需要加origin master参数的原因是空仓库是没有分支的,所以我们需要强制推送本地的master到远端的master,在这之后可以直接用git push命令推送而不需要加后面的参数了。, (*5)
{ "name": "marshung/my-composer", "description": "Learning Install GitHub Project By Composer", "homepage": "https://github.com/marshung24/my-composer", "type": "library", "license": "MIT", "authors": [ { "name": "Mars Hung", "email": "tfaredxj@gmail.com" } ], "autoload": { "psr-4": { "marshung\\": "src" } }, "minimum-stability": "stable", "require": {} }
$ cd ~/work/github/my-composer/ $ mkdir src $ cd src/ $ mkdir hello $ cd hello/ $ touch HelloWorld.php
```php= <?php, (*6)
namespace marshung\hello;, (*7)
class HelloWorld { private $name; public function __construct($name = 'World') { $this->name = $name; } public function getName() { return $this->name; } public function hello() { return 'Hello ' . $this->name . '!'; } }, (*8)
## 提交前測試程式是否有問題
$ cd ~/work/github/my-composer/ $ composer install, (*9)
## 建立測試文件
$ cd ~/work/github/my-composer/ $ mkdir test $ cd test/ $ touch test.php, (*10)
```php= <?php require_once "../vendor/autoload.php"; $obj = new \marshung\hello\HelloWorld(); echo $obj->hello(); echo "\n"; $obj = new \marshung\hello\HelloWorld('My Goddess'); echo $obj->hello();
訪問Packagist主頁,確認自己已經登錄,然後點擊右上角大大的Submit Package,然後填入我們創建的倉庫的地址,點擊Check,然後沒問題,再點擊Submit。, (*11)
網址:https://packagist.org/, (*12)
$ cd ~/work/github/test $ composer require marshung/my-composer
$ cd ~/work/github/my-composer $ git branch
$ git checkout -b 0.1 $ git commit -m 'update readme, add Hello class demo' $ git push origin 0.1
$ git tag 0.1.0 $ git push --tags