From 19b71e656717ab3f059156eab9d7af767a7ed3c6 Mon Sep 17 00:00:00 2001 From: Inhere Date: Sun, 7 Aug 2022 16:50:49 +0800 Subject: [PATCH] up: update the gh release action and add zh-CN readme --- .github/changelog.yml | 49 ++++++----- .github/workflows/release.yml | 45 ++-------- README.md | 38 ++++++-- README.zh-CN.md | 157 ++++++++++++++++++++++++++++++++++ 4 files changed, 225 insertions(+), 64 deletions(-) create mode 100644 README.zh-CN.md diff --git a/.github/changelog.yml b/.github/changelog.yml index f5df969..06048e3 100644 --- a/.github/changelog.yml +++ b/.github/changelog.yml @@ -1,27 +1,36 @@ -options: - title: '## Change Log' - style: gh-release +title: '## Change Log' +# style allow: simple, markdown(mkdown), ghr(gh-release) +style: gh-release +# group names +names: [Refactor, Fixed, Feature, Update, Other] +#repo_url: https://github.com/gookit/gcli + filters: - # message length >= 12 - - name: msgLen - minLen: 12 - # message words >= 3 - - name: wordsLen - minLen: 3 + # message length should >= 12 + - name: msg_len + min_len: 12 + # message words should >= 3 + - name: words_len + min_len: 3 + - name: keyword + keyword: format code + exclude: true - name: keywords - keywords: ['format code'] + keywords: format code, action test exclude: true +# group match rules # not matched will use 'Other' group. -groups: - - name: New - keywords: [add, new] +rules: + - name: Refactor + start_withs: [refactor, break] + contains: ['refactor:', 'break:'] - name: Fixed - startWiths: [add, new] - keywords: [add, new] - - name: Feat - startWiths: [feat] - keywords: [feature] + start_withs: [fix] + contains: ['fix:'] + - name: Feature + start_withs: [feat, new] + contains: ['feat:', 'new:'] - name: Update - startWiths: [update, 'up:'] - keywords: [update] + start_withs: [up] + contains: ['update:', 'up:'] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1f99f3..7b4db6f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,17 +7,15 @@ on: jobs: release: - name: Test on php ${{ matrix.php}} + name: Tag release runs-on: ubuntu-latest timeout-minutes: 10 - strategy: - fail-fast: true - matrix: - php: [8.0] steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set ENV for github-release # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable @@ -25,45 +23,18 @@ jobs: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV echo "RELEASE_NAME=$GITHUB_WORKFLOW" >> $GITHUB_ENV - # usage refer https://github.com/shivammathur/setup-php - - name: Setup PHP - timeout-minutes: 5 - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php}} - tools: pecl, php-cs-fixer, phpunit - extensions: mbstring, dom, fileinfo, mysql, openssl # , swoole-4.4.19 #optional, setup extensions - ini-values: post_max_size=56M, short_open_tag=On #optional, setup php.ini configuration - coverage: none #optional, setup coverage driver: xdebug, none - - # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" - # Docs: https://getcomposer.org/doc/articles/scripts.md - - - name: Install dependencies # eg: v1.0.3 - run: | - echo $RELEASE_TAG - echo $RELEASE_NAME - tag1=${GITHUB_REF#refs/*/} - echo "release tag: ${tag1}" - composer update --no-progress - - # more see https://github.com/inhere/kite - - name: Generate changelog file - id: changelog + - name: Generate changelog run: | - wget -c -q https://github.com/inhere/kite/releases/latest/download/kite.phar - php kite.phar git cl prev last --style gh-release --no-merges --fetch-tags --unshallow --file changelog.md - cat changelog.md + curl https://github.com/gookit/gitw/releases/latest/download/chlog-linux-amd64 -L -o /usr/local/bin/chlog + chmod a+x /usr/local/bin/chlog + chlog -c .github/changelog.yml -o changelog.md prev last # https://github.com/softprops/action-gh-release - name: Create release and upload assets uses: softprops/action-gh-release@v1 -# if: startsWith(github.ref, 'refs/tags/') with: name: ${{ env.RELEASE_TAG }} tag_name: ${{ env.RELEASE_TAG }} body_path: changelog.md - # files: kite-${{ env.RELEASE_TAG }}.phar env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# GITHUB_REPOSITORY: my_gh_org/my_gh_repo \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index fad2bc0..4ff730a 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,24 @@ [![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/phppkg/ini)](https://github.com/phppkg/ini) [![Actions Status](https://github.com/phppkg/ini/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/ini/actions) -💪 An enhanced PHP INI parser +💪 An enhanced `INI` format parser written in PHP. -- auto convert data type, eg: int, bool, float +- auto convert data type, eg: `int, bool, float` +- support encode data to INI string. - ignores commented lines that start with ";" or "#" -- ignores broken lines that do not have "=" + - ignores broken lines that do not have "=" - supports array values and array value keys -- enhance: supports inline array value -- enhance: supports multi inline string. use `'''` or `"""` +- enhance: supports inline list array value +- enhance: supports multi line string. use `'''` or `"""` - enhance: supports add interceptor before collect value - TODO: support parse ENV var. `${SHELL | bash}` +> **[中文说明](README.zh-CN.md)** + ## Install +- Required PHP 8.0+ + **composer** ```bash @@ -75,13 +80,18 @@ val_arr_two[6] = "key_6" val_arr_two[some_key] = "some_key_value" ``` -usage: +### Decode + +Decode from INI string. ```php -use PhpPkg\Ini\Ini; +use PhpPkg\Ini\Ini;use Toolkit\Stdlib\Std\Collection; $data = Ini::decode($ini); vdump($data); + +$cfg = Collection::new($data); +$int = $cfg->get('int'); // 23 ``` **Output**: @@ -129,6 +139,20 @@ array(13) { } ``` +### Decode file + +```php +$data = Ini::decodeFile($iniFile); +``` + +## Encode + +Encode data to INI string. + +```php +$iniString = Ini::encode($data); +``` + ## License [MIT](LICENSE) diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..4f004bd --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,157 @@ +# INI + +[![License](https://img.shields.io/github/license/phppkg/ini?style=flat-square)](LICENSE) +[![Php Version](https://img.shields.io/packagist/php-v/phppkg/ini?maxAge=2592000)](https://packagist.org/packages/phppkg/ini) +[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/phppkg/ini)](https://github.com/phppkg/ini) +[![Actions Status](https://github.com/phppkg/ini/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/ini/actions) + +💪 PHP编写的一个增强的 `INI` 格式解析器。 + +- 自动转换数据类型,例如:`int, bool, float` +- 支持将数据编码为 `INI` 字符串。 +- 忽略以 `;` 或者 `#` 开头的注释行 +- 支持数组值和数组值键 +- 增强:支持内联数组值 +- 增强:支持多行字符串。 使用 `'''` 或 `"""` +- 增强:支持在收集值之前添加拦截器 +- TODO: support parse ENV var. `${SHELL | bash}` + +> **[EN README](README.md)** + +## 安装 + +- Required PHP 8.0+ + +**composer** + +```bash +composer require phppkg/ini +``` + +## 使用 + +example ini: + +```ini +; comments line +// comments line +# comments line + +int = 23 +float = 34.5 +str=ab cd +bool=true +empty-str = + +# support multi-line +multi-line = ''' +this is + a multi + line string +''' + +# simple inline list array +inlineList = [ab, 23, 34.5] + +# simple multi-line list array, equals the 'simpleList1' +simpleList[] = 567 +simpleList[] = "some value" + +# simple multi-line list array +[simpleList1] +- = 567 +- = "some value" + +# simple k-v map +[simpleMap] +val_one = 567 +val_two = 'some value' + +# multi level list array +[array] +arr_sub_key[] = "arr_elem_one" +arr_sub_key[] = "arr_elem_two" +arr_sub_key[] = "arr_elem_three" + +# multi level k-v map sub array +[array_keys] +val_arr_two[6] = "key_6" +val_arr_two[some_key] = "some_key_value" +``` + +### 解析为数据 + +usage: + +```php +use PhpPkg\Ini\Ini; + +$data = Ini::decode($ini); +vdump($data); + +$cfg = Collection::new($data); +$int = $cfg->get('int'); // 23 +``` + +**Output**: + +```text +array(13) { + ["int"]=> int(23) + ["float"]=> float(34.5) + ["str"]=> string(5) "ab cd" + ["bool"]=> bool(true) + ["empty-str"]=> string(0) "" + ["multi-line"]=> string(30) "this is + a multi + line string" + ["inlineList"]=> array(3) { + [0]=> string(2) "ab" + [1]=> int(23) + [2]=> float(34.5) + } + ["simpleList"]=> array(2) { + [0]=> int(567) + [1]=> string(10) "some value" + } + ["simpleList1"]=> array(2) { + [0]=> int(567) + [1]=> string(10) "some value" + } + ["simpleMap"]=> array(2) { + ["val_one"]=> int(567) + ["val_two"]=> string(10) "some value" + } + ["array"]=> array(1) { + ["arr_sub_key"]=> array(3) { + [0]=> string(12) "arr_elem_one" + [1]=> string(12) "arr_elem_two" + [2]=> string(14) "arr_elem_three" + } + } + ["array_keys"]=> array(1) { + ["val_arr_two"]=> array(2) { + [6]=> string(5) "key_6" + ["some_key"]=> string(14) "some_key_value" + } + } +} +``` + +### 从文件解析 + +```php +$data = Ini::decodeFile($iniFile); +``` + +## 编码数据为INI + +Encode data to INI string. + +```php +$iniString = Ini::encode($data); +``` + +## License + +[MIT](LICENSE)