mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Adds hyperf/helper
component (#5809)
This commit is contained in:
parent
d3ab30ca4b
commit
00e2854a3e
@ -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
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) {
|
||||
@ -12,6 +19,7 @@ foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php',
|
||||
|
||||
$files = Finder::create()
|
||||
->in(__DIR__ . '/../src')
|
||||
->exclude('helper')
|
||||
->name('composer.json')
|
||||
->files();
|
||||
|
||||
|
2
src/helper/.gitattributes
vendored
Normal file
2
src/helper/.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/tests export-ignore
|
||||
/.github export-ignore
|
13
src/helper/.github/workflows/close-pull-request.yml
vendored
Normal file
13
src/helper/.github/workflows/close-pull-request.yml
vendored
Normal file
@ -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.<br><br> This Pull Request will close automatically.<br><br> Thanks! "
|
25
src/helper/.github/workflows/release.yml
vendored
Normal file
25
src/helper/.github/workflows/release.yml
vendored
Normal file
@ -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
|
21
src/helper/LICENSE
Normal file
21
src/helper/LICENSE
Normal file
@ -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.
|
40
src/helper/composer.json
Normal file
40
src/helper/composer.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
312
src/helper/src/Functions.php
Normal file
312
src/helper/src/Functions.php
Normal file
@ -0,0 +1,312 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
use Hyperf\Collection\Collection;
|
||||
|
||||
if (! function_exists('value')) {
|
||||
/**
|
||||
* Return the default value of the given value.
|
||||
*/
|
||||
function value(mixed $value, ...$args)
|
||||
{
|
||||
return \Hyperf\Support\value($value, ...$args);
|
||||
}
|
||||
}
|
||||
if (! function_exists('env')) {
|
||||
/**
|
||||
* Gets the value of an environment variable.
|
||||
*
|
||||
* @param string $key
|
||||
* @param null|mixed $default
|
||||
*/
|
||||
function env($key, $default = null)
|
||||
{
|
||||
return \Hyperf\Support\env($key, $default);
|
||||
}
|
||||
}
|
||||
if (! function_exists('retry')) {
|
||||
/**
|
||||
* Retry an operation a given number of times.
|
||||
*
|
||||
* @param float|int $times
|
||||
* @param int $sleep millisecond
|
||||
* @throws \Throwable
|
||||
*/
|
||||
function retry($times, callable $callback, int $sleep = 0)
|
||||
{
|
||||
return \Hyperf\Support\retry($times, $callback, $sleep);
|
||||
}
|
||||
}
|
||||
if (! function_exists('with')) {
|
||||
/**
|
||||
* Return the given value, optionally passed through the given callback.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
function with($value, callable $callback = null)
|
||||
{
|
||||
return \Hyperf\Support\with($value, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('collect')) {
|
||||
/**
|
||||
* Create a collection from the given value.
|
||||
*
|
||||
* @param null|mixed $value
|
||||
* @return Collection
|
||||
*/
|
||||
function collect($value = null)
|
||||
{
|
||||
return \Hyperf\Collection\collect($value);
|
||||
}
|
||||
}
|
||||
if (! function_exists('data_fill')) {
|
||||
/**
|
||||
* Fill in data where it's missing.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param array|string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
function data_fill(&$target, $key, $value)
|
||||
{
|
||||
return \Hyperf\Collection\data_fill($target, $key, $value);
|
||||
}
|
||||
}
|
||||
if (! function_exists('data_get')) {
|
||||
/**
|
||||
* Get an item from an array or object using "dot" notation.
|
||||
*
|
||||
* @param null|array|int|string $key
|
||||
* @param null|mixed $default
|
||||
* @param mixed $target
|
||||
*/
|
||||
function data_get($target, $key, $default = null)
|
||||
{
|
||||
return \Hyperf\Collection\data_get($target, $key, $default);
|
||||
}
|
||||
}
|
||||
if (! function_exists('data_set')) {
|
||||
/**
|
||||
* Set an item on an array or object using dot notation.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param array|string $key
|
||||
* @param bool $overwrite
|
||||
* @param mixed $value
|
||||
*/
|
||||
function data_set(&$target, $key, $value, $overwrite = true)
|
||||
{
|
||||
return \Hyperf\Collection\data_set($target, $key, $value, $overwrite);
|
||||
}
|
||||
}
|
||||
if (! function_exists('head')) {
|
||||
/**
|
||||
* Get the first element of an array. Useful for method chaining.
|
||||
*
|
||||
* @param array $array
|
||||
*/
|
||||
function head($array)
|
||||
{
|
||||
return reset($array);
|
||||
}
|
||||
}
|
||||
if (! function_exists('last')) {
|
||||
/**
|
||||
* Get the last element from an array.
|
||||
*
|
||||
* @param array $array
|
||||
*/
|
||||
function last($array)
|
||||
{
|
||||
return \Hyperf\Collection\last($array);
|
||||
}
|
||||
}
|
||||
if (! function_exists('tap')) {
|
||||
/**
|
||||
* Call the given Closure with the given value then return the value.
|
||||
*
|
||||
* @template TValue
|
||||
*
|
||||
* @param null|callable $callback
|
||||
* @param TValue $value
|
||||
* @return TValue
|
||||
*/
|
||||
function tap($value, $callback = null)
|
||||
{
|
||||
return \Hyperf\Tappable\tap($value, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('call')) {
|
||||
/**
|
||||
* Call a callback with the arguments.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return null|mixed
|
||||
*/
|
||||
function call($callback, array $args = [])
|
||||
{
|
||||
return \Hyperf\Support\call($callback, $args);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('go')) {
|
||||
/**
|
||||
* @return bool|int
|
||||
*/
|
||||
function go(callable $callable)
|
||||
{
|
||||
return \Hyperf\Coroutine\go($callable);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('co')) {
|
||||
/**
|
||||
* @return bool|int
|
||||
*/
|
||||
function co(callable $callable)
|
||||
{
|
||||
return \Hyperf\Coroutine\co($callable);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('defer')) {
|
||||
function defer(callable $callable): void
|
||||
{
|
||||
\Hyperf\Coroutine\defer($callable);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('class_basename')) {
|
||||
/**
|
||||
* Get the class "basename" of the given object / class.
|
||||
*
|
||||
* @param object|string $class
|
||||
* @return string
|
||||
*/
|
||||
function class_basename($class)
|
||||
{
|
||||
return \Hyperf\Support\class_basename($class);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('trait_uses_recursive')) {
|
||||
/**
|
||||
* Returns all traits used by a trait and its traits.
|
||||
*
|
||||
* @param object|string $trait
|
||||
* @return array
|
||||
*/
|
||||
function trait_uses_recursive($trait)
|
||||
{
|
||||
return \Hyperf\Support\trait_uses_recursive($trait);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('class_uses_recursive')) {
|
||||
/**
|
||||
* Returns all traits used by a class, its parent classes and trait of their traits.
|
||||
*
|
||||
* @param object|string $class
|
||||
* @return array
|
||||
*/
|
||||
function class_uses_recursive($class)
|
||||
{
|
||||
return \Hyperf\Support\class_uses_recursive($class);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('setter')) {
|
||||
/**
|
||||
* Create a setter string.
|
||||
*/
|
||||
function setter(string $property): string
|
||||
{
|
||||
return \Hyperf\Support\setter($property);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('getter')) {
|
||||
/**
|
||||
* Create a getter string.
|
||||
*/
|
||||
function getter(string $property): string
|
||||
{
|
||||
return \Hyperf\Support\getter($property);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('parallel')) {
|
||||
/**
|
||||
* @param callable[] $callables
|
||||
* @param int $concurrent if $concurrent is equal to 0, that means unlimited
|
||||
*/
|
||||
function parallel(array $callables, int $concurrent = 0)
|
||||
{
|
||||
return Hyperf\Coroutine\parallel($callables, $concurrent);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('make')) {
|
||||
/**
|
||||
* Create an object instance, if the DI container exist in ApplicationContext,
|
||||
* then the object will be created by DI container via `make()` method, if not,
|
||||
* the object will create by `new` keyword.
|
||||
*/
|
||||
function make(string $name, array $parameters = [])
|
||||
{
|
||||
return \Hyperf\Support\make($name, $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('run')) {
|
||||
/**
|
||||
* Run callable in non-coroutine environment, all hook functions by Swoole only available in the callable.
|
||||
*
|
||||
* @param array|callable $callbacks
|
||||
*/
|
||||
function run($callbacks, int $flags = SWOOLE_HOOK_ALL): bool
|
||||
{
|
||||
return \Hyperf\Coroutine\run($callbacks, $flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('swoole_hook_flags')) {
|
||||
/**
|
||||
* Return the default swoole hook flags, you can rewrite it by defining `SWOOLE_HOOK_FLAGS`.
|
||||
*/
|
||||
function swoole_hook_flags(): int
|
||||
{
|
||||
return \Hyperf\Support\swoole_hook_flags();
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('optional')) {
|
||||
/**
|
||||
* Provide access to optional objects.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function optional($value = null, callable $callback = null)
|
||||
{
|
||||
return \Hyperf\Support\optional($value, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('wait')) {
|
||||
function wait(Closure $closure, ?float $timeout = null)
|
||||
{
|
||||
return \Hyperf\Coroutine\wait($closure, $timeout);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user