添加网站文件

This commit is contained in:
2025-12-22 13:59:40 +08:00
commit 117aaf83d1
19468 changed files with 2111999 additions and 0 deletions

View 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;
}
}
}
}
}

View 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;
}
}

View 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
View 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
View 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;
}
}

View 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;
}

View 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';
}
}

View File

@@ -0,0 +1,13 @@
<?php
use Songshenzong\Support\Strings;
if (!function_exists('strings')) {
/**
* @return Strings
*/
function strings()
{
return new Strings;
}
}

View 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);
}
}

View 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;
}
}

View 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';
}
}

View 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;
}
}