From 00e2854a3e5f18a7b425dc20957c6f67f292f5b0 Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Wed, 7 Jun 2023 14:33:04 +0800 Subject: [PATCH] Adds `hyperf/helper` component (#5809) --- CHANGELOG-3.1.md | 1 + bin/composer-json-fixer | 18 +- src/helper/.gitattributes | 2 + .../.github/workflows/close-pull-request.yml | 13 + src/helper/.github/workflows/release.yml | 25 ++ src/helper/LICENSE | 21 ++ src/helper/composer.json | 40 +++ src/helper/src/Functions.php | 312 ++++++++++++++++++ 8 files changed, 427 insertions(+), 5 deletions(-) create mode 100644 src/helper/.gitattributes create mode 100644 src/helper/.github/workflows/close-pull-request.yml create mode 100644 src/helper/.github/workflows/release.yml create mode 100644 src/helper/LICENSE create mode 100644 src/helper/composer.json create mode 100644 src/helper/src/Functions.php diff --git a/CHANGELOG-3.1.md b/CHANGELOG-3.1.md index 84a4e3bc0..83baeb6c7 100644 --- a/CHANGELOG-3.1.md +++ b/CHANGELOG-3.1.md @@ -17,6 +17,7 @@ - [ ] Support v2 and v3 for socketio-server - [ ] Support [Psr7Plus](https://github.com/swow/psr7-plus) - [x] Support [pest](https://github.com/pestphp/pest) +- [x] Added `hyperf/helper` component ## Optimized diff --git a/bin/composer-json-fixer b/bin/composer-json-fixer index b3ed79fd8..875d92727 100755 --- a/bin/composer-json-fixer +++ b/bin/composer-json-fixer @@ -1,6 +1,13 @@ #!/usr/bin/env php in(__DIR__ . '/../src') + ->exclude('helper') ->name('composer.json') ->files(); @@ -24,7 +32,7 @@ $replaces = []; foreach ($files as $file) { $component = basename(dirname($file)); $composerJson = json_decode(file_get_contents($file), true); - if(isset($composerJson['name']) && str_starts_with($composerJson['name'], 'hyperf')){ + if (isset($composerJson['name']) && str_starts_with($composerJson['name'], 'hyperf')) { $replaces[$composerJson['name']] = '*'; } @@ -41,14 +49,14 @@ foreach ($files as $file) { } foreach ($composerJson['autoload-dev']['psr-4'] ?? [] as $ns => $dir) { $value = "src/{$component}/" . trim($dir, '/') . '/'; - if(isset($autoloadDev[$ns])){ + if (isset($autoloadDev[$ns])) { $autoloadDev[$ns] = [$value, ...(array) $autoloadDev[$ns]]; - }else{ + } else { $autoloadDev[$ns] = $value; } } if (isset($composerJson['extra']['hyperf']['config'])) { - $configProviders = array_merge($configProviders, (array)$composerJson['extra']['hyperf']['config']); + $configProviders = array_merge($configProviders, (array) $composerJson['extra']['hyperf']['config']); } } diff --git a/src/helper/.gitattributes b/src/helper/.gitattributes new file mode 100644 index 000000000..27b765f55 --- /dev/null +++ b/src/helper/.gitattributes @@ -0,0 +1,2 @@ +/tests export-ignore +/.github export-ignore diff --git a/src/helper/.github/workflows/close-pull-request.yml b/src/helper/.github/workflows/close-pull-request.yml new file mode 100644 index 000000000..591822c0f --- /dev/null +++ b/src/helper/.github/workflows/close-pull-request.yml @@ -0,0 +1,13 @@ +name: Close Pull Request + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: "Hi, this is a READ-ONLY repository, please submit your PR on the https://github.com/hyperf/hyperf repository.

This Pull Request will close automatically.

Thanks! " diff --git a/src/helper/.github/workflows/release.yml b/src/helper/.github/workflows/release.yml new file mode 100644 index 000000000..0f7d23faa --- /dev/null +++ b/src/helper/.github/workflows/release.yml @@ -0,0 +1,25 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Release + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false diff --git a/src/helper/LICENSE b/src/helper/LICENSE new file mode 100644 index 000000000..352b796f2 --- /dev/null +++ b/src/helper/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Hyperf + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/helper/composer.json b/src/helper/composer.json new file mode 100644 index 000000000..80b5aca04 --- /dev/null +++ b/src/helper/composer.json @@ -0,0 +1,40 @@ +{ + "name": "hyperf/helper", + "description": "A function helper package that could help developer solved the problem quickly.", + "license": "MIT", + "keywords": [ + "php", + "swoole", + "hyperf", + "helper" + ], + "homepage": "https://hyperf.io", + "support": { + "docs": "https://hyperf.wiki", + "issues": "https://github.com/hyperf/hyperf/issues", + "pull-request": "https://github.com/hyperf/hyperf/pulls", + "source": "https://github.com/hyperf/hyperf" + }, + "require": { + "php": ">=8.1", + "hyperf/collection": "~3.1.0", + "hyperf/contract": "~3.1.0", + "hyperf/coroutine": "~3.1.0", + "hyperf/stringable": "~3.1.0", + "hyperf/support": "~3.1.0", + "hyperf/tappable": "~3.1.0" + }, + "autoload": { + "files": [ + "src/Functions.php" + ] + }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + } +} diff --git a/src/helper/src/Functions.php b/src/helper/src/Functions.php new file mode 100644 index 000000000..a39c9ea5b --- /dev/null +++ b/src/helper/src/Functions.php @@ -0,0 +1,312 @@ +