mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-11-13 06:03:44 +08:00
框架更新
This commit is contained in:
36
vendor/topthink/think-helper/.github/workflows/ci.yml
vendored
Normal file
36
vendor/topthink/think-helper/.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
|
||||
jobs:
|
||||
phpcs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup PHP environment
|
||||
uses: shivammathur/setup-php@v2
|
||||
- name: Install dependencies
|
||||
run: composer install
|
||||
- name: PHPCSFixer check
|
||||
run: composer check-style
|
||||
phpunit:
|
||||
strategy:
|
||||
matrix:
|
||||
php_version: [7.3, 7.4, 8.0]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup PHP environment
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php_version }}
|
||||
coverage: xdebug
|
||||
- name: Install dependencies
|
||||
run: composer install
|
||||
- name: PHPUnit check
|
||||
run: ./vendor/bin/phpunit --coverage-text
|
||||
36
vendor/topthink/think-helper/.github/workflows/php.yml
vendored
Normal file
36
vendor/topthink/think-helper/.github/workflows/php.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: PHP Composer
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ 3.0 ]
|
||||
pull_request:
|
||||
branches: [ 3.0 ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate --strict
|
||||
|
||||
- name: Cache Composer packages
|
||||
id: composer-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php-
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
|
||||
# Docs: https://getcomposer.org/doc/articles/scripts.md
|
||||
|
||||
- name: Run test suite
|
||||
run: composer test
|
||||
201
vendor/topthink/think-helper/LICENSE
vendored
Normal file
201
vendor/topthink/think-helper/LICENSE
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
35
vendor/topthink/think-helper/README.md
vendored
Normal file
35
vendor/topthink/think-helper/README.md
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# thinkphp6 常用的一些扩展类库
|
||||
|
||||
基于PHP7.1+
|
||||
|
||||
[](https://github.com/larvatecn/think-helper/actions/workflows/php.yml)
|
||||
|
||||
> 以下类库都在`\\think\\helper`命名空间下
|
||||
|
||||
## Str
|
||||
|
||||
> 字符串操作
|
||||
|
||||
```
|
||||
// 检查字符串中是否包含某些字符串
|
||||
Str::contains($haystack, $needles)
|
||||
|
||||
// 检查字符串是否以某些字符串结尾
|
||||
Str::endsWith($haystack, $needles)
|
||||
|
||||
// 获取指定长度的随机字母数字组合的字符串
|
||||
Str::random($length = 16)
|
||||
|
||||
// 字符串转小写
|
||||
Str::lower($value)
|
||||
|
||||
// 字符串转大写
|
||||
Str::upper($value)
|
||||
|
||||
// 获取字符串的长度
|
||||
Str::length($value)
|
||||
|
||||
// 截取字符串
|
||||
Str::substr($string, $start, $length = null)
|
||||
|
||||
```
|
||||
36
vendor/topthink/think-helper/composer.json
vendored
Normal file
36
vendor/topthink/think-helper/composer.json
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "topthink/think-helper",
|
||||
"description": "The ThinkPHP6 Helper Package",
|
||||
"license": "Apache-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "yunwuxin",
|
||||
"email": "448901948@qq.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"think\\": "src"
|
||||
},
|
||||
"files": [
|
||||
"src/helper.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./vendor/bin/phpunit --colors"
|
||||
},
|
||||
"scripts-descriptions": {
|
||||
"test": "Run all tests."
|
||||
}
|
||||
}
|
||||
17
vendor/topthink/think-helper/phpunit.xml.dist
vendored
Normal file
17
vendor/topthink/think-helper/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Application Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
</phpunit>
|
||||
662
vendor/topthink/think-helper/src/Collection.php
vendored
Normal file
662
vendor/topthink/think-helper/src/Collection.php
vendored
Normal file
@@ -0,0 +1,662 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: zhangyajun <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace think;
|
||||
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
use JsonSerializable;
|
||||
use think\contract\Arrayable;
|
||||
use think\contract\Jsonable;
|
||||
use think\helper\Arr;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* 数据集管理类
|
||||
*/
|
||||
class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Arrayable, Jsonable
|
||||
{
|
||||
/**
|
||||
* 数据集数据
|
||||
* @var array
|
||||
*/
|
||||
protected $items = [];
|
||||
|
||||
public function __construct($items = [])
|
||||
{
|
||||
$this->items = $this->convertToArray($items);
|
||||
}
|
||||
|
||||
public static function make($items = [])
|
||||
{
|
||||
return new static($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为空
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return empty($this->items);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return array_map(function ($value) {
|
||||
return $value instanceof Arrayable ? $value->toArray() : $value;
|
||||
}, $this->items);
|
||||
}
|
||||
|
||||
public function all(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并数组
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $items 数据
|
||||
* @return static
|
||||
*/
|
||||
public function merge($items)
|
||||
{
|
||||
return new static(array_merge($this->items, $this->convertToArray($items)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 按指定键整理数据
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $items 数据
|
||||
* @param string $indexKey 键名
|
||||
* @return array
|
||||
*/
|
||||
public function dictionary($items = null, string &$indexKey = null)
|
||||
{
|
||||
if ($items instanceof self) {
|
||||
$items = $items->all();
|
||||
}
|
||||
|
||||
$items = is_null($items) ? $this->items : $items;
|
||||
|
||||
if ($items && empty($indexKey)) {
|
||||
$indexKey = is_array($items[0]) ? 'id' : $items[0]->getPk();
|
||||
}
|
||||
|
||||
if (isset($indexKey) && is_string($indexKey)) {
|
||||
return array_column($items, null, $indexKey);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较数组,返回差集
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $items 数据
|
||||
* @param string $indexKey 指定比较的键名
|
||||
* @return static
|
||||
*/
|
||||
public function diff($items, string $indexKey = null)
|
||||
{
|
||||
if ($this->isEmpty() || is_scalar($this->items[0])) {
|
||||
return new static(array_diff($this->items, $this->convertToArray($items)));
|
||||
}
|
||||
|
||||
$diff = [];
|
||||
$dictionary = $this->dictionary($items, $indexKey);
|
||||
|
||||
if (is_string($indexKey)) {
|
||||
foreach ($this->items as $item) {
|
||||
if (!isset($dictionary[$item[$indexKey]])) {
|
||||
$diff[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new static($diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较数组,返回交集
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $items 数据
|
||||
* @param string $indexKey 指定比较的键名
|
||||
* @return static
|
||||
*/
|
||||
public function intersect($items, string $indexKey = null)
|
||||
{
|
||||
if ($this->isEmpty() || is_scalar($this->items[0])) {
|
||||
return new static(array_intersect($this->items, $this->convertToArray($items)));
|
||||
}
|
||||
|
||||
$intersect = [];
|
||||
$dictionary = $this->dictionary($items, $indexKey);
|
||||
|
||||
if (is_string($indexKey)) {
|
||||
foreach ($this->items as $item) {
|
||||
if (isset($dictionary[$item[$indexKey]])) {
|
||||
$intersect[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new static($intersect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 交换数组中的键和值
|
||||
*
|
||||
* @access public
|
||||
* @return static
|
||||
*/
|
||||
public function flip()
|
||||
{
|
||||
return new static(array_flip($this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回数组中所有的键名
|
||||
*
|
||||
* @access public
|
||||
* @return static
|
||||
*/
|
||||
public function keys()
|
||||
{
|
||||
return new static(array_keys($this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回数组中所有的值组成的新 Collection 实例
|
||||
* @access public
|
||||
* @return static
|
||||
*/
|
||||
public function values()
|
||||
{
|
||||
return new static(array_values($this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数组的最后一个元素(出栈)
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function pop()
|
||||
{
|
||||
return array_pop($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过使用用户自定义函数,以字符串返回数组
|
||||
*
|
||||
* @access public
|
||||
* @param callable $callback 调用方法
|
||||
* @param mixed $initial
|
||||
* @return mixed
|
||||
*/
|
||||
public function reduce(callable $callback, $initial = null)
|
||||
{
|
||||
return array_reduce($this->items, $callback, $initial);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以相反的顺序返回数组。
|
||||
*
|
||||
* @access public
|
||||
* @return static
|
||||
*/
|
||||
public function reverse()
|
||||
{
|
||||
return new static(array_reverse($this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数组中首个元素,并返回被删除元素的值
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function shift()
|
||||
{
|
||||
return array_shift($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在数组结尾插入一个元素
|
||||
* @access public
|
||||
* @param mixed $value 元素
|
||||
* @param string $key KEY
|
||||
* @return $this
|
||||
*/
|
||||
public function push($value, string $key = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
$this->items[] = $value;
|
||||
} else {
|
||||
$this->items[$key] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个数组分割为新的数组块.
|
||||
*
|
||||
* @access public
|
||||
* @param int $size 块大小
|
||||
* @param bool $preserveKeys
|
||||
* @return static
|
||||
*/
|
||||
public function chunk(int $size, bool $preserveKeys = false)
|
||||
{
|
||||
$chunks = [];
|
||||
|
||||
foreach (array_chunk($this->items, $size, $preserveKeys) as $chunk) {
|
||||
$chunks[] = new static($chunk);
|
||||
}
|
||||
|
||||
return new static($chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在数组开头插入一个元素
|
||||
* @access public
|
||||
* @param mixed $value 元素
|
||||
* @param string $key KEY
|
||||
* @return $this
|
||||
*/
|
||||
public function unshift($value, string $key = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
array_unshift($this->items, $value);
|
||||
} else {
|
||||
$this->items = [$key => $value] + $this->items;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给每个元素执行个回调
|
||||
*
|
||||
* @access public
|
||||
* @param callable $callback 回调
|
||||
* @return $this
|
||||
*/
|
||||
public function each(callable $callback)
|
||||
{
|
||||
foreach ($this->items as $key => $item) {
|
||||
$result = $callback($item, $key);
|
||||
|
||||
if (false === $result) {
|
||||
break;
|
||||
} elseif (!is_object($item)) {
|
||||
$this->items[$key] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用回调函数处理数组中的元素
|
||||
* @access public
|
||||
* @param callable|null $callback 回调
|
||||
* @return static
|
||||
*/
|
||||
public function map(callable $callback)
|
||||
{
|
||||
return new static(array_map($callback, $this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用回调函数过滤数组中的元素
|
||||
* @access public
|
||||
* @param callable|null $callback 回调
|
||||
* @return static
|
||||
*/
|
||||
public function filter(callable $callback = null)
|
||||
{
|
||||
if ($callback) {
|
||||
return new static(array_filter($this->items, $callback));
|
||||
}
|
||||
|
||||
return new static(array_filter($this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段条件过滤数组中的元素
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param mixed $operator 操作符
|
||||
* @param mixed $value 数据
|
||||
* @return static
|
||||
*/
|
||||
public function where(string $field, $operator, $value = null)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
$value = $operator;
|
||||
$operator = '=';
|
||||
}
|
||||
|
||||
return $this->filter(function ($data) use ($field, $operator, $value) {
|
||||
if (strpos($field, '.')) {
|
||||
[$field, $relation] = explode('.', $field);
|
||||
|
||||
$result = $data[$field][$relation] ?? null;
|
||||
} else {
|
||||
$result = $data[$field] ?? null;
|
||||
}
|
||||
|
||||
switch (strtolower($operator)) {
|
||||
case '===':
|
||||
return $result === $value;
|
||||
case '!==':
|
||||
return $result !== $value;
|
||||
case '!=':
|
||||
case '<>':
|
||||
return $result != $value;
|
||||
case '>':
|
||||
return $result > $value;
|
||||
case '>=':
|
||||
return $result >= $value;
|
||||
case '<':
|
||||
return $result < $value;
|
||||
case '<=':
|
||||
return $result <= $value;
|
||||
case 'like':
|
||||
return is_string($result) && false !== strpos($result, $value);
|
||||
case 'not like':
|
||||
return is_string($result) && false === strpos($result, $value);
|
||||
case 'in':
|
||||
return is_scalar($result) && in_array($result, $value, true);
|
||||
case 'not in':
|
||||
return is_scalar($result) && !in_array($result, $value, true);
|
||||
case 'between':
|
||||
[$min, $max] = is_string($value) ? explode(',', $value) : $value;
|
||||
return is_scalar($result) && $result >= $min && $result <= $max;
|
||||
case 'not between':
|
||||
[$min, $max] = is_string($value) ? explode(',', $value) : $value;
|
||||
return is_scalar($result) && $result > $max || $result < $min;
|
||||
case '==':
|
||||
case '=':
|
||||
default:
|
||||
return $result == $value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE过滤
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param string $value 数据
|
||||
* @return static
|
||||
*/
|
||||
public function whereLike(string $field, string $value)
|
||||
{
|
||||
return $this->where($field, 'like', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE过滤
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param string $value 数据
|
||||
* @return static
|
||||
*/
|
||||
public function whereNotLike(string $field, string $value)
|
||||
{
|
||||
return $this->where($field, 'not like', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* IN过滤
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param array $value 数据
|
||||
* @return static
|
||||
*/
|
||||
public function whereIn(string $field, array $value)
|
||||
{
|
||||
return $this->where($field, 'in', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT IN过滤
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param array $value 数据
|
||||
* @return static
|
||||
*/
|
||||
public function whereNotIn(string $field, array $value)
|
||||
{
|
||||
return $this->where($field, 'not in', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* BETWEEN 过滤
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param mixed $value 数据
|
||||
* @return static
|
||||
*/
|
||||
public function whereBetween(string $field, $value)
|
||||
{
|
||||
return $this->where($field, 'between', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT BETWEEN 过滤
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param mixed $value 数据
|
||||
* @return static
|
||||
*/
|
||||
public function whereNotBetween(string $field, $value)
|
||||
{
|
||||
return $this->where($field, 'not between', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回数据中指定的一列
|
||||
* @access public
|
||||
* @param string|null $columnKey 键名
|
||||
* @param string|null $indexKey 作为索引值的列
|
||||
* @return array
|
||||
*/
|
||||
public function column( ? string $columnKey, string $indexKey = null)
|
||||
{
|
||||
return array_column($this->items, $columnKey, $indexKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对数组排序
|
||||
*
|
||||
* @access public
|
||||
* @param callable|null $callback 回调
|
||||
* @return static
|
||||
*/
|
||||
public function sort(callable $callback = null)
|
||||
{
|
||||
$items = $this->items;
|
||||
|
||||
$callback = $callback ?: function ($a, $b) {
|
||||
return $a == $b ? 0 : (($a < $b) ? -1 : 1);
|
||||
};
|
||||
|
||||
uasort($items, $callback);
|
||||
|
||||
return new static($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定字段排序
|
||||
* @access public
|
||||
* @param string $field 排序字段
|
||||
* @param string $order 排序
|
||||
* @return $this
|
||||
*/
|
||||
public function order(string $field, string $order = 'asc')
|
||||
{
|
||||
return $this->sort(function ($a, $b) use ($field, $order) {
|
||||
$fieldA = $a[$field] ?? null;
|
||||
$fieldB = $b[$field] ?? null;
|
||||
|
||||
return 'desc' == strtolower($order) ? intval($fieldB > $fieldA) : intval($fieldA > $fieldB);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数组打乱
|
||||
*
|
||||
* @access public
|
||||
* @return static
|
||||
*/
|
||||
public function shuffle()
|
||||
{
|
||||
$items = $this->items;
|
||||
|
||||
shuffle($items);
|
||||
|
||||
return new static($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一个单元数据
|
||||
*
|
||||
* @access public
|
||||
* @param callable|null $callback
|
||||
* @param null $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function first(callable $callback = null, $default = null)
|
||||
{
|
||||
return Arr::first($this->items, $callback, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最后一个单元数据
|
||||
*
|
||||
* @access public
|
||||
* @param callable|null $callback
|
||||
* @param null $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function last(callable $callback = null, $default = null)
|
||||
{
|
||||
return Arr::last($this->items, $callback, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取数组
|
||||
*
|
||||
* @access public
|
||||
* @param int $offset 起始位置
|
||||
* @param int $length 截取长度
|
||||
* @param bool $preserveKeys preserveKeys
|
||||
* @return static
|
||||
*/
|
||||
public function slice(int $offset, int $length = null, bool $preserveKeys = false)
|
||||
{
|
||||
return new static(array_slice($this->items, $offset, $length, $preserveKeys));
|
||||
}
|
||||
|
||||
// ArrayAccess
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetExists($offset) : bool
|
||||
{
|
||||
return array_key_exists($offset, $this->items);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->items[$offset];
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
if (is_null($offset)) {
|
||||
$this->items[] = $value;
|
||||
} else {
|
||||
$this->items[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->items[$offset]);
|
||||
}
|
||||
|
||||
//Countable
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
|
||||
//IteratorAggregate
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new ArrayIterator($this->items);
|
||||
}
|
||||
|
||||
//JsonSerializable
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换当前数据集为JSON字符串
|
||||
* @access public
|
||||
* @param integer $options json参数
|
||||
* @return string
|
||||
*/
|
||||
public function toJson(int $options = JSON_UNESCAPED_UNICODE): string
|
||||
{
|
||||
return json_encode($this->toArray(), $options);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换成数组
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $items 数据
|
||||
* @return array
|
||||
*/
|
||||
protected function convertToArray($items): array
|
||||
{
|
||||
if ($items instanceof self) {
|
||||
return $items->all();
|
||||
}
|
||||
|
||||
return (array) $items;
|
||||
}
|
||||
}
|
||||
8
vendor/topthink/think-helper/src/contract/Arrayable.php
vendored
Normal file
8
vendor/topthink/think-helper/src/contract/Arrayable.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace think\contract;
|
||||
|
||||
interface Arrayable
|
||||
{
|
||||
public function toArray(): array;
|
||||
}
|
||||
8
vendor/topthink/think-helper/src/contract/Jsonable.php
vendored
Normal file
8
vendor/topthink/think-helper/src/contract/Jsonable.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace think\contract;
|
||||
|
||||
interface Jsonable
|
||||
{
|
||||
public function toJson(int $options = JSON_UNESCAPED_UNICODE): string;
|
||||
}
|
||||
279
vendor/topthink/think-helper/src/helper.php
vendored
Normal file
279
vendor/topthink/think-helper/src/helper.php
vendored
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\Collection;
|
||||
use think\helper\Arr;
|
||||
|
||||
if (!function_exists('throw_if')) {
|
||||
/**
|
||||
* 按条件抛异常
|
||||
*
|
||||
* @param mixed $condition
|
||||
* @param Throwable|string $exception
|
||||
* @param array ...$parameters
|
||||
* @return mixed
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
function throw_if($condition, $exception, ...$parameters)
|
||||
{
|
||||
if ($condition) {
|
||||
throw (is_string($exception) ? new $exception(...$parameters) : $exception);
|
||||
}
|
||||
|
||||
return $condition;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('throw_unless')) {
|
||||
/**
|
||||
* 按条件抛异常
|
||||
*
|
||||
* @param mixed $condition
|
||||
* @param Throwable|string $exception
|
||||
* @param array ...$parameters
|
||||
* @return mixed
|
||||
* @throws Throwable
|
||||
*/
|
||||
function throw_unless($condition, $exception, ...$parameters)
|
||||
{
|
||||
if (!$condition) {
|
||||
throw (is_string($exception) ? new $exception(...$parameters) : $exception);
|
||||
}
|
||||
|
||||
return $condition;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tap')) {
|
||||
/**
|
||||
* 对一个值调用给定的闭包,然后返回该值
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param callable|null $callback
|
||||
* @return mixed
|
||||
*/
|
||||
function tap($value, $callback = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$callback($value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('value')) {
|
||||
/**
|
||||
* Return the default value of the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function value($value)
|
||||
{
|
||||
return $value instanceof Closure ? $value() : $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('collect')) {
|
||||
/**
|
||||
* Create a collection from the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return Collection
|
||||
*/
|
||||
function collect($value = null)
|
||||
{
|
||||
return new Collection($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('data_fill')) {
|
||||
/**
|
||||
* Fill in data where it's missing.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param string|array $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function data_fill(&$target, $key, $value)
|
||||
{
|
||||
return data_set($target, $key, $value, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('data_get')) {
|
||||
/**
|
||||
* Get an item from an array or object using "dot" notation.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param string|array|int $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
function data_get($target, $key, $default = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return $target;
|
||||
}
|
||||
|
||||
$key = is_array($key) ? $key : explode('.', $key);
|
||||
|
||||
while (!is_null($segment = array_shift($key))) {
|
||||
if ('*' === $segment) {
|
||||
if ($target instanceof Collection) {
|
||||
$target = $target->all();
|
||||
} elseif (!is_array($target)) {
|
||||
return value($default);
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($target as $item) {
|
||||
$result[] = data_get($item, $key);
|
||||
}
|
||||
|
||||
return in_array('*', $key) ? Arr::collapse($result) : $result;
|
||||
}
|
||||
|
||||
if (Arr::accessible($target) && Arr::exists($target, $segment)) {
|
||||
$target = $target[$segment];
|
||||
} elseif (is_object($target) && isset($target->{$segment})) {
|
||||
$target = $target->{$segment};
|
||||
} else {
|
||||
return value($default);
|
||||
}
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('data_set')) {
|
||||
/**
|
||||
* Set an item on an array or object using dot notation.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param string|array $key
|
||||
* @param mixed $value
|
||||
* @param bool $overwrite
|
||||
* @return mixed
|
||||
*/
|
||||
function data_set(&$target, $key, $value, $overwrite = true)
|
||||
{
|
||||
$segments = is_array($key) ? $key : explode('.', $key);
|
||||
|
||||
if (($segment = array_shift($segments)) === '*') {
|
||||
if (!Arr::accessible($target)) {
|
||||
$target = [];
|
||||
}
|
||||
|
||||
if ($segments) {
|
||||
foreach ($target as &$inner) {
|
||||
data_set($inner, $segments, $value, $overwrite);
|
||||
}
|
||||
} elseif ($overwrite) {
|
||||
foreach ($target as &$inner) {
|
||||
$inner = $value;
|
||||
}
|
||||
}
|
||||
} elseif (Arr::accessible($target)) {
|
||||
if ($segments) {
|
||||
if (!Arr::exists($target, $segment)) {
|
||||
$target[$segment] = [];
|
||||
}
|
||||
|
||||
data_set($target[$segment], $segments, $value, $overwrite);
|
||||
} elseif ($overwrite || !Arr::exists($target, $segment)) {
|
||||
$target[$segment] = $value;
|
||||
}
|
||||
} elseif (is_object($target)) {
|
||||
if ($segments) {
|
||||
if (!isset($target->{$segment})) {
|
||||
$target->{$segment} = [];
|
||||
}
|
||||
|
||||
data_set($target->{$segment}, $segments, $value, $overwrite);
|
||||
} elseif ($overwrite || !isset($target->{$segment})) {
|
||||
$target->{$segment} = $value;
|
||||
}
|
||||
} else {
|
||||
$target = [];
|
||||
|
||||
if ($segments) {
|
||||
data_set($target[$segment], $segments, $value, $overwrite);
|
||||
} elseif ($overwrite) {
|
||||
$target[$segment] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('trait_uses_recursive')) {
|
||||
/**
|
||||
* 获取一个trait里所有引用到的trait
|
||||
*
|
||||
* @param string $trait Trait
|
||||
* @return array
|
||||
*/
|
||||
function trait_uses_recursive(string $trait): array
|
||||
{
|
||||
$traits = class_uses($trait);
|
||||
foreach ($traits as $trait) {
|
||||
$traits += trait_uses_recursive($trait);
|
||||
}
|
||||
|
||||
return $traits;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('class_basename')) {
|
||||
/**
|
||||
* 获取类名(不包含命名空间)
|
||||
*
|
||||
* @param mixed $class 类名
|
||||
* @return string
|
||||
*/
|
||||
function class_basename($class): string
|
||||
{
|
||||
$class = is_object($class) ? get_class($class) : $class;
|
||||
return basename(str_replace('\\', '/', $class));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('class_uses_recursive')) {
|
||||
/**
|
||||
*获取一个类里所有用到的trait,包括父类的
|
||||
*
|
||||
* @param mixed $class 类名
|
||||
* @return array
|
||||
*/
|
||||
function class_uses_recursive($class): array
|
||||
{
|
||||
if (is_object($class)) {
|
||||
$class = get_class($class);
|
||||
}
|
||||
|
||||
$results = [];
|
||||
$classes = array_merge([$class => $class], class_parents($class));
|
||||
foreach ($classes as $class) {
|
||||
$results += trait_uses_recursive($class);
|
||||
}
|
||||
|
||||
return array_unique($results);
|
||||
}
|
||||
}
|
||||
634
vendor/topthink/think-helper/src/helper/Arr.php
vendored
Normal file
634
vendor/topthink/think-helper/src/helper/Arr.php
vendored
Normal file
@@ -0,0 +1,634 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\helper;
|
||||
|
||||
use ArrayAccess;
|
||||
use InvalidArgumentException;
|
||||
use think\Collection;
|
||||
|
||||
class Arr
|
||||
{
|
||||
|
||||
/**
|
||||
* Determine whether the given value is array accessible.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function accessible($value)
|
||||
{
|
||||
return is_array($value) || $value instanceof ArrayAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an element to an array using "dot" notation if it doesn't exist.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public static function add($array, $key, $value)
|
||||
{
|
||||
if (is_null(static::get($array, $key))) {
|
||||
static::set($array, $key, $value);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse an array of arrays into a single array.
|
||||
*
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public static function collapse($array)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($array as $values) {
|
||||
if ($values instanceof Collection) {
|
||||
$values = $values->all();
|
||||
} elseif (!is_array($values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$results = array_merge($results, $values);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross join the given arrays, returning all possible permutations.
|
||||
*
|
||||
* @param array ...$arrays
|
||||
* @return array
|
||||
*/
|
||||
public static function crossJoin(...$arrays)
|
||||
{
|
||||
$results = [[]];
|
||||
|
||||
foreach ($arrays as $index => $array) {
|
||||
$append = [];
|
||||
|
||||
foreach ($results as $product) {
|
||||
foreach ($array as $item) {
|
||||
$product[$index] = $item;
|
||||
|
||||
$append[] = $product;
|
||||
}
|
||||
}
|
||||
|
||||
$results = $append;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide an array into two arrays. One with keys and the other with values.
|
||||
*
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public static function divide($array)
|
||||
{
|
||||
return [array_keys($array), array_values($array)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with dots.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $prepend
|
||||
* @return array
|
||||
*/
|
||||
public static function dot($array, $prepend = '')
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value) && !empty($value)) {
|
||||
$results = array_merge($results, static::dot($value, $prepend . $key . '.'));
|
||||
} else {
|
||||
$results[$prepend . $key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the given array except for a specified array of keys.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array|string $keys
|
||||
* @return array
|
||||
*/
|
||||
public static function except($array, $keys)
|
||||
{
|
||||
static::forget($array, $keys);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given key exists in the provided array.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string|int $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($array, $key)
|
||||
{
|
||||
if ($array instanceof ArrayAccess) {
|
||||
return $array->offsetExists($key);
|
||||
}
|
||||
|
||||
return array_key_exists($key, $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first element in an array passing a given truth test.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function first($array, callable $callback = null, $default = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
if (empty($array)) {
|
||||
return value($default);
|
||||
}
|
||||
|
||||
foreach ($array as $item) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (call_user_func($callback, $value, $key)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return value($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last element in an array passing a given truth test.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function last($array, callable $callback = null, $default = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
return empty($array) ? value($default) : end($array);
|
||||
}
|
||||
|
||||
return static::first(array_reverse($array, true), $callback, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional array into a single level.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $depth
|
||||
* @return array
|
||||
*/
|
||||
public static function flatten($array, $depth = INF)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($array as $item) {
|
||||
$item = $item instanceof Collection ? $item->all() : $item;
|
||||
|
||||
if (!is_array($item)) {
|
||||
$result[] = $item;
|
||||
} elseif ($depth === 1) {
|
||||
$result = array_merge($result, array_values($item));
|
||||
} else {
|
||||
$result = array_merge($result, static::flatten($item, $depth - 1));
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove one or many array items from a given array using "dot" notation.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array|string $keys
|
||||
* @return void
|
||||
*/
|
||||
public static function forget(&$array, $keys)
|
||||
{
|
||||
$original = &$array;
|
||||
|
||||
$keys = (array) $keys;
|
||||
|
||||
if (count($keys) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
// if the exact key exists in the top-level, remove it
|
||||
if (static::exists($array, $key)) {
|
||||
unset($array[$key]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$parts = explode('.', $key);
|
||||
|
||||
// clean up before each pass
|
||||
$array = &$original;
|
||||
|
||||
while (count($parts) > 1) {
|
||||
$part = array_shift($parts);
|
||||
|
||||
if (isset($array[$part]) && is_array($array[$part])) {
|
||||
$array = &$array[$part];
|
||||
} else {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
unset($array[array_shift($parts)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($array, $key, $default = null)
|
||||
{
|
||||
if (!static::accessible($array)) {
|
||||
return value($default);
|
||||
}
|
||||
|
||||
if (is_null($key)) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
if (static::exists($array, $key)) {
|
||||
return $array[$key];
|
||||
}
|
||||
|
||||
if (strpos($key, '.') === false) {
|
||||
return $array[$key] ?? value($default);
|
||||
}
|
||||
|
||||
foreach (explode('.', $key) as $segment) {
|
||||
if (static::accessible($array) && static::exists($array, $segment)) {
|
||||
$array = $array[$segment];
|
||||
} else {
|
||||
return value($default);
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an item or items exist in an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string|array $keys
|
||||
* @return bool
|
||||
*/
|
||||
public static function has($array, $keys)
|
||||
{
|
||||
$keys = (array) $keys;
|
||||
|
||||
if (!$array || $keys === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$subKeyArray = $array;
|
||||
|
||||
if (static::exists($array, $key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (explode('.', $key) as $segment) {
|
||||
if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) {
|
||||
$subKeyArray = $subKeyArray[$segment];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an array is associative.
|
||||
*
|
||||
* An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
|
||||
*
|
||||
* @param array $array
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAssoc(array $array)
|
||||
{
|
||||
$keys = array_keys($array);
|
||||
|
||||
return array_keys($keys) !== $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a subset of the items from the given array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array|string $keys
|
||||
* @return array
|
||||
*/
|
||||
public static function only($array, $keys)
|
||||
{
|
||||
return array_intersect_key($array, array_flip((array) $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluck an array of values from an array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string|array $value
|
||||
* @param string|array|null $key
|
||||
* @return array
|
||||
*/
|
||||
public static function pluck($array, $value, $key = null)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
[$value, $key] = static::explodePluckParameters($value, $key);
|
||||
|
||||
foreach ($array as $item) {
|
||||
$itemValue = data_get($item, $value);
|
||||
|
||||
// If the key is "null", we will just append the value to the array and keep
|
||||
// looping. Otherwise we will key the array using the value of the key we
|
||||
// received from the developer. Then we'll return the final array form.
|
||||
if (is_null($key)) {
|
||||
$results[] = $itemValue;
|
||||
} else {
|
||||
$itemKey = data_get($item, $key);
|
||||
|
||||
if (is_object($itemKey) && method_exists($itemKey, '__toString')) {
|
||||
$itemKey = (string) $itemKey;
|
||||
}
|
||||
|
||||
$results[$itemKey] = $itemValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explode the "value" and "key" arguments passed to "pluck".
|
||||
*
|
||||
* @param string|array $value
|
||||
* @param string|array|null $key
|
||||
* @return array
|
||||
*/
|
||||
protected static function explodePluckParameters($value, $key)
|
||||
{
|
||||
$value = is_string($value) ? explode('.', $value) : $value;
|
||||
|
||||
$key = is_null($key) || is_array($key) ? $key : explode('.', $key);
|
||||
|
||||
return [$value, $key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an item onto the beginning of an array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param mixed $value
|
||||
* @param mixed $key
|
||||
* @return array
|
||||
*/
|
||||
public static function prepend($array, $value, $key = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
array_unshift($array, $value);
|
||||
} else {
|
||||
$array = [$key => $value] + $array;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from the array, and remove it.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function pull(&$array, $key, $default = null)
|
||||
{
|
||||
$value = static::get($array, $key, $default);
|
||||
|
||||
static::forget($array, $key);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one or a specified number of random values from an array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int|null $number
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function random($array, $number = null)
|
||||
{
|
||||
$requested = is_null($number) ? 1 : $number;
|
||||
|
||||
$count = count($array);
|
||||
|
||||
if ($requested > $count) {
|
||||
throw new InvalidArgumentException(
|
||||
"You requested {$requested} items, but there are only {$count} items available."
|
||||
);
|
||||
}
|
||||
|
||||
if (is_null($number)) {
|
||||
return $array[array_rand($array)];
|
||||
}
|
||||
|
||||
if ((int) $number === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$keys = array_rand($array, $number);
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ((array) $keys as $key) {
|
||||
$results[] = $array[$key];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an array item to a given value using "dot" notation.
|
||||
*
|
||||
* If no key is given to the method, the entire array will be replaced.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public static function set(&$array, $key, $value)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return $array = $value;
|
||||
}
|
||||
|
||||
$keys = explode('.', $key);
|
||||
|
||||
while (count($keys) > 1) {
|
||||
$key = array_shift($keys);
|
||||
|
||||
// If the key doesn't exist at this depth, we will just create an empty array
|
||||
// to hold the next value, allowing us to create the arrays to hold final
|
||||
// values at the correct depth. Then we'll keep digging into the array.
|
||||
if (!isset($array[$key]) || !is_array($array[$key])) {
|
||||
$array[$key] = [];
|
||||
}
|
||||
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
$array[array_shift($keys)] = $value;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffle the given array and return the result.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int|null $seed
|
||||
* @return array
|
||||
*/
|
||||
public static function shuffle($array, $seed = null)
|
||||
{
|
||||
if (is_null($seed)) {
|
||||
shuffle($array);
|
||||
} else {
|
||||
srand($seed);
|
||||
|
||||
usort($array, function () {
|
||||
return rand(-1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the array using the given callback or "dot" notation.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable|string|null $callback
|
||||
* @return array
|
||||
*/
|
||||
public static function sort($array, $callback = null)
|
||||
{
|
||||
return Collection::make($array)->sort($callback)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively sort an array by keys and values.
|
||||
*
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public static function sortRecursive($array)
|
||||
{
|
||||
foreach ($array as &$value) {
|
||||
if (is_array($value)) {
|
||||
$value = static::sortRecursive($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (static::isAssoc($array)) {
|
||||
ksort($array);
|
||||
} else {
|
||||
sort($array);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the array into a query string.
|
||||
*
|
||||
* @param array $array
|
||||
* @return string
|
||||
*/
|
||||
public static function query($array)
|
||||
{
|
||||
return http_build_query($array, null, '&', PHP_QUERY_RFC3986);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the array using the given callback.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable $callback
|
||||
* @return array
|
||||
*/
|
||||
public static function where($array, callable $callback)
|
||||
{
|
||||
return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the given value is not an array and not null, wrap it in one.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public static function wrap($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return is_array($value) ? $value : [$value];
|
||||
}
|
||||
}
|
||||
234
vendor/topthink/think-helper/src/helper/Str.php
vendored
Normal file
234
vendor/topthink/think-helper/src/helper/Str.php
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\helper;
|
||||
|
||||
class Str
|
||||
{
|
||||
|
||||
protected static $snakeCache = [];
|
||||
|
||||
protected static $camelCache = [];
|
||||
|
||||
protected static $studlyCache = [];
|
||||
|
||||
/**
|
||||
* 检查字符串中是否包含某些字符串
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
public static function contains(string $haystack, $needles): bool
|
||||
{
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ('' != $needle && mb_strpos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查字符串是否以某些字符串结尾
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
public static function endsWith(string $haystack, $needles): bool
|
||||
{
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ((string) $needle === static::substr($haystack, -static::length($needle))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查字符串是否以某些字符串开头
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
public static function startsWith(string $haystack, $needles): bool
|
||||
{
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ('' != $needle && mb_strpos($haystack, $needle) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定长度的随机字母数字组合的字符串
|
||||
*
|
||||
* @param int $length
|
||||
* @param int $type
|
||||
* @param string $addChars
|
||||
* @return string
|
||||
*/
|
||||
public static function random(int $length = 6, int $type = null, string $addChars = ''): string
|
||||
{
|
||||
$str = '';
|
||||
switch ($type) {
|
||||
case 0:
|
||||
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars;
|
||||
break;
|
||||
case 1:
|
||||
$chars = str_repeat('0123456789', 3);
|
||||
break;
|
||||
case 2:
|
||||
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars;
|
||||
break;
|
||||
case 3:
|
||||
$chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars;
|
||||
break;
|
||||
case 4:
|
||||
$chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书" . $addChars;
|
||||
break;
|
||||
default:
|
||||
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
|
||||
break;
|
||||
}
|
||||
if ($length > 10) {
|
||||
$chars = $type == 1 ? str_repeat($chars, $length) : str_repeat($chars, 5);
|
||||
}
|
||||
if ($type != 4) {
|
||||
$chars = str_shuffle($chars);
|
||||
$str = substr($chars, 0, $length);
|
||||
} else {
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= mb_substr($chars, floor(mt_rand(0, mb_strlen($chars, 'utf-8') - 1)), 1);
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转小写
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function lower(string $value): string
|
||||
{
|
||||
return mb_strtolower($value, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转大写
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function upper(string $value): string
|
||||
{
|
||||
return mb_strtoupper($value, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串的长度
|
||||
*
|
||||
* @param string $value
|
||||
* @return int
|
||||
*/
|
||||
public static function length(string $value): int
|
||||
{
|
||||
return mb_strlen($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $start
|
||||
* @param int|null $length
|
||||
* @return string
|
||||
*/
|
||||
public static function substr(string $string, int $start, int $length = null): string
|
||||
{
|
||||
return mb_substr($string, $start, $length, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰转下划线
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $delimiter
|
||||
* @return string
|
||||
*/
|
||||
public static function snake(string $value, string $delimiter = '_'): string
|
||||
{
|
||||
$key = $value;
|
||||
|
||||
if (isset(static::$snakeCache[$key][$delimiter])) {
|
||||
return static::$snakeCache[$key][$delimiter];
|
||||
}
|
||||
|
||||
if (!ctype_lower($value)) {
|
||||
$value = preg_replace('/\s+/u', '', ucwords($value));
|
||||
|
||||
$value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value));
|
||||
}
|
||||
|
||||
return static::$snakeCache[$key][$delimiter] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下划线转驼峰(首字母小写)
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function camel(string $value): string
|
||||
{
|
||||
if (isset(static::$camelCache[$value])) {
|
||||
return static::$camelCache[$value];
|
||||
}
|
||||
|
||||
return static::$camelCache[$value] = lcfirst(static::studly($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 下划线转驼峰(首字母大写)
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function studly(string $value): string
|
||||
{
|
||||
$key = $value;
|
||||
|
||||
if (isset(static::$studlyCache[$key])) {
|
||||
return static::$studlyCache[$key];
|
||||
}
|
||||
|
||||
$value = ucwords(str_replace(['-', '_'], ' ', $value));
|
||||
|
||||
return static::$studlyCache[$key] = str_replace(' ', '', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为首字母大写的标题格式
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function title(string $value): string
|
||||
{
|
||||
return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
|
||||
}
|
||||
}
|
||||
342
vendor/topthink/think-helper/tests/ArrTest.php
vendored
Normal file
342
vendor/topthink/think-helper/tests/ArrTest.php
vendored
Normal file
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use stdClass;
|
||||
use think\Collection;
|
||||
use think\helper\Arr;
|
||||
|
||||
class ArrTest extends TestCase
|
||||
{
|
||||
public function testAdd()
|
||||
{
|
||||
$array = Arr::add(['name' => 'ThinkPHP'], 'price', 100);
|
||||
$this->assertSame(['name' => 'ThinkPHP', 'price' => 100], $array);
|
||||
}
|
||||
|
||||
public function testCrossJoin()
|
||||
{
|
||||
// Single dimension
|
||||
$this->assertSame(
|
||||
[[1, 'a'], [1, 'b'], [1, 'c']],
|
||||
Arr::crossJoin([1], ['a', 'b', 'c'])
|
||||
);
|
||||
// Square matrix
|
||||
$this->assertSame(
|
||||
[[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']],
|
||||
Arr::crossJoin([1, 2], ['a', 'b'])
|
||||
);
|
||||
// Rectangular matrix
|
||||
$this->assertSame(
|
||||
[[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']],
|
||||
Arr::crossJoin([1, 2], ['a', 'b', 'c'])
|
||||
);
|
||||
// 3D matrix
|
||||
$this->assertSame(
|
||||
[
|
||||
[1, 'a', 'I'], [1, 'a', 'II'], [1, 'a', 'III'],
|
||||
[1, 'b', 'I'], [1, 'b', 'II'], [1, 'b', 'III'],
|
||||
[2, 'a', 'I'], [2, 'a', 'II'], [2, 'a', 'III'],
|
||||
[2, 'b', 'I'], [2, 'b', 'II'], [2, 'b', 'III'],
|
||||
],
|
||||
Arr::crossJoin([1, 2], ['a', 'b'], ['I', 'II', 'III'])
|
||||
);
|
||||
// With 1 empty dimension
|
||||
$this->assertSame([], Arr::crossJoin([], ['a', 'b'], ['I', 'II', 'III']));
|
||||
$this->assertSame([], Arr::crossJoin([1, 2], [], ['I', 'II', 'III']));
|
||||
$this->assertSame([], Arr::crossJoin([1, 2], ['a', 'b'], []));
|
||||
// With empty arrays
|
||||
$this->assertSame([], Arr::crossJoin([], [], []));
|
||||
$this->assertSame([], Arr::crossJoin([], []));
|
||||
$this->assertSame([], Arr::crossJoin([]));
|
||||
// Not really a proper usage, still, test for preserving BC
|
||||
$this->assertSame([[]], Arr::crossJoin());
|
||||
}
|
||||
|
||||
public function testDivide()
|
||||
{
|
||||
list($keys, $values) = Arr::divide(['name' => 'ThinkPHP']);
|
||||
$this->assertSame(['name'], $keys);
|
||||
$this->assertSame(['ThinkPHP'], $values);
|
||||
}
|
||||
|
||||
public function testDot()
|
||||
{
|
||||
$array = Arr::dot(['foo' => ['bar' => 'baz']]);
|
||||
$this->assertSame(['foo.bar' => 'baz'], $array);
|
||||
$array = Arr::dot([]);
|
||||
$this->assertSame([], $array);
|
||||
$array = Arr::dot(['foo' => []]);
|
||||
$this->assertSame(['foo' => []], $array);
|
||||
$array = Arr::dot(['foo' => ['bar' => []]]);
|
||||
$this->assertSame(['foo.bar' => []], $array);
|
||||
}
|
||||
|
||||
public function testExcept()
|
||||
{
|
||||
$array = ['name' => 'ThinkPHP', 'price' => 100];
|
||||
$array = Arr::except($array, ['price']);
|
||||
$this->assertSame(['name' => 'ThinkPHP'], $array);
|
||||
}
|
||||
|
||||
public function testExists()
|
||||
{
|
||||
$this->assertTrue(Arr::exists([1], 0));
|
||||
$this->assertTrue(Arr::exists([null], 0));
|
||||
$this->assertTrue(Arr::exists(['a' => 1], 'a'));
|
||||
$this->assertTrue(Arr::exists(['a' => null], 'a'));
|
||||
$this->assertFalse(Arr::exists([1], 1));
|
||||
$this->assertFalse(Arr::exists([null], 1));
|
||||
$this->assertFalse(Arr::exists(['a' => 1], 0));
|
||||
}
|
||||
|
||||
public function testFirst()
|
||||
{
|
||||
$array = [100, 200, 300];
|
||||
$value = Arr::first($array, function ($value) {
|
||||
return $value >= 150;
|
||||
});
|
||||
$this->assertSame(200, $value);
|
||||
$this->assertSame(100, Arr::first($array));
|
||||
|
||||
$this->assertSame('default', Arr::first([], null, 'default'));
|
||||
|
||||
$this->assertSame('default', Arr::first([], function () {
|
||||
return false;
|
||||
}, 'default'));
|
||||
}
|
||||
|
||||
public function testLast()
|
||||
{
|
||||
$array = [100, 200, 300];
|
||||
$last = Arr::last($array, function ($value) {
|
||||
return $value < 250;
|
||||
});
|
||||
$this->assertSame(200, $last);
|
||||
$last = Arr::last($array, function ($value, $key) {
|
||||
return $key < 2;
|
||||
});
|
||||
$this->assertSame(200, $last);
|
||||
$this->assertSame(300, Arr::last($array));
|
||||
}
|
||||
|
||||
public function testFlatten()
|
||||
{
|
||||
// Flat arrays are unaffected
|
||||
$array = ['#foo', '#bar', '#baz'];
|
||||
$this->assertSame(['#foo', '#bar', '#baz'], Arr::flatten(['#foo', '#bar', '#baz']));
|
||||
// Nested arrays are flattened with existing flat items
|
||||
$array = [['#foo', '#bar'], '#baz'];
|
||||
$this->assertSame(['#foo', '#bar', '#baz'], Arr::flatten($array));
|
||||
// Flattened array includes "null" items
|
||||
$array = [['#foo', null], '#baz', null];
|
||||
$this->assertSame(['#foo', null, '#baz', null], Arr::flatten($array));
|
||||
// Sets of nested arrays are flattened
|
||||
$array = [['#foo', '#bar'], ['#baz']];
|
||||
$this->assertSame(['#foo', '#bar', '#baz'], Arr::flatten($array));
|
||||
// Deeply nested arrays are flattened
|
||||
$array = [['#foo', ['#bar']], ['#baz']];
|
||||
$this->assertSame(['#foo', '#bar', '#baz'], Arr::flatten($array));
|
||||
// Nested arrays are flattened alongside arrays
|
||||
$array = [new Collection(['#foo', '#bar']), ['#baz']];
|
||||
$this->assertSame(['#foo', '#bar', '#baz'], Arr::flatten($array));
|
||||
// Nested arrays containing plain arrays are flattened
|
||||
$array = [new Collection(['#foo', ['#bar']]), ['#baz']];
|
||||
$this->assertSame(['#foo', '#bar', '#baz'], Arr::flatten($array));
|
||||
// Nested arrays containing arrays are flattened
|
||||
$array = [['#foo', new Collection(['#bar'])], ['#baz']];
|
||||
$this->assertSame(['#foo', '#bar', '#baz'], Arr::flatten($array));
|
||||
// Nested arrays containing arrays containing arrays are flattened
|
||||
$array = [['#foo', new Collection(['#bar', ['#zap']])], ['#baz']];
|
||||
$this->assertSame(['#foo', '#bar', '#zap', '#baz'], Arr::flatten($array));
|
||||
}
|
||||
|
||||
public function testFlattenWithDepth()
|
||||
{
|
||||
// No depth flattens recursively
|
||||
$array = [['#foo', ['#bar', ['#baz']]], '#zap'];
|
||||
$this->assertSame(['#foo', '#bar', '#baz', '#zap'], Arr::flatten($array));
|
||||
// Specifying a depth only flattens to that depth
|
||||
$array = [['#foo', ['#bar', ['#baz']]], '#zap'];
|
||||
$this->assertSame(['#foo', ['#bar', ['#baz']], '#zap'], Arr::flatten($array, 1));
|
||||
$array = [['#foo', ['#bar', ['#baz']]], '#zap'];
|
||||
$this->assertSame(['#foo', '#bar', ['#baz'], '#zap'], Arr::flatten($array, 2));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$array = ['products.item' => ['price' => 100]];
|
||||
$this->assertSame(['price' => 100], Arr::get($array, 'products.item'));
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
$value = Arr::get($array, 'products.item');
|
||||
$this->assertSame(['price' => 100], $value);
|
||||
// Test null array values
|
||||
$array = ['foo' => null, 'bar' => ['baz' => null]];
|
||||
$this->assertNull(Arr::get($array, 'foo', 'default'));
|
||||
$this->assertNull(Arr::get($array, 'bar.baz', 'default'));
|
||||
// Test null key returns the whole array
|
||||
$array = ['foo', 'bar'];
|
||||
$this->assertSame($array, Arr::get($array, null));
|
||||
// Test $array is empty and key is null
|
||||
$this->assertSame([], Arr::get([], null));
|
||||
$this->assertSame([], Arr::get([], null, 'default'));
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$array = ['products.item' => ['price' => 100]];
|
||||
$this->assertTrue(Arr::has($array, 'products.item'));
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
$this->assertTrue(Arr::has($array, 'products.item'));
|
||||
$this->assertTrue(Arr::has($array, 'products.item.price'));
|
||||
$this->assertFalse(Arr::has($array, 'products.foo'));
|
||||
$this->assertFalse(Arr::has($array, 'products.item.foo'));
|
||||
$array = ['foo' => null, 'bar' => ['baz' => null]];
|
||||
$this->assertTrue(Arr::has($array, 'foo'));
|
||||
$this->assertTrue(Arr::has($array, 'bar.baz'));
|
||||
$array = ['foo', 'bar'];
|
||||
$this->assertFalse(Arr::has($array, null));
|
||||
$this->assertFalse(Arr::has([], null));
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
$this->assertTrue(Arr::has($array, ['products.item']));
|
||||
$this->assertTrue(Arr::has($array, ['products.item', 'products.item.price']));
|
||||
$this->assertTrue(Arr::has($array, ['products', 'products']));
|
||||
$this->assertFalse(Arr::has($array, ['foo']));
|
||||
$this->assertFalse(Arr::has($array, []));
|
||||
$this->assertFalse(Arr::has($array, ['products.item', 'products.price']));
|
||||
$this->assertFalse(Arr::has([], [null]));
|
||||
}
|
||||
|
||||
public function testIsAssoc()
|
||||
{
|
||||
$this->assertTrue(Arr::isAssoc(['a' => 'a', 0 => 'b']));
|
||||
$this->assertTrue(Arr::isAssoc([1 => 'a', 0 => 'b']));
|
||||
$this->assertTrue(Arr::isAssoc([1 => 'a', 2 => 'b']));
|
||||
$this->assertFalse(Arr::isAssoc([0 => 'a', 1 => 'b']));
|
||||
$this->assertFalse(Arr::isAssoc(['a', 'b']));
|
||||
}
|
||||
|
||||
public function testOnly()
|
||||
{
|
||||
$array = ['name' => 'ThinkPHP', 'price' => 100, 'orders' => 10];
|
||||
$array = Arr::only($array, ['name', 'price']);
|
||||
$this->assertSame(['name' => 'ThinkPHP', 'price' => 100], $array);
|
||||
}
|
||||
|
||||
public function testPrepend()
|
||||
{
|
||||
$array = Arr::prepend(['one', 'two', 'three', 'four'], 'zero');
|
||||
$this->assertSame(['zero', 'one', 'two', 'three', 'four'], $array);
|
||||
$array = Arr::prepend(['one' => 1, 'two' => 2], 0, 'zero');
|
||||
$this->assertSame(['zero' => 0, 'one' => 1, 'two' => 2], $array);
|
||||
}
|
||||
|
||||
public function testPull()
|
||||
{
|
||||
$array = ['name' => 'ThinkPHP', 'price' => 100];
|
||||
$name = Arr::pull($array, 'name');
|
||||
$this->assertSame('ThinkPHP', $name);
|
||||
$this->assertSame(['price' => 100], $array);
|
||||
// Only works on first level keys
|
||||
$array = ['i@example.com' => 'Joe', 'jack@localhost' => 'Jane'];
|
||||
$name = Arr::pull($array, 'i@example.com');
|
||||
$this->assertSame('Joe', $name);
|
||||
$this->assertSame(['jack@localhost' => 'Jane'], $array);
|
||||
// Does not work for nested keys
|
||||
$array = ['emails' => ['i@example.com' => 'Joe', 'jack@localhost' => 'Jane']];
|
||||
$name = Arr::pull($array, 'emails.i@example.com');
|
||||
$this->assertNull($name);
|
||||
$this->assertSame(['emails' => ['i@example.com' => 'Joe', 'jack@localhost' => 'Jane']], $array);
|
||||
}
|
||||
|
||||
public function testRandom()
|
||||
{
|
||||
$randomValue = Arr::random(['foo', 'bar', 'baz']);
|
||||
$this->assertContains($randomValue, ['foo', 'bar', 'baz']);
|
||||
$randomValues = Arr::random(['foo', 'bar', 'baz'], 1);
|
||||
$this->assertIsArray($randomValues);
|
||||
$this->assertCount(1, $randomValues);
|
||||
$this->assertContains($randomValues[0], ['foo', 'bar', 'baz']);
|
||||
$randomValues = Arr::random(['foo', 'bar', 'baz'], 2);
|
||||
$this->assertIsArray($randomValues);
|
||||
$this->assertCount(2, $randomValues);
|
||||
$this->assertContains($randomValues[0], ['foo', 'bar', 'baz']);
|
||||
$this->assertContains($randomValues[1], ['foo', 'bar', 'baz']);
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
Arr::set($array, 'products.item.price', 200);
|
||||
Arr::set($array, 'goods.item.price', 200);
|
||||
$this->assertSame(['products' => ['item' => ['price' => 200]], 'goods' => ['item' => ['price' => 200]]], $array);
|
||||
}
|
||||
|
||||
public function testWhere()
|
||||
{
|
||||
$array = [100, '200', 300, '400', 500];
|
||||
$array = Arr::where($array, function ($value, $key) {
|
||||
return is_string($value);
|
||||
});
|
||||
$this->assertSame([1 => '200', 3 => '400'], $array);
|
||||
}
|
||||
|
||||
public function testWhereKey()
|
||||
{
|
||||
$array = ['10' => 1, 'foo' => 3, 20 => 2];
|
||||
$array = Arr::where($array, function ($value, $key) {
|
||||
return is_numeric($key);
|
||||
});
|
||||
$this->assertSame(['10' => 1, 20 => 2], $array);
|
||||
}
|
||||
|
||||
public function testForget()
|
||||
{
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
Arr::forget($array, null);
|
||||
$this->assertSame(['products' => ['item' => ['price' => 100]]], $array);
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
Arr::forget($array, []);
|
||||
$this->assertSame(['products' => ['item' => ['price' => 100]]], $array);
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
Arr::forget($array, 'products.item');
|
||||
$this->assertSame(['products' => []], $array);
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
Arr::forget($array, 'products.item.price');
|
||||
$this->assertSame(['products' => ['item' => []]], $array);
|
||||
$array = ['products' => ['item' => ['price' => 100]]];
|
||||
Arr::forget($array, 'products.final.price');
|
||||
$this->assertSame(['products' => ['item' => ['price' => 100]]], $array);
|
||||
$array = ['shop' => ['cart' => [150 => 0]]];
|
||||
Arr::forget($array, 'shop.final.cart');
|
||||
$this->assertSame(['shop' => ['cart' => [150 => 0]]], $array);
|
||||
$array = ['products' => ['item' => ['price' => ['original' => 50, 'taxes' => 60]]]];
|
||||
Arr::forget($array, 'products.item.price.taxes');
|
||||
$this->assertSame(['products' => ['item' => ['price' => ['original' => 50]]]], $array);
|
||||
$array = ['products' => ['item' => ['price' => ['original' => 50, 'taxes' => 60]]]];
|
||||
Arr::forget($array, 'products.item.final.taxes');
|
||||
$this->assertSame(['products' => ['item' => ['price' => ['original' => 50, 'taxes' => 60]]]], $array);
|
||||
$array = ['products' => ['item' => ['price' => 50], null => 'something']];
|
||||
Arr::forget($array, ['products.amount.all', 'products.item.price']);
|
||||
$this->assertSame(['products' => ['item' => [], null => 'something']], $array);
|
||||
// Only works on first level keys
|
||||
$array = ['i@example.com' => 'Joe', 'i@thinkphp.com' => 'Jane'];
|
||||
Arr::forget($array, 'i@example.com');
|
||||
$this->assertSame(['i@thinkphp.com' => 'Jane'], $array);
|
||||
// Does not work for nested keys
|
||||
$array = ['emails' => ['i@example.com' => ['name' => 'Joe'], 'jack@localhost' => ['name' => 'Jane']]];
|
||||
Arr::forget($array, ['emails.i@example.com', 'emails.jack@localhost']);
|
||||
$this->assertSame(['emails' => ['i@example.com' => ['name' => 'Joe']]], $array);
|
||||
}
|
||||
|
||||
public function testWrap()
|
||||
{
|
||||
$string = 'a';
|
||||
$array = ['a'];
|
||||
$object = new stdClass();
|
||||
$object->value = 'a';
|
||||
$this->assertSame(['a'], Arr::wrap($string));
|
||||
$this->assertSame($array, Arr::wrap($array));
|
||||
$this->assertSame([$object], Arr::wrap($object));
|
||||
}
|
||||
}
|
||||
70
vendor/topthink/think-helper/tests/CollectionTest.php
vendored
Normal file
70
vendor/topthink/think-helper/tests/CollectionTest.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use think\Collection;
|
||||
|
||||
class CollectionTest extends TestCase
|
||||
{
|
||||
public function testMerge()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello']);
|
||||
$this->assertSame(['name' => 'Hello', 'id' => 1], $c->merge(['id' => 1])->all());
|
||||
}
|
||||
|
||||
public function testFirst()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello', 'age' => 25]);
|
||||
|
||||
$this->assertSame('Hello', $c->first());
|
||||
}
|
||||
|
||||
public function testLast()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello', 'age' => 25]);
|
||||
|
||||
$this->assertSame(25, $c->last());
|
||||
}
|
||||
|
||||
public function testToArray()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello', 'age' => 25]);
|
||||
|
||||
$this->assertSame(['name' => 'Hello', 'age' => 25], $c->toArray());
|
||||
}
|
||||
|
||||
public function testToJson()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello', 'age' => 25]);
|
||||
|
||||
$this->assertSame(json_encode(['name' => 'Hello', 'age' => 25]), $c->toJson());
|
||||
$this->assertSame(json_encode(['name' => 'Hello', 'age' => 25]), (string) $c);
|
||||
$this->assertSame(json_encode(['name' => 'Hello', 'age' => 25]), json_encode($c));
|
||||
}
|
||||
|
||||
public function testSerialize()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello', 'age' => 25]);
|
||||
|
||||
$sc = serialize($c);
|
||||
$c = unserialize($sc);
|
||||
|
||||
$this->assertSame(['name' => 'Hello', 'age' => 25], $c->all());
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello', 'age' => 25]);
|
||||
|
||||
$this->assertInstanceOf(\ArrayIterator::class, $c->getIterator());
|
||||
|
||||
$this->assertSame(['name' => 'Hello', 'age' => 25], $c->getIterator()->getArrayCopy());
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$c = new Collection(['name' => 'Hello', 'age' => 25]);
|
||||
|
||||
$this->assertCount(2, $c);
|
||||
}
|
||||
}
|
||||
59
vendor/topthink/think-helper/tests/StrTest.php
vendored
Normal file
59
vendor/topthink/think-helper/tests/StrTest.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Tests;
|
||||
|
||||
use think\helper\Str;
|
||||
|
||||
class StrTest extends TestCase
|
||||
{
|
||||
public function testCamel()
|
||||
{
|
||||
$this->assertSame('fooBar', Str::camel('FooBar'));
|
||||
$this->assertSame('fooBar', Str::camel('FooBar'));
|
||||
$this->assertSame('fooBar', Str::camel('foo_bar'));
|
||||
$this->assertSame('fooBar', Str::camel('_foo_bar'));
|
||||
$this->assertSame('fooBar', Str::camel('_foo_bar_'));
|
||||
}
|
||||
|
||||
public function testStudly()
|
||||
{
|
||||
$this->assertSame('FooBar', Str::studly('fooBar'));
|
||||
$this->assertSame('FooBar', Str::studly('_foo_bar'));
|
||||
$this->assertSame('FooBar', Str::studly('_foo_bar_'));
|
||||
$this->assertSame('FooBar', Str::studly('_foo_bar_'));
|
||||
}
|
||||
|
||||
public function testSnake()
|
||||
{
|
||||
$this->assertSame('think_p_h_p_framework', Str::snake('ThinkPHPFramework'));
|
||||
$this->assertSame('think_php_framework', Str::snake('ThinkPhpFramework'));
|
||||
$this->assertSame('think php framework', Str::snake('ThinkPhpFramework', ' '));
|
||||
$this->assertSame('think_php_framework', Str::snake('Think Php Framework'));
|
||||
$this->assertSame('think_php_framework', Str::snake('Think Php Framework '));
|
||||
// ensure cache keys don't overlap
|
||||
$this->assertSame('think__php__framework', Str::snake('ThinkPhpFramework', '__'));
|
||||
$this->assertSame('think_php_framework_', Str::snake('ThinkPhpFramework_', '_'));
|
||||
$this->assertSame('think_php_framework', Str::snake('think php Framework'));
|
||||
$this->assertSame('think_php_frame_work', Str::snake('think php FrameWork'));
|
||||
// prevent breaking changes
|
||||
$this->assertSame('foo-bar', Str::snake('foo-bar'));
|
||||
$this->assertSame('foo-_bar', Str::snake('Foo-Bar'));
|
||||
$this->assertSame('foo__bar', Str::snake('Foo_Bar'));
|
||||
$this->assertSame('żółtałódka', Str::snake('ŻółtaŁódka'));
|
||||
}
|
||||
|
||||
public function testTitle()
|
||||
{
|
||||
$this->assertSame('Welcome Back', Str::title('welcome back'));
|
||||
}
|
||||
|
||||
public function testRandom()
|
||||
{
|
||||
$this->assertIsString(Str::random(10));
|
||||
}
|
||||
|
||||
public function testUpper()
|
||||
{
|
||||
$this->assertSame('USERNAME', Str::upper('username'));
|
||||
$this->assertSame('USERNAME', Str::upper('userNaMe'));
|
||||
}
|
||||
}
|
||||
13
vendor/topthink/think-helper/tests/TestCase.php
vendored
Normal file
13
vendor/topthink/think-helper/tests/TestCase.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
|
||||
/**
|
||||
* Class TestCase
|
||||
* @author Tongle Xu <xutongle@gmail.com>
|
||||
*/
|
||||
class TestCase extends BaseTestCase
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user