添加网站文件
This commit is contained in:
7
vendor/songshenzong/support/.gitignore
vendored
Normal file
7
vendor/songshenzong/support/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
.DS_Store
|
||||
.idea
|
||||
/vendor/
|
||||
/support.iml
|
||||
build
|
||||
composer.lock
|
||||
/.php_cs.cache
|
||||
22
vendor/songshenzong/support/.travis.yml
vendored
Normal file
22
vendor/songshenzong/support/.travis.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
language: php
|
||||
install: true
|
||||
php:
|
||||
- 7.2
|
||||
before_script:
|
||||
- composer install --no-interaction --prefer-source --dev
|
||||
- curl -sSfL -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar
|
||||
script: phpunit
|
||||
before_deploy:
|
||||
- git config --local user.email "i@songshenzong.com"
|
||||
- git config --local user.name "Songshenzong"
|
||||
- export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
|
||||
- git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: tMfMInav0NrKJUZw861pXhAfhioLm/f6dSP9fyNePOnUbbKAqubac6Lh6IbVLlM//tY+hF5p0Ln4q1XYn7JAd9PzO3tWkZC83HDIP9cbZnMKqXU5EaX2fuRwbxt82ISYXbKtwfRBtR2ZkTUSk1rh1TtjkXSJ5Wpv+An2GefF5jwPKeME6fqLsIlCBlReFFD+o36wJaS8vMIIsOsaVxmhZsjBpSBAX6YyV+bOGwgK6YTfPXjh3nz7JrJ1mx+XxFU60cMlpYHgw46FF9ZgJB03T+UtQswUTGDtHdSmVP4nentzuw90prO2w51fOK4cLj7c2Bx/9Wda4Cte8XO1g7sBoSuVaHDtn3qini8pSA1jvjx6GXojqk3NnV3PLA+BOJm7yrNWssrAQxPBm6PJsF7YSrX418MTzoMhvz8TBmc6R9S5r7kyeaB4pY0ZP6O/04C59U/79sVbQO184FkiIX5Ezf7wRsaKCuxa/FavyAdfXG4WmDQLJmvLUa1bzvRd+O94/I9eoh+1/YhN7sPlXctHjdWKIdy5StkB43gP7r+DorBWF3rHrtmGTjAk17SJxyTsiqDmLgNTTeu5+f9j/40Jz65fiN1QFLTQBVXKEWcaGX1kB85GRpa4mQebI7TzqGpGHPkP+3Fc7Fjw8Jc6a06LTDPJVSMSSChi8j/IKYyMb0k=
|
||||
file:
|
||||
- "README.md"
|
||||
on:
|
||||
repo: songshenzong/support
|
||||
tags: true
|
||||
24
vendor/songshenzong/support/CHANGELOG.md
vendored
Normal file
24
vendor/songshenzong/support/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# ChangeLog
|
||||
|
||||
---
|
||||
|
||||
## 2.0.5 - 2019-08-30
|
||||
- Improved `Time`.
|
||||
|
||||
## 2.0.4 - 2019-08-30
|
||||
- Added `Time`.
|
||||
|
||||
## 2.0.3 - 2019-08-27
|
||||
- Added `Env` for `OS`.
|
||||
|
||||
## 2.0.2 - 2019-08-14
|
||||
- Added `get` for `Arrays`.
|
||||
|
||||
## 2.0.1 - 2019-06-12
|
||||
- Added `Arrays`.
|
||||
|
||||
## 2.0.0 - 2019-06-12
|
||||
- Improved Design.
|
||||
|
||||
## 1.0.0 - 2017-03-07
|
||||
- Released
|
||||
19
vendor/songshenzong/support/LICENSE.txt
vendored
Normal file
19
vendor/songshenzong/support/LICENSE.txt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (C) 2019 Songshenzong
|
||||
|
||||
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.
|
||||
32
vendor/songshenzong/support/README.md
vendored
Normal file
32
vendor/songshenzong/support/README.md
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
[][travis]
|
||||
[][packagist]
|
||||
[][packagist]
|
||||
[][packagist]
|
||||
[][packagist]
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Require this package with composer:
|
||||
|
||||
|
||||
```shell
|
||||
composer require songshenzong/support
|
||||
```
|
||||
|
||||
## Quick Examples
|
||||
|
||||
Please refer to our extensive [Wiki documentation](https://github.com/songshenzong/support/wiki) for more information.
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
For answers you may not find in the Wiki, avoid posting issues. Feel free to ask for support on Songshenzong.com
|
||||
|
||||
|
||||
## License
|
||||
|
||||
This package is licensed under the [BSD 3-Clause license](http://opensource.org/licenses/BSD-3-Clause).
|
||||
|
||||
[packagist]: https://packagist.org/packages/songshenzong/support
|
||||
[travis]: https://travis-ci.org/songshenzong/support
|
||||
60
vendor/songshenzong/support/composer.json
vendored
Normal file
60
vendor/songshenzong/support/composer.json
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"name": "songshenzong/support",
|
||||
"description": "The Songshenzong Support package.",
|
||||
"keywords": [
|
||||
"support",
|
||||
"laravel",
|
||||
"web",
|
||||
"Tools"
|
||||
],
|
||||
"license": "MIT",
|
||||
"homepage": "http://songshenzong.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/songshenzong/support/issues",
|
||||
"source": "https://github.com/songshenzong/support"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Songshenzong",
|
||||
"email": "i@songshenzong.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5",
|
||||
"ext-xml": "*",
|
||||
"ext-json": "*",
|
||||
"ext-simplexml": "*",
|
||||
"danielstjules/stringy": "^3.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35|^5.4.3",
|
||||
"laravel/framework": "^5.8"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Songshenzong\\Support\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/StringsHelpers.php",
|
||||
"src/BashEchoHelpers.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Songshenzong\\Support\\Test\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Songshenzong\\Support\\StringsServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Strings": "Songshenzong\\Support\\StringsFacade"
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"fixer": "php-cs-fixer fix ./"
|
||||
}
|
||||
}
|
||||
35
vendor/songshenzong/support/phpunit.xml
vendored
Normal file
35
vendor/songshenzong/support/phpunit.xml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="./tests/bootstrap.php"
|
||||
colors="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
testSuiteLoaderFile="phpunit/src/Runner/StandardTestSuiteLoader.php">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="All">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>integration</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
|
||||
<logging>
|
||||
<log type="junit" target="build/junit.xml"/>
|
||||
<log type="coverage-clover" target="build/coverage/clover.xml"/>
|
||||
</logging>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./src</directory>
|
||||
<exclude>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
84
vendor/songshenzong/support/src/Arrays.php
vendored
Normal file
84
vendor/songshenzong/support/src/Arrays.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Class Arrays
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class Arrays
|
||||
{
|
||||
/**
|
||||
* @param array $arrays
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function merge(array $arrays)
|
||||
{
|
||||
$result = [];
|
||||
foreach ($arrays as $array) {
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$result[] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($result[$key]) && is_array($result[$key])) {
|
||||
$result[$key] = self::merge(
|
||||
[$result[$key], $value]
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns item from array or $default if item is not set.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string|int|array $key one or more keys
|
||||
* @param null $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get(array $array, $key, $default = null)
|
||||
{
|
||||
foreach (is_array($key) ? $key : [$key] as $k) {
|
||||
if (is_array($array) && array_key_exists($k, $array)) {
|
||||
$array = $array[$k];
|
||||
} else {
|
||||
if (func_num_args() < 3) {
|
||||
throw new InvalidArgumentException("Missing item '$k'.");
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $system_version
|
||||
*/
|
||||
public static function versionCompare(array &$system_version)
|
||||
{
|
||||
for ($i = 0; $i < count($system_version) - 1; $i++) {
|
||||
for ($j = 0; $j < count($system_version) - 1 - $i; $j++) {
|
||||
if (version_compare($system_version[$j], $system_version[$j + 1], '<')) {
|
||||
$tmp = $system_version[$j];
|
||||
$system_version[$j] = $system_version[$j + 1];
|
||||
$system_version[$j + 1] = $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
72
vendor/songshenzong/support/src/BashEcho.php
vendored
Normal file
72
vendor/songshenzong/support/src/BashEcho.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
/**
|
||||
* Class BashEcho
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class BashEcho
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public static function echoRed($string)
|
||||
{
|
||||
$cmd = "echo -ne \"\033[31m" . $string . " \033[0m\n\"";
|
||||
$a = exec($cmd);
|
||||
print $a . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public static function echoCyan($string)
|
||||
{
|
||||
$cmd = "printf \"\033[35m" . $string . "\033[0m\n\"";
|
||||
$a = exec($cmd);
|
||||
print $a . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public static function echoGreen($string)
|
||||
{
|
||||
$cmd = "printf \"\033[32m" . $string . "\033[0m\n\"";
|
||||
$a = exec($cmd);
|
||||
print $a . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public static function echoBrown($string)
|
||||
{
|
||||
$cmd = "printf \"\033[33m" . $string . "\033[0m\n\"";
|
||||
$a = exec($cmd);
|
||||
print $a . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public static function echoBlue($string)
|
||||
{
|
||||
$cmd = "printf \"\033[34m" . $string . "\033[0m\n\"";
|
||||
$a = exec($cmd);
|
||||
print $a . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public static function echoPurple($string)
|
||||
{
|
||||
$cmd = "printf \"\033[35m" . $string . "\033[0m\n\"";
|
||||
$a = exec($cmd);
|
||||
print $a . PHP_EOL;
|
||||
}
|
||||
}
|
||||
64
vendor/songshenzong/support/src/BashEchoHelpers.php
vendored
Normal file
64
vendor/songshenzong/support/src/BashEchoHelpers.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use Songshenzong\Support\BashEcho;
|
||||
|
||||
if (!function_exists('echoRed')) {
|
||||
/**
|
||||
* @param $string
|
||||
*/
|
||||
function echoRed($string)
|
||||
{
|
||||
BashEcho::echoRed($string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('echoGreen')) {
|
||||
/**
|
||||
* @param $string
|
||||
*/
|
||||
function echoGreen($string)
|
||||
{
|
||||
BashEcho::echoGreen($string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('echoBrown')) {
|
||||
/**
|
||||
* @param $string
|
||||
*/
|
||||
function echoBrown($string)
|
||||
{
|
||||
BashEcho::echoBrown($string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('echoBlue')) {
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
*/
|
||||
function echoBlue($string)
|
||||
{
|
||||
BashEcho::echoBlue($string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('echoPurple')) {
|
||||
/**
|
||||
* @param $string
|
||||
*/
|
||||
function echoPurple($string)
|
||||
{
|
||||
BashEcho::echoPurple($string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('echoCyan')) {
|
||||
/**
|
||||
* @param $string
|
||||
*/
|
||||
function echoCyan($string)
|
||||
{
|
||||
BashEcho::echoCyan($string);
|
||||
}
|
||||
}
|
||||
101
vendor/songshenzong/support/src/Env.php
vendored
Normal file
101
vendor/songshenzong/support/src/Env.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Class Env
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class Env
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the value of an environment variable.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function env($key, $default = null)
|
||||
{
|
||||
$value = getenv($key);
|
||||
|
||||
if ($value === false) {
|
||||
return self::value($default);
|
||||
}
|
||||
|
||||
if (self::envSubstr($value)) {
|
||||
return substr($value, 1, -1);
|
||||
}
|
||||
|
||||
return self::envConversion($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function envNotEmpty($key)
|
||||
{
|
||||
$value = self::env($key, false);
|
||||
if ($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function value($value)
|
||||
{
|
||||
return $value instanceof Closure ? $value() : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function envSubstr($value)
|
||||
{
|
||||
return ($valueLength = strlen($value)) > 1
|
||||
&& strpos($value, '"') === 0
|
||||
&& $value[$valueLength - 1] === '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function envConversion($value)
|
||||
{
|
||||
$key = strtolower($value);
|
||||
|
||||
if ($key === 'null' || $key === '(null)') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$list = [
|
||||
'true' => true,
|
||||
'(true)' => true,
|
||||
'false' => false,
|
||||
'(false)' => false,
|
||||
'empty' => '',
|
||||
'(empty)' => '',
|
||||
];
|
||||
|
||||
return isset($list[$key]) ? $list[$key] : $value;
|
||||
}
|
||||
}
|
||||
75
vendor/songshenzong/support/src/OS.php
vendored
Normal file
75
vendor/songshenzong/support/src/OS.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
use Stringy\Stringy;
|
||||
|
||||
/**
|
||||
* Class OS
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class OS
|
||||
{
|
||||
/**
|
||||
* @param $filename
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function inOpenBasedir($filename)
|
||||
{
|
||||
$open_basedir = ini_get('open_basedir');
|
||||
if (!$open_basedir) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$dirs = explode(PATH_SEPARATOR, $open_basedir);
|
||||
|
||||
return empty($dirs) || self::inDir($filename, $dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @param array $dirs
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function inDir($filename, array $dirs)
|
||||
{
|
||||
foreach ($dirs as $dir) {
|
||||
if (!Stringy::create($dir)->endsWith(DIRECTORY_SEPARATOR)) {
|
||||
$dir .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
if (0 === strpos($filename, $dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWindows()
|
||||
{
|
||||
return PATH_SEPARATOR === ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the environment's HOME directory.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function getHomeDirectory()
|
||||
{
|
||||
if (getenv('HOME')) {
|
||||
return getenv('HOME');
|
||||
}
|
||||
|
||||
return (getenv('HOMEDRIVE') && getenv('HOMEPATH'))
|
||||
? getenv('HOMEDRIVE') . getenv('HOMEPATH')
|
||||
: null;
|
||||
}
|
||||
}
|
||||
16
vendor/songshenzong/support/src/Strings.php
vendored
Normal file
16
vendor/songshenzong/support/src/Strings.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
use Songshenzong\Support\Traits\Str;
|
||||
use Songshenzong\Support\Traits\Uri;
|
||||
|
||||
/**
|
||||
* Class Strings
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class Strings
|
||||
{
|
||||
use Str, Uri;
|
||||
}
|
||||
21
vendor/songshenzong/support/src/StringsFacade.php
vendored
Normal file
21
vendor/songshenzong/support/src/StringsFacade.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* Class StringsFacade
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class StringsFacade extends Facade
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'Strings';
|
||||
}
|
||||
}
|
||||
13
vendor/songshenzong/support/src/StringsHelpers.php
vendored
Normal file
13
vendor/songshenzong/support/src/StringsHelpers.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Songshenzong\Support\Strings;
|
||||
|
||||
if (!function_exists('strings')) {
|
||||
/**
|
||||
* @return Strings
|
||||
*/
|
||||
function strings()
|
||||
{
|
||||
return new Strings;
|
||||
}
|
||||
}
|
||||
37
vendor/songshenzong/support/src/StringsServiceProvider.php
vendored
Normal file
37
vendor/songshenzong/support/src/StringsServiceProvider.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class StringsServiceProvider
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class StringsServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton(
|
||||
'Strings',
|
||||
static function () {
|
||||
return new Strings();
|
||||
}
|
||||
);
|
||||
|
||||
$this->app->alias('Strings', StringsFacade::class);
|
||||
}
|
||||
}
|
||||
72
vendor/songshenzong/support/src/Time.php
vendored
Normal file
72
vendor/songshenzong/support/src/Time.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support;
|
||||
|
||||
/**
|
||||
* Class Time
|
||||
*
|
||||
* @package Songshenzong\Support
|
||||
*/
|
||||
class Time
|
||||
{
|
||||
|
||||
/**
|
||||
* @param int|string $begin_time
|
||||
* @param int|string $end_time
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function dates($begin_time, $end_time = null)
|
||||
{
|
||||
if ($end_time === null) {
|
||||
$end_time = time();
|
||||
}
|
||||
|
||||
// Y-m-d to timestamp
|
||||
if (!is_int($begin_time)) {
|
||||
$begin_time = strtotime($begin_time);
|
||||
}
|
||||
|
||||
// Y-m-d to timestamp
|
||||
if (!is_int($end_time)) {
|
||||
$end_time = strtotime($end_time);
|
||||
}
|
||||
|
||||
$dates = [];
|
||||
|
||||
for ($start = $begin_time; $start <= $end_time; $start += 86400) {
|
||||
$dates[] = date('Y-m-d', $start);
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format Time.
|
||||
*
|
||||
* @param string $time_string
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public static function formatTime($time_string)
|
||||
{
|
||||
$time = time() - strtotime($time_string);
|
||||
$time1 = time() - strtotime('today');
|
||||
if ($time < 60) {
|
||||
$str = '刚刚';
|
||||
} elseif ($time < 3600) {
|
||||
$min = floor($time / 60);
|
||||
$str = $min . '分钟前';
|
||||
} elseif ($time < 24 * 3600) {
|
||||
$min = floor($time / (60 * 60));
|
||||
$str = $min . '小时前';
|
||||
} elseif ($time > $time1 && $time < 7 * 24 * 3600) {
|
||||
$min = floor($time / (3600 * 24));
|
||||
$str = $min . '天前';
|
||||
} else {
|
||||
$str = date('n月j日 H:i', strtotime($time_string));
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
295
vendor/songshenzong/support/src/Traits/Str.php
vendored
Normal file
295
vendor/songshenzong/support/src/Traits/Str.php
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Traits;
|
||||
|
||||
use stdClass;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Trait Str
|
||||
*
|
||||
* @package Songshenzong\Support\Traits
|
||||
*/
|
||||
trait Str
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function toArray($string = '')
|
||||
{
|
||||
if ($string === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (self::isJson($string)) {
|
||||
return json_decode($string, true);
|
||||
}
|
||||
|
||||
if (self::isXml($string)) {
|
||||
return self::xmlToArray($string);
|
||||
}
|
||||
|
||||
$unserialize = self::unserialize($string);
|
||||
if ($unserialize === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (\is_array($unserialize)) {
|
||||
return $unserialize;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isJson($string = '')
|
||||
{
|
||||
if ($string === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
\json_decode($string, true);
|
||||
if (\json_last_error()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isXml($string = '')
|
||||
{
|
||||
if ($string === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$xml_parser = xml_parser_create();
|
||||
if (!xml_parse($xml_parser, $string, true)) {
|
||||
xml_parser_free($xml_parser);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function xmlToArray($string)
|
||||
{
|
||||
return json_decode(json_encode(simplexml_load_string($string)), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serialized
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function unserialize($serialized)
|
||||
{
|
||||
// Set Handle
|
||||
set_error_handler(
|
||||
function () {
|
||||
},
|
||||
E_ALL
|
||||
);
|
||||
$result = unserialize((string)$serialized);
|
||||
// Restores the previous error handler function
|
||||
restore_error_handler();
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return stdClass|SimpleXMLElement
|
||||
*
|
||||
*/
|
||||
public static function toObject($string = '')
|
||||
{
|
||||
if ($string === '') {
|
||||
return new stdClass();
|
||||
}
|
||||
|
||||
if (self::isJson($string)) {
|
||||
return json_decode($string);
|
||||
}
|
||||
|
||||
if (self::isXml($string)) {
|
||||
return self::xmlToObject($string);
|
||||
}
|
||||
|
||||
$unserialize = self::unserialize($string);
|
||||
if ($unserialize === false) {
|
||||
return new stdClass();
|
||||
}
|
||||
|
||||
if (\is_object($unserialize)) {
|
||||
return $unserialize;
|
||||
}
|
||||
|
||||
return new stdClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public static function xmlToObject($string)
|
||||
{
|
||||
return simplexml_load_string($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSerialized($string)
|
||||
{
|
||||
// Set Handle
|
||||
set_error_handler(
|
||||
function () {
|
||||
},
|
||||
E_ALL
|
||||
);
|
||||
$result = unserialize($string);
|
||||
// Restores the previous error handler function
|
||||
restore_error_handler();
|
||||
|
||||
return !($result === false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function filter($string)
|
||||
{
|
||||
$filter = [
|
||||
"\n",
|
||||
'`',
|
||||
'·',
|
||||
'~',
|
||||
'!',
|
||||
'!',
|
||||
'@',
|
||||
'#',
|
||||
'$',
|
||||
'¥',
|
||||
'%',
|
||||
'^',
|
||||
'……',
|
||||
'&',
|
||||
'*',
|
||||
'(',
|
||||
')',
|
||||
'(',
|
||||
')',
|
||||
'-',
|
||||
'_',
|
||||
'——',
|
||||
'+',
|
||||
'=',
|
||||
'|',
|
||||
'\\',
|
||||
'[',
|
||||
']',
|
||||
'【',
|
||||
'】',
|
||||
'{',
|
||||
'}',
|
||||
';',
|
||||
';',
|
||||
':',
|
||||
':',
|
||||
'\'',
|
||||
'"',
|
||||
'“',
|
||||
'”',
|
||||
',',
|
||||
',',
|
||||
'<',
|
||||
'>',
|
||||
'《',
|
||||
'》',
|
||||
'.',
|
||||
'。',
|
||||
'/',
|
||||
'、',
|
||||
'?',
|
||||
'?',
|
||||
';',
|
||||
'nbsp',
|
||||
];
|
||||
|
||||
$str = str_replace($filter, '', $string);
|
||||
|
||||
return trim($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function trim($string)
|
||||
{
|
||||
$filter = [
|
||||
"\0",
|
||||
"\n",
|
||||
"\t",
|
||||
"\x0B",
|
||||
"\r",
|
||||
' ',
|
||||
];
|
||||
|
||||
$str = str_replace($filter, '', $string);
|
||||
|
||||
return trim($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Set and Not Empty.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSetAndNotEmpty($value)
|
||||
{
|
||||
return isset($value) && !empty($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Set and Not Empty and Not Null.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSetAndNotEmptyAndNotNull($value)
|
||||
{
|
||||
return isset($value) && !empty($value) && $value !== 'null';
|
||||
}
|
||||
}
|
||||
73
vendor/songshenzong/support/src/Traits/Uri.php
vendored
Normal file
73
vendor/songshenzong/support/src/Traits/Uri.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Traits;
|
||||
|
||||
/**
|
||||
* Trait Uri
|
||||
*
|
||||
* @package Songshenzong\Support\Traits
|
||||
*/
|
||||
trait Uri
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $parameters
|
||||
* @param bool $appendsCurrentUri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function uri($uri, array $parameters = [], $appendsCurrentUri = false)
|
||||
{
|
||||
$uriComponents = parse_url($uri);
|
||||
|
||||
if (isset($uriComponents['query'])) {
|
||||
\parse_str($uriComponents['query'], $uriComponents['query']);
|
||||
} else {
|
||||
$uriComponents['query'] = [];
|
||||
}
|
||||
|
||||
if ($appendsCurrentUri) {
|
||||
$newQuery = $parameters + $_GET + $uriComponents['query'];
|
||||
} else {
|
||||
$newQuery = $parameters + $uriComponents['query'];
|
||||
}
|
||||
|
||||
$newUriComponents = isset($uriComponents['scheme']) ? $uriComponents['scheme'] . '://' : '';
|
||||
$newUriComponents .= isset($uriComponents['host']) ? $uriComponents['host'] : '';
|
||||
$newUriComponents .= isset($uriComponents['port']) ? ':' . $uriComponents['port'] : '';
|
||||
$newUriComponents .= isset($uriComponents['path']) ? $uriComponents['path'] : '';
|
||||
$newUriComponents .= '?' . http_build_query($newQuery);
|
||||
|
||||
return $newUriComponents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $host
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function host($host)
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_HOST'])) {
|
||||
return false;
|
||||
}
|
||||
$lower = \strtolower($_SERVER['HTTP_HOST']);
|
||||
|
||||
if (\is_string($host)) {
|
||||
return $host === $lower;
|
||||
}
|
||||
|
||||
if (\is_array($host)) {
|
||||
foreach ($host as $item) {
|
||||
if ($item === $lower) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
29
vendor/songshenzong/support/tests/Core/EchoBashTest.php
vendored
Normal file
29
vendor/songshenzong/support/tests/Core/EchoBashTest.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class EchoBashTest
|
||||
*
|
||||
* @package Songshenzong\Support\Test\Core
|
||||
*/
|
||||
class EchoBashTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testIsJson()
|
||||
{
|
||||
echoRed('echo Red');
|
||||
echoPurple('echo Purple');
|
||||
echoGreen('echo Green');
|
||||
echoCyan('echo Cyan');
|
||||
echoBrown('echo Brown');
|
||||
echoBlue('echo Blue');
|
||||
$this->assertEquals(true, true);
|
||||
}
|
||||
}
|
||||
108
vendor/songshenzong/support/tests/Core/StrTest.php
vendored
Normal file
108
vendor/songshenzong/support/tests/Core/StrTest.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use stdClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Songshenzong\Support\Strings;
|
||||
|
||||
/**
|
||||
* Class StrTest
|
||||
*
|
||||
* @package Songshenzong\Support\Test\Core
|
||||
*/
|
||||
class StrTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $xmlString = <<<ETO
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<books>
|
||||
<book>
|
||||
<author>Jack Herrington</author>
|
||||
<title>PHP Hacks</title>
|
||||
<publisher>O'Reilly</publisher>
|
||||
</book>
|
||||
<book>
|
||||
<author>Jack Herrington</author>
|
||||
<title>Podcasting Hacks</title>
|
||||
<publisher>O'Reilly</publisher>
|
||||
</book>
|
||||
</books>
|
||||
ETO;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $jsonString = '{ "tools": [ { "name":"css format" , "site":"https://songshenzong.com" }, { "name":"pwd check" , "site":"https://songshenzong.com" } ] }';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $simpleJsonArray = ['json' => true];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $simpleJsonString = '{"json":true}';
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testIsJson()
|
||||
{
|
||||
$this->assertEquals(false, Strings::isJson());
|
||||
$this->assertEquals(false, Strings::isJson(''));
|
||||
$this->assertEquals(false, Strings::isJson($this->xmlString));
|
||||
$this->assertEquals(true, Strings::isJson($this->simpleJsonString));
|
||||
$this->assertEquals(true, Strings::isJson($this->jsonString));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testIsXml()
|
||||
{
|
||||
$this->assertEquals(false, Strings::isXml(''));
|
||||
$this->assertEquals(false, Strings::isXml());
|
||||
$this->assertEquals(false, Strings::isXml($this->jsonString));
|
||||
$this->assertEquals(true, Strings::isXml($this->xmlString));
|
||||
$this->assertEquals(false, Strings::isXml($this->simpleJsonString));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testToArray()
|
||||
{
|
||||
$this->assertEquals($this->simpleJsonArray, Strings::toArray($this->simpleJsonString));
|
||||
$this->assertEquals([], Strings::toArray());
|
||||
$this->assertEquals([], Strings::toArray(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testToObject()
|
||||
{
|
||||
$this->assertEquals(true, Strings::toObject($this->simpleJsonString)->json);
|
||||
$this->assertObjectHasAttribute('book', Strings::toObject($this->xmlString));
|
||||
$this->assertEquals(new stdClass(), Strings::toObject());
|
||||
$this->assertEquals(new stdClass(), Strings::toObject(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testXmlToArray()
|
||||
{
|
||||
$this->assertArrayHasKey('book', Strings::xmlToArray($this->xmlString));
|
||||
$this->assertObjectHasAttribute('book', Strings::xmlToObject($this->xmlString));
|
||||
}
|
||||
}
|
||||
46
vendor/songshenzong/support/tests/OSTest.php
vendored
Normal file
46
vendor/songshenzong/support/tests/OSTest.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use Songshenzong\Support\OS;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class OSTest
|
||||
*
|
||||
* @package Songshenzong\Support\Test\Core
|
||||
*/
|
||||
class OSTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetsHomeDirectoryForWindowsUser()
|
||||
{
|
||||
putenv('HOME=');
|
||||
putenv('HOMEDRIVE=C:');
|
||||
putenv('HOMEPATH=\\Users\\Support');
|
||||
$ref = new ReflectionClass(OS::class);
|
||||
$method = $ref->getMethod('getHomeDirectory');
|
||||
$method->setAccessible(true);
|
||||
$this->assertEquals('C:\\Users\\Support', $method->invoke(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetsHomeDirectoryForWindowsUser
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetsHomeDirectoryForLinuxUser()
|
||||
{
|
||||
putenv('HOME=/root');
|
||||
putenv('HOMEDRIVE=');
|
||||
putenv('HOMEPATH=');
|
||||
$ref = new ReflectionClass(OS::class);
|
||||
$method = $ref->getMethod('getHomeDirectory');
|
||||
$method->setAccessible(true);
|
||||
$this->assertEquals('/root', $method->invoke(null));
|
||||
}
|
||||
}
|
||||
22
vendor/songshenzong/support/tests/TimeTest.php
vendored
Normal file
22
vendor/songshenzong/support/tests/TimeTest.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use Songshenzong\Support\Time;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TimeTest extends TestCase
|
||||
{
|
||||
public function testDates()
|
||||
{
|
||||
$expect = [
|
||||
'2019-09-10',
|
||||
'2019-09-11',
|
||||
'2019-09-12',
|
||||
];
|
||||
|
||||
self::assertEquals($expect, Time::dates('2019-09-10', '2019-09-12'));
|
||||
|
||||
self::assertEquals($expect, Time::dates(strtotime('2019-09-10'), strtotime('2019-09-12')));
|
||||
}
|
||||
}
|
||||
11
vendor/songshenzong/support/tests/bootstrap.php
vendored
Normal file
11
vendor/songshenzong/support/tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('GMT');
|
||||
}
|
||||
|
||||
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
$loader->add('Songshenzong\\Support\\Test\\', __DIR__);
|
||||
Reference in New Issue
Block a user