2017 © Pedro Peláez
 

project my-composer

Learning Install GitHub Project By Composer

image

marshung/my-composer

Learning Install GitHub Project By Composer

  • Sunday, April 15, 2018
  • by marshung24
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

練習GitHub+Composer+Packagist

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

動態Badges (poser.pugx.org), (*2)

plastic plastic plastic, (*3)

靜態Badges (shields.io), (*4)

練習內容

  • Git Repository 建立
  • composer套件架構
  • 發佈到 packagist.org
  • 安裝並使用
  • READMD編寫

Git Repository 建立

在GitHub上建立Repository

clone回本地端

$ cd ~/work/github/
$ git clone git@github.com:marshung24/my-composer.git

初始化composer.json

$ cd ~/work/github/my-composer
$ composer init

建立README.md

推送回GitHub

$ git add ./
$ git commit -m 'init package'
$ git push origin master

最后一步需要加origin master参数的原因是空仓库是没有分支的,所以我们需要强制推送本地的master到远端的master,在这之后可以直接用git push命令推送而不需要加后面的参数了。, (*5)

composer套件架構

composer.json

  • 套件根目錄建立 composer.json
{
    "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": {}
}

建立class

$ 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.org

訪問Packagist主頁,確認自己已經登錄,然後點擊右上角大大的Submit Package,然後填入我們創建的倉庫的地址,點擊Check,然後沒問題,再點擊Submit。, (*11)

網址:https://packagist.org/, (*12)

設定 GitHub Service Hook

安裝並使用

$ cd ~/work/github/test
$ composer require marshung/my-composer

版本管理

Composer的版本管理

  • 開發版: branch
    • 如分支名為 mastar 時,版本號為 dev-master
  • 正式版: tag
    • 格式: major.minor.build
    • major: [int] 當做了不相容的修改
    • minor: [int] 當做了向下相容的功能性新增
    • build: [int] 當做了向下相容的問題修正

查看現在分支

$ cd ~/work/github/my-composer
$ git branch

建立新分支0.1(dev)

$ git checkout -b 0.1
$ git commit -m 'update readme, add Hello class demo'
$ git push origin 0.1

建立stable版本(tag)

$ git tag 0.1.0
$ git push --tags

參考

記錄

  • 20180414: MarsHung 建立專案
  • 20180415: MarsHung 完成初版

The Versions

15/04 2018

0.1.x-dev

0.1.9999999.9999999-dev

Learning Install GitHub Project By Composer

  Sources   Download

MIT

by Mars Hung

15/04 2018

dev-master

9999999-dev

Learning Install GitHub Project By Composer

  Sources   Download

MIT

by Mars Hung

15/04 2018

0.1.1

0.1.1.0

Learning Install GitHub Project By Composer

  Sources   Download

MIT

by Mars Hung

15/04 2018

0.1.0

0.1.0.0

Learning Install GitHub Project By Composer

  Sources   Download

MIT

by Mars Hung