mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-05 19:41:44 +08:00
ComposerUpdate
This commit is contained in:
parent
4f50cf16c7
commit
73021a0bc8
@ -1,36 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "topthink/think",
|
"name": "topthink/think",
|
||||||
"description": "the new thinkphp framework",
|
"description": "the new thinkphp framework",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"framework",
|
"framework",
|
||||||
"thinkphp",
|
"thinkphp",
|
||||||
"ORM"
|
"ORM"
|
||||||
],
|
],
|
||||||
"homepage": "http://thinkphp.cn/",
|
"homepage": "http://thinkphp.cn/",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "liu21st",
|
"name": "liu21st",
|
||||||
"email": "liu21st@gmail.com"
|
"email": "liu21st@gmail.com"
|
||||||
}
|
|
||||||
],
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.4.0",
|
|
||||||
"qiniu/php-sdk": "^7.0",
|
|
||||||
"zoujingli/wechat-php-sdk": "dev-master",
|
|
||||||
"zoujingli/ip2region": "^1.0",
|
|
||||||
"topthink/framework": "5.0.*",
|
|
||||||
"topthink/think-captcha": "^1.0",
|
|
||||||
"topthink/think-mongo": "^1.1",
|
|
||||||
"topthink/think-queue": "^1.0",
|
|
||||||
"endroid/qr-code": "^1.9",
|
|
||||||
"aliyuncs/oss-sdk-php": "^2.2"
|
|
||||||
},
|
|
||||||
"extra": {
|
|
||||||
"think-path": "thinkphp"
|
|
||||||
},
|
|
||||||
"config": {
|
|
||||||
"preferred-install": "dist"
|
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.4.0",
|
||||||
|
"qiniu/php-sdk": "^7.0",
|
||||||
|
"zoujingli/wechat-php-sdk": "dev-master",
|
||||||
|
"zoujingli/ip2region": "^1.0",
|
||||||
|
"topthink/framework": "5.0.*",
|
||||||
|
"topthink/think-captcha": "1.0.*",
|
||||||
|
"topthink/think-mongo": "1.1.*",
|
||||||
|
"topthink/think-queue": "1.0.*",
|
||||||
|
"endroid/qr-code": "^1.9",
|
||||||
|
"aliyuncs/oss-sdk-php": "^2.2"
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"think-path": "thinkphp"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"preferred-install": "dist"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
require_once __DIR__ . '/composer/autoload_real.php';
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|
||||||
return ComposerAutoloaderInitb1bfee82f75c4c17ecc734b1a1dad3c0::getLoader();
|
return ComposerAutoloaderInitc1cac3a0444716bb820c298f6d3202fd::getLoader();
|
||||||
|
40
vendor/composer/autoload_classmap.php
vendored
40
vendor/composer/autoload_classmap.php
vendored
@ -157,7 +157,6 @@ return array(
|
|||||||
'think\\Model' => $baseDir . '/thinkphp/library/think/Model.php',
|
'think\\Model' => $baseDir . '/thinkphp/library/think/Model.php',
|
||||||
'think\\Paginator' => $baseDir . '/thinkphp/library/think/Paginator.php',
|
'think\\Paginator' => $baseDir . '/thinkphp/library/think/Paginator.php',
|
||||||
'think\\Process' => $baseDir . '/thinkphp/library/think/Process.php',
|
'think\\Process' => $baseDir . '/thinkphp/library/think/Process.php',
|
||||||
'think\\Queue' => $vendorDir . '/topthink/think-queue/src/Queue.php',
|
|
||||||
'think\\Request' => $baseDir . '/thinkphp/library/think/Request.php',
|
'think\\Request' => $baseDir . '/thinkphp/library/think/Request.php',
|
||||||
'think\\Response' => $baseDir . '/thinkphp/library/think/Response.php',
|
'think\\Response' => $baseDir . '/thinkphp/library/think/Response.php',
|
||||||
'think\\Route' => $baseDir . '/thinkphp/library/think/Route.php',
|
'think\\Route' => $baseDir . '/thinkphp/library/think/Route.php',
|
||||||
@ -213,8 +212,6 @@ return array(
|
|||||||
'think\\console\\output\\formatter\\Style' => $baseDir . '/thinkphp/library/think/console/output/formatter/Style.php',
|
'think\\console\\output\\formatter\\Style' => $baseDir . '/thinkphp/library/think/console/output/formatter/Style.php',
|
||||||
'think\\console\\output\\question\\Choice' => $baseDir . '/thinkphp/library/think/console/output/question/Choice.php',
|
'think\\console\\output\\question\\Choice' => $baseDir . '/thinkphp/library/think/console/output/question/Choice.php',
|
||||||
'think\\console\\output\\question\\Confirmation' => $baseDir . '/thinkphp/library/think/console/output/question/Confirmation.php',
|
'think\\console\\output\\question\\Confirmation' => $baseDir . '/thinkphp/library/think/console/output/question/Confirmation.php',
|
||||||
'think\\contract\\Arrayable' => $vendorDir . '/topthink/think-helper/src/contract/Arrayable.php',
|
|
||||||
'think\\contract\\Jsonable' => $vendorDir . '/topthink/think-helper/src/contract/Jsonable.php',
|
|
||||||
'think\\controller\\Rest' => $baseDir . '/thinkphp/library/think/controller/Rest.php',
|
'think\\controller\\Rest' => $baseDir . '/thinkphp/library/think/controller/Rest.php',
|
||||||
'think\\controller\\Yar' => $baseDir . '/thinkphp/library/think/controller/Yar.php',
|
'think\\controller\\Yar' => $baseDir . '/thinkphp/library/think/controller/Yar.php',
|
||||||
'think\\db\\Builder' => $baseDir . '/thinkphp/library/think/db/Builder.php',
|
'think\\db\\Builder' => $baseDir . '/thinkphp/library/think/db/Builder.php',
|
||||||
@ -245,8 +242,6 @@ return array(
|
|||||||
'think\\exception\\TemplateNotFoundException' => $baseDir . '/thinkphp/library/think/exception/TemplateNotFoundException.php',
|
'think\\exception\\TemplateNotFoundException' => $baseDir . '/thinkphp/library/think/exception/TemplateNotFoundException.php',
|
||||||
'think\\exception\\ThrowableError' => $baseDir . '/thinkphp/library/think/exception/ThrowableError.php',
|
'think\\exception\\ThrowableError' => $baseDir . '/thinkphp/library/think/exception/ThrowableError.php',
|
||||||
'think\\exception\\ValidateException' => $baseDir . '/thinkphp/library/think/exception/ValidateException.php',
|
'think\\exception\\ValidateException' => $baseDir . '/thinkphp/library/think/exception/ValidateException.php',
|
||||||
'think\\helper\\Arr' => $vendorDir . '/topthink/think-helper/src/helper/Arr.php',
|
|
||||||
'think\\helper\\Str' => $vendorDir . '/topthink/think-helper/src/helper/Str.php',
|
|
||||||
'think\\log\\driver\\File' => $baseDir . '/thinkphp/library/think/log/driver/File.php',
|
'think\\log\\driver\\File' => $baseDir . '/thinkphp/library/think/log/driver/File.php',
|
||||||
'think\\log\\driver\\Socket' => $baseDir . '/thinkphp/library/think/log/driver/Socket.php',
|
'think\\log\\driver\\Socket' => $baseDir . '/thinkphp/library/think/log/driver/Socket.php',
|
||||||
'think\\log\\driver\\Test' => $baseDir . '/thinkphp/library/think/log/driver/Test.php',
|
'think\\log\\driver\\Test' => $baseDir . '/thinkphp/library/think/log/driver/Test.php',
|
||||||
@ -274,25 +269,22 @@ return array(
|
|||||||
'think\\process\\pipes\\Pipes' => $baseDir . '/thinkphp/library/think/process/pipes/Pipes.php',
|
'think\\process\\pipes\\Pipes' => $baseDir . '/thinkphp/library/think/process/pipes/Pipes.php',
|
||||||
'think\\process\\pipes\\Unix' => $baseDir . '/thinkphp/library/think/process/pipes/Unix.php',
|
'think\\process\\pipes\\Unix' => $baseDir . '/thinkphp/library/think/process/pipes/Unix.php',
|
||||||
'think\\process\\pipes\\Windows' => $baseDir . '/thinkphp/library/think/process/pipes/Windows.php',
|
'think\\process\\pipes\\Windows' => $baseDir . '/thinkphp/library/think/process/pipes/Windows.php',
|
||||||
'think\\queue\\CallQueuedHandler' => $vendorDir . '/topthink/think-queue/src/queue/CallQueuedHandler.php',
|
'think\\queue\\Job' => $vendorDir . '/topthink/think-queue/src/Job.php',
|
||||||
'think\\queue\\Connector' => $vendorDir . '/topthink/think-queue/src/queue/Connector.php',
|
'think\\queue\\Listener' => $vendorDir . '/topthink/think-queue/src/Listener.php',
|
||||||
'think\\queue\\Job' => $vendorDir . '/topthink/think-queue/src/queue/Job.php',
|
'think\\queue\\Queue' => $vendorDir . '/topthink/think-queue/src/Queue.php',
|
||||||
'think\\queue\\Listener' => $vendorDir . '/topthink/think-queue/src/queue/Listener.php',
|
'think\\queue\\Worker' => $vendorDir . '/topthink/think-queue/src/Worker.php',
|
||||||
'think\\queue\\Queueable' => $vendorDir . '/topthink/think-queue/src/queue/Queueable.php',
|
'think\\queue\\command\\Listen' => $vendorDir . '/topthink/think-queue/src/command/Listen.php',
|
||||||
'think\\queue\\ShouldQueue' => $vendorDir . '/topthink/think-queue/src/queue/ShouldQueue.php',
|
'think\\queue\\command\\Restart' => $vendorDir . '/topthink/think-queue/src/command/Restart.php',
|
||||||
'think\\queue\\Worker' => $vendorDir . '/topthink/think-queue/src/queue/Worker.php',
|
'think\\queue\\command\\Subscribe' => $vendorDir . '/topthink/think-queue/src/command/Subscribe.php',
|
||||||
'think\\queue\\command\\Listen' => $vendorDir . '/topthink/think-queue/src/queue/command/Listen.php',
|
'think\\queue\\command\\Work' => $vendorDir . '/topthink/think-queue/src/command/Work.php',
|
||||||
'think\\queue\\command\\Restart' => $vendorDir . '/topthink/think-queue/src/queue/command/Restart.php',
|
'think\\queue\\driver\\Database' => $vendorDir . '/topthink/think-queue/src/driver/Database.php',
|
||||||
'think\\queue\\command\\Subscribe' => $vendorDir . '/topthink/think-queue/src/queue/command/Subscribe.php',
|
'think\\queue\\driver\\Redis' => $vendorDir . '/topthink/think-queue/src/driver/Redis.php',
|
||||||
'think\\queue\\command\\Work' => $vendorDir . '/topthink/think-queue/src/queue/command/Work.php',
|
'think\\queue\\driver\\Sync' => $vendorDir . '/topthink/think-queue/src/driver/Sync.php',
|
||||||
'think\\queue\\connector\\Database' => $vendorDir . '/topthink/think-queue/src/queue/connector/Database.php',
|
'think\\queue\\driver\\Topthink' => $vendorDir . '/topthink/think-queue/src/driver/Topthink.php',
|
||||||
'think\\queue\\connector\\Redis' => $vendorDir . '/topthink/think-queue/src/queue/connector/Redis.php',
|
'think\\queue\\job\\Database' => $vendorDir . '/topthink/think-queue/src/job/Database.php',
|
||||||
'think\\queue\\connector\\Sync' => $vendorDir . '/topthink/think-queue/src/queue/connector/Sync.php',
|
'think\\queue\\job\\Redis' => $vendorDir . '/topthink/think-queue/src/job/Redis.php',
|
||||||
'think\\queue\\connector\\Topthink' => $vendorDir . '/topthink/think-queue/src/queue/connector/Topthink.php',
|
'think\\queue\\job\\Sync' => $vendorDir . '/topthink/think-queue/src/job/Sync.php',
|
||||||
'think\\queue\\job\\Database' => $vendorDir . '/topthink/think-queue/src/queue/job/Database.php',
|
'think\\queue\\job\\Topthink' => $vendorDir . '/topthink/think-queue/src/job/Topthink.php',
|
||||||
'think\\queue\\job\\Redis' => $vendorDir . '/topthink/think-queue/src/queue/job/Redis.php',
|
|
||||||
'think\\queue\\job\\Sync' => $vendorDir . '/topthink/think-queue/src/queue/job/Sync.php',
|
|
||||||
'think\\queue\\job\\Topthink' => $vendorDir . '/topthink/think-queue/src/queue/job/Topthink.php',
|
|
||||||
'think\\response\\Json' => $baseDir . '/thinkphp/library/think/response/Json.php',
|
'think\\response\\Json' => $baseDir . '/thinkphp/library/think/response/Json.php',
|
||||||
'think\\response\\Jsonp' => $baseDir . '/thinkphp/library/think/response/Jsonp.php',
|
'think\\response\\Jsonp' => $baseDir . '/thinkphp/library/think/response/Jsonp.php',
|
||||||
'think\\response\\Redirect' => $baseDir . '/thinkphp/library/think/response/Redirect.php',
|
'think\\response\\Redirect' => $baseDir . '/thinkphp/library/think/response/Redirect.php',
|
||||||
|
3
vendor/composer/autoload_files.php
vendored
3
vendor/composer/autoload_files.php
vendored
@ -6,8 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
|
|||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
|
|
||||||
'841780ea2e1d6545ea3a253239d59c05' => $vendorDir . '/qiniu/php-sdk/src/Qiniu/functions.php',
|
'841780ea2e1d6545ea3a253239d59c05' => $vendorDir . '/qiniu/php-sdk/src/Qiniu/functions.php',
|
||||||
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
|
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
|
||||||
'cc56288302d9df745d97c934d6a6e5f0' => $vendorDir . '/topthink/think-queue/src/common.php',
|
'9e05116ddaa5b1d244b68c3993908acd' => $vendorDir . '/topthink/think-queue/src/config.php',
|
||||||
);
|
);
|
||||||
|
3
vendor/composer/autoload_psr4.php
vendored
3
vendor/composer/autoload_psr4.php
vendored
@ -6,10 +6,11 @@ $vendorDir = dirname(dirname(__FILE__));
|
|||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'think\\queue\\' => array($vendorDir . '/topthink/think-queue/src'),
|
||||||
'think\\mongo\\' => array($vendorDir . '/topthink/think-mongo/src'),
|
'think\\mongo\\' => array($vendorDir . '/topthink/think-mongo/src'),
|
||||||
'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
|
'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
|
||||||
'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
|
'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
|
||||||
'think\\' => array($baseDir . '/thinkphp/library/think', $vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-queue/src'),
|
'think\\' => array($baseDir . '/thinkphp/library/think'),
|
||||||
'Wechat\\' => array($vendorDir . '/zoujingli/wechat-php-sdk/Wechat'),
|
'Wechat\\' => array($vendorDir . '/zoujingli/wechat-php-sdk/Wechat'),
|
||||||
'Symfony\\Component\\OptionsResolver\\' => array($vendorDir . '/symfony/options-resolver'),
|
'Symfony\\Component\\OptionsResolver\\' => array($vendorDir . '/symfony/options-resolver'),
|
||||||
'Qiniu\\' => array($vendorDir . '/qiniu/php-sdk/src/Qiniu'),
|
'Qiniu\\' => array($vendorDir . '/qiniu/php-sdk/src/Qiniu'),
|
||||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// autoload_real.php @generated by Composer
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
class ComposerAutoloaderInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
class ComposerAutoloaderInitc1cac3a0444716bb820c298f6d3202fd
|
||||||
{
|
{
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
@ -19,15 +19,15 @@ class ComposerAutoloaderInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
return self::$loader;
|
return self::$loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register(array('ComposerAutoloaderInitb1bfee82f75c4c17ecc734b1a1dad3c0', 'loadClassLoader'), true, true);
|
spl_autoload_register(array('ComposerAutoloaderInitc1cac3a0444716bb820c298f6d3202fd', 'loadClassLoader'), true, true);
|
||||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||||
spl_autoload_unregister(array('ComposerAutoloaderInitb1bfee82f75c4c17ecc734b1a1dad3c0', 'loadClassLoader'));
|
spl_autoload_unregister(array('ComposerAutoloaderInitc1cac3a0444716bb820c298f6d3202fd', 'loadClassLoader'));
|
||||||
|
|
||||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||||
if ($useStaticLoader) {
|
if ($useStaticLoader) {
|
||||||
require_once __DIR__ . '/autoload_static.php';
|
require_once __DIR__ . '/autoload_static.php';
|
||||||
|
|
||||||
call_user_func(\Composer\Autoload\ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0::getInitializer($loader));
|
call_user_func(\Composer\Autoload\ComposerStaticInitc1cac3a0444716bb820c298f6d3202fd::getInitializer($loader));
|
||||||
} else {
|
} else {
|
||||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||||
foreach ($map as $namespace => $path) {
|
foreach ($map as $namespace => $path) {
|
||||||
@ -48,19 +48,19 @@ class ComposerAutoloaderInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
$loader->register(true);
|
$loader->register(true);
|
||||||
|
|
||||||
if ($useStaticLoader) {
|
if ($useStaticLoader) {
|
||||||
$includeFiles = Composer\Autoload\ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0::$files;
|
$includeFiles = Composer\Autoload\ComposerStaticInitc1cac3a0444716bb820c298f6d3202fd::$files;
|
||||||
} else {
|
} else {
|
||||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||||
}
|
}
|
||||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||||
composerRequireb1bfee82f75c4c17ecc734b1a1dad3c0($fileIdentifier, $file);
|
composerRequirec1cac3a0444716bb820c298f6d3202fd($fileIdentifier, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loader;
|
return $loader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function composerRequireb1bfee82f75c4c17ecc734b1a1dad3c0($fileIdentifier, $file)
|
function composerRequirec1cac3a0444716bb820c298f6d3202fd($fileIdentifier, $file)
|
||||||
{
|
{
|
||||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||||
require $file;
|
require $file;
|
||||||
|
58
vendor/composer/autoload_static.php
vendored
58
vendor/composer/autoload_static.php
vendored
@ -4,18 +4,18 @@
|
|||||||
|
|
||||||
namespace Composer\Autoload;
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
class ComposerStaticInitc1cac3a0444716bb820c298f6d3202fd
|
||||||
{
|
{
|
||||||
public static $files = array (
|
public static $files = array (
|
||||||
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
|
|
||||||
'841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php',
|
'841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php',
|
||||||
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
|
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
|
||||||
'cc56288302d9df745d97c934d6a6e5f0' => __DIR__ . '/..' . '/topthink/think-queue/src/common.php',
|
'9e05116ddaa5b1d244b68c3993908acd' => __DIR__ . '/..' . '/topthink/think-queue/src/config.php',
|
||||||
);
|
);
|
||||||
|
|
||||||
public static $prefixLengthsPsr4 = array (
|
public static $prefixLengthsPsr4 = array (
|
||||||
't' =>
|
't' =>
|
||||||
array (
|
array (
|
||||||
|
'think\\queue\\' => 12,
|
||||||
'think\\mongo\\' => 12,
|
'think\\mongo\\' => 12,
|
||||||
'think\\composer\\' => 15,
|
'think\\composer\\' => 15,
|
||||||
'think\\captcha\\' => 14,
|
'think\\captcha\\' => 14,
|
||||||
@ -44,6 +44,10 @@ class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
);
|
);
|
||||||
|
|
||||||
public static $prefixDirsPsr4 = array (
|
public static $prefixDirsPsr4 = array (
|
||||||
|
'think\\queue\\' =>
|
||||||
|
array (
|
||||||
|
0 => __DIR__ . '/..' . '/topthink/think-queue/src',
|
||||||
|
),
|
||||||
'think\\mongo\\' =>
|
'think\\mongo\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/topthink/think-mongo/src',
|
0 => __DIR__ . '/..' . '/topthink/think-mongo/src',
|
||||||
@ -59,8 +63,6 @@ class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
'think\\' =>
|
'think\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/../..' . '/thinkphp/library/think',
|
0 => __DIR__ . '/../..' . '/thinkphp/library/think',
|
||||||
1 => __DIR__ . '/..' . '/topthink/think-helper/src',
|
|
||||||
2 => __DIR__ . '/..' . '/topthink/think-queue/src',
|
|
||||||
),
|
),
|
||||||
'Wechat\\' =>
|
'Wechat\\' =>
|
||||||
array (
|
array (
|
||||||
@ -236,7 +238,6 @@ class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
'think\\Model' => __DIR__ . '/../..' . '/thinkphp/library/think/Model.php',
|
'think\\Model' => __DIR__ . '/../..' . '/thinkphp/library/think/Model.php',
|
||||||
'think\\Paginator' => __DIR__ . '/../..' . '/thinkphp/library/think/Paginator.php',
|
'think\\Paginator' => __DIR__ . '/../..' . '/thinkphp/library/think/Paginator.php',
|
||||||
'think\\Process' => __DIR__ . '/../..' . '/thinkphp/library/think/Process.php',
|
'think\\Process' => __DIR__ . '/../..' . '/thinkphp/library/think/Process.php',
|
||||||
'think\\Queue' => __DIR__ . '/..' . '/topthink/think-queue/src/Queue.php',
|
|
||||||
'think\\Request' => __DIR__ . '/../..' . '/thinkphp/library/think/Request.php',
|
'think\\Request' => __DIR__ . '/../..' . '/thinkphp/library/think/Request.php',
|
||||||
'think\\Response' => __DIR__ . '/../..' . '/thinkphp/library/think/Response.php',
|
'think\\Response' => __DIR__ . '/../..' . '/thinkphp/library/think/Response.php',
|
||||||
'think\\Route' => __DIR__ . '/../..' . '/thinkphp/library/think/Route.php',
|
'think\\Route' => __DIR__ . '/../..' . '/thinkphp/library/think/Route.php',
|
||||||
@ -292,8 +293,6 @@ class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
'think\\console\\output\\formatter\\Style' => __DIR__ . '/../..' . '/thinkphp/library/think/console/output/formatter/Style.php',
|
'think\\console\\output\\formatter\\Style' => __DIR__ . '/../..' . '/thinkphp/library/think/console/output/formatter/Style.php',
|
||||||
'think\\console\\output\\question\\Choice' => __DIR__ . '/../..' . '/thinkphp/library/think/console/output/question/Choice.php',
|
'think\\console\\output\\question\\Choice' => __DIR__ . '/../..' . '/thinkphp/library/think/console/output/question/Choice.php',
|
||||||
'think\\console\\output\\question\\Confirmation' => __DIR__ . '/../..' . '/thinkphp/library/think/console/output/question/Confirmation.php',
|
'think\\console\\output\\question\\Confirmation' => __DIR__ . '/../..' . '/thinkphp/library/think/console/output/question/Confirmation.php',
|
||||||
'think\\contract\\Arrayable' => __DIR__ . '/..' . '/topthink/think-helper/src/contract/Arrayable.php',
|
|
||||||
'think\\contract\\Jsonable' => __DIR__ . '/..' . '/topthink/think-helper/src/contract/Jsonable.php',
|
|
||||||
'think\\controller\\Rest' => __DIR__ . '/../..' . '/thinkphp/library/think/controller/Rest.php',
|
'think\\controller\\Rest' => __DIR__ . '/../..' . '/thinkphp/library/think/controller/Rest.php',
|
||||||
'think\\controller\\Yar' => __DIR__ . '/../..' . '/thinkphp/library/think/controller/Yar.php',
|
'think\\controller\\Yar' => __DIR__ . '/../..' . '/thinkphp/library/think/controller/Yar.php',
|
||||||
'think\\db\\Builder' => __DIR__ . '/../..' . '/thinkphp/library/think/db/Builder.php',
|
'think\\db\\Builder' => __DIR__ . '/../..' . '/thinkphp/library/think/db/Builder.php',
|
||||||
@ -324,8 +323,6 @@ class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
'think\\exception\\TemplateNotFoundException' => __DIR__ . '/../..' . '/thinkphp/library/think/exception/TemplateNotFoundException.php',
|
'think\\exception\\TemplateNotFoundException' => __DIR__ . '/../..' . '/thinkphp/library/think/exception/TemplateNotFoundException.php',
|
||||||
'think\\exception\\ThrowableError' => __DIR__ . '/../..' . '/thinkphp/library/think/exception/ThrowableError.php',
|
'think\\exception\\ThrowableError' => __DIR__ . '/../..' . '/thinkphp/library/think/exception/ThrowableError.php',
|
||||||
'think\\exception\\ValidateException' => __DIR__ . '/../..' . '/thinkphp/library/think/exception/ValidateException.php',
|
'think\\exception\\ValidateException' => __DIR__ . '/../..' . '/thinkphp/library/think/exception/ValidateException.php',
|
||||||
'think\\helper\\Arr' => __DIR__ . '/..' . '/topthink/think-helper/src/helper/Arr.php',
|
|
||||||
'think\\helper\\Str' => __DIR__ . '/..' . '/topthink/think-helper/src/helper/Str.php',
|
|
||||||
'think\\log\\driver\\File' => __DIR__ . '/../..' . '/thinkphp/library/think/log/driver/File.php',
|
'think\\log\\driver\\File' => __DIR__ . '/../..' . '/thinkphp/library/think/log/driver/File.php',
|
||||||
'think\\log\\driver\\Socket' => __DIR__ . '/../..' . '/thinkphp/library/think/log/driver/Socket.php',
|
'think\\log\\driver\\Socket' => __DIR__ . '/../..' . '/thinkphp/library/think/log/driver/Socket.php',
|
||||||
'think\\log\\driver\\Test' => __DIR__ . '/../..' . '/thinkphp/library/think/log/driver/Test.php',
|
'think\\log\\driver\\Test' => __DIR__ . '/../..' . '/thinkphp/library/think/log/driver/Test.php',
|
||||||
@ -353,25 +350,22 @@ class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
'think\\process\\pipes\\Pipes' => __DIR__ . '/../..' . '/thinkphp/library/think/process/pipes/Pipes.php',
|
'think\\process\\pipes\\Pipes' => __DIR__ . '/../..' . '/thinkphp/library/think/process/pipes/Pipes.php',
|
||||||
'think\\process\\pipes\\Unix' => __DIR__ . '/../..' . '/thinkphp/library/think/process/pipes/Unix.php',
|
'think\\process\\pipes\\Unix' => __DIR__ . '/../..' . '/thinkphp/library/think/process/pipes/Unix.php',
|
||||||
'think\\process\\pipes\\Windows' => __DIR__ . '/../..' . '/thinkphp/library/think/process/pipes/Windows.php',
|
'think\\process\\pipes\\Windows' => __DIR__ . '/../..' . '/thinkphp/library/think/process/pipes/Windows.php',
|
||||||
'think\\queue\\CallQueuedHandler' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/CallQueuedHandler.php',
|
'think\\queue\\Job' => __DIR__ . '/..' . '/topthink/think-queue/src/Job.php',
|
||||||
'think\\queue\\Connector' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/Connector.php',
|
'think\\queue\\Listener' => __DIR__ . '/..' . '/topthink/think-queue/src/Listener.php',
|
||||||
'think\\queue\\Job' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/Job.php',
|
'think\\queue\\Queue' => __DIR__ . '/..' . '/topthink/think-queue/src/Queue.php',
|
||||||
'think\\queue\\Listener' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/Listener.php',
|
'think\\queue\\Worker' => __DIR__ . '/..' . '/topthink/think-queue/src/Worker.php',
|
||||||
'think\\queue\\Queueable' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/Queueable.php',
|
'think\\queue\\command\\Listen' => __DIR__ . '/..' . '/topthink/think-queue/src/command/Listen.php',
|
||||||
'think\\queue\\ShouldQueue' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/ShouldQueue.php',
|
'think\\queue\\command\\Restart' => __DIR__ . '/..' . '/topthink/think-queue/src/command/Restart.php',
|
||||||
'think\\queue\\Worker' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/Worker.php',
|
'think\\queue\\command\\Subscribe' => __DIR__ . '/..' . '/topthink/think-queue/src/command/Subscribe.php',
|
||||||
'think\\queue\\command\\Listen' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/command/Listen.php',
|
'think\\queue\\command\\Work' => __DIR__ . '/..' . '/topthink/think-queue/src/command/Work.php',
|
||||||
'think\\queue\\command\\Restart' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/command/Restart.php',
|
'think\\queue\\driver\\Database' => __DIR__ . '/..' . '/topthink/think-queue/src/driver/Database.php',
|
||||||
'think\\queue\\command\\Subscribe' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/command/Subscribe.php',
|
'think\\queue\\driver\\Redis' => __DIR__ . '/..' . '/topthink/think-queue/src/driver/Redis.php',
|
||||||
'think\\queue\\command\\Work' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/command/Work.php',
|
'think\\queue\\driver\\Sync' => __DIR__ . '/..' . '/topthink/think-queue/src/driver/Sync.php',
|
||||||
'think\\queue\\connector\\Database' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/connector/Database.php',
|
'think\\queue\\driver\\Topthink' => __DIR__ . '/..' . '/topthink/think-queue/src/driver/Topthink.php',
|
||||||
'think\\queue\\connector\\Redis' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/connector/Redis.php',
|
'think\\queue\\job\\Database' => __DIR__ . '/..' . '/topthink/think-queue/src/job/Database.php',
|
||||||
'think\\queue\\connector\\Sync' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/connector/Sync.php',
|
'think\\queue\\job\\Redis' => __DIR__ . '/..' . '/topthink/think-queue/src/job/Redis.php',
|
||||||
'think\\queue\\connector\\Topthink' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/connector/Topthink.php',
|
'think\\queue\\job\\Sync' => __DIR__ . '/..' . '/topthink/think-queue/src/job/Sync.php',
|
||||||
'think\\queue\\job\\Database' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/job/Database.php',
|
'think\\queue\\job\\Topthink' => __DIR__ . '/..' . '/topthink/think-queue/src/job/Topthink.php',
|
||||||
'think\\queue\\job\\Redis' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/job/Redis.php',
|
|
||||||
'think\\queue\\job\\Sync' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/job/Sync.php',
|
|
||||||
'think\\queue\\job\\Topthink' => __DIR__ . '/..' . '/topthink/think-queue/src/queue/job/Topthink.php',
|
|
||||||
'think\\response\\Json' => __DIR__ . '/../..' . '/thinkphp/library/think/response/Json.php',
|
'think\\response\\Json' => __DIR__ . '/../..' . '/thinkphp/library/think/response/Json.php',
|
||||||
'think\\response\\Jsonp' => __DIR__ . '/../..' . '/thinkphp/library/think/response/Jsonp.php',
|
'think\\response\\Jsonp' => __DIR__ . '/../..' . '/thinkphp/library/think/response/Jsonp.php',
|
||||||
'think\\response\\Redirect' => __DIR__ . '/../..' . '/thinkphp/library/think/response/Redirect.php',
|
'think\\response\\Redirect' => __DIR__ . '/../..' . '/thinkphp/library/think/response/Redirect.php',
|
||||||
@ -390,9 +384,9 @@ class ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0
|
|||||||
public static function getInitializer(ClassLoader $loader)
|
public static function getInitializer(ClassLoader $loader)
|
||||||
{
|
{
|
||||||
return \Closure::bind(function () use ($loader) {
|
return \Closure::bind(function () use ($loader) {
|
||||||
$loader->prefixLengthsPsr4 = ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0::$prefixLengthsPsr4;
|
$loader->prefixLengthsPsr4 = ComposerStaticInitc1cac3a0444716bb820c298f6d3202fd::$prefixLengthsPsr4;
|
||||||
$loader->prefixDirsPsr4 = ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0::$prefixDirsPsr4;
|
$loader->prefixDirsPsr4 = ComposerStaticInitc1cac3a0444716bb820c298f6d3202fd::$prefixDirsPsr4;
|
||||||
$loader->classMap = ComposerStaticInitb1bfee82f75c4c17ecc734b1a1dad3c0::$classMap;
|
$loader->classMap = ComposerStaticInitc1cac3a0444716bb820c298f6d3202fd::$classMap;
|
||||||
|
|
||||||
}, null, ClassLoader::class);
|
}, null, ClassLoader::class);
|
||||||
}
|
}
|
||||||
|
83
vendor/composer/installed.json
vendored
83
vendor/composer/installed.json
vendored
@ -308,47 +308,6 @@
|
|||||||
],
|
],
|
||||||
"description": "captcha package for thinkphp5"
|
"description": "captcha package for thinkphp5"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "topthink/think-helper",
|
|
||||||
"version": "v3.1.3",
|
|
||||||
"version_normalized": "3.1.3.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/top-think/think-helper.git",
|
|
||||||
"reference": "4d85dfd3778623bbb1de3648f1dcd0c82f4439f4"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/top-think/think-helper/zipball/4d85dfd3778623bbb1de3648f1dcd0c82f4439f4",
|
|
||||||
"reference": "4d85dfd3778623bbb1de3648f1dcd0c82f4439f4",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=7.1.0"
|
|
||||||
},
|
|
||||||
"time": "2019-09-30T02:36:48+00:00",
|
|
||||||
"type": "library",
|
|
||||||
"installation-source": "dist",
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"think\\": "src"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"src/helper.php"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"Apache-2.0"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "yunwuxin",
|
|
||||||
"email": "448901948@qq.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "The ThinkPHP6 Helper Package"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "topthink/think-installer",
|
"name": "topthink/think-installer",
|
||||||
"version": "v1.0.12",
|
"version": "v1.0.12",
|
||||||
@ -394,20 +353,20 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "topthink/think-mongo",
|
"name": "topthink/think-mongo",
|
||||||
"version": "v1.8.5",
|
"version": "v1.1",
|
||||||
"version_normalized": "1.8.5.0",
|
"version_normalized": "1.1.0.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/top-think/think-mongo.git",
|
"url": "https://github.com/top-think/think-mongo.git",
|
||||||
"reference": "657cc79bd5f090a58b0cc83776073dd69c83a3d1"
|
"reference": "04548b89d283a15e4b3fc040cd0b3832efba15c5"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/top-think/think-mongo/zipball/657cc79bd5f090a58b0cc83776073dd69c83a3d1",
|
"url": "https://api.github.com/repos/top-think/think-mongo/zipball/04548b89d283a15e4b3fc040cd0b3832efba15c5",
|
||||||
"reference": "657cc79bd5f090a58b0cc83776073dd69c83a3d1",
|
"reference": "04548b89d283a15e4b3fc040cd0b3832efba15c5",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"time": "2018-06-03T01:51:27+00:00",
|
"time": "2016-11-04T02:10:44+00:00",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"installation-source": "dist",
|
"installation-source": "dist",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -430,40 +389,28 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "topthink/think-queue",
|
"name": "topthink/think-queue",
|
||||||
"version": "v1.1.6",
|
"version": "v1.0.2",
|
||||||
"version_normalized": "1.1.6.0",
|
"version_normalized": "1.0.2.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/top-think/think-queue.git",
|
"url": "https://github.com/top-think/think-queue.git",
|
||||||
"reference": "250650eb0e8ea5af4cfdc7ae46f3f4e0a24ac245"
|
"reference": "bd0cf0f18146fafd4314c30a26b105d8b71f72b2"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/top-think/think-queue/zipball/250650eb0e8ea5af4cfdc7ae46f3f4e0a24ac245",
|
"url": "https://api.github.com/repos/top-think/think-queue/zipball/bd0cf0f18146fafd4314c30a26b105d8b71f72b2",
|
||||||
"reference": "250650eb0e8ea5af4cfdc7ae46f3f4e0a24ac245",
|
"reference": "bd0cf0f18146fafd4314c30a26b105d8b71f72b2",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"time": "2016-11-25T03:41:00+00:00",
|
||||||
"topthink/think-helper": ">=1.0.4",
|
"type": "library",
|
||||||
"topthink/think-installer": ">=1.0.10"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"topthink/framework": "~5.0.0"
|
|
||||||
},
|
|
||||||
"time": "2018-10-15T10:16:55+00:00",
|
|
||||||
"type": "think-extend",
|
|
||||||
"extra": {
|
|
||||||
"think-config": {
|
|
||||||
"queue": "src/config.php"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"installation-source": "dist",
|
"installation-source": "dist",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"think\\": "src"
|
"think\\queue\\": "src"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/common.php"
|
"src/config.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
3
vendor/topthink/think-helper/.gitignore
vendored
3
vendor/topthink/think-helper/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
/vendor/
|
|
||||||
/.idea/
|
|
||||||
composer.lock
|
|
201
vendor/topthink/think-helper/LICENSE
vendored
201
vendor/topthink/think-helper/LICENSE
vendored
@ -1,201 +0,0 @@
|
|||||||
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.
|
|
33
vendor/topthink/think-helper/README.md
vendored
33
vendor/topthink/think-helper/README.md
vendored
@ -1,33 +0,0 @@
|
|||||||
# thinkphp6 常用的一些扩展类库
|
|
||||||
|
|
||||||
基于PHP7.1+
|
|
||||||
|
|
||||||
> 以下类库都在`\\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)
|
|
||||||
|
|
||||||
```
|
|
22
vendor/topthink/think-helper/composer.json
vendored
22
vendor/topthink/think-helper/composer.json
vendored
@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"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"
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"think\\": "src"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"src/helper.php"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
651
vendor/topthink/think-helper/src/Collection.php
vendored
651
vendor/topthink/think-helper/src/Collection.php
vendored
@ -1,651 +0,0 @@
|
|||||||
<?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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据集管理类
|
|
||||||
*/
|
|
||||||
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_diff($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 void
|
|
||||||
*/
|
|
||||||
public function push($value, string $key = null): void
|
|
||||||
{
|
|
||||||
if (is_null($key)) {
|
|
||||||
$this->items[] = $value;
|
|
||||||
} else {
|
|
||||||
$this->items[$key] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 把一个数组分割为新的数组块.
|
|
||||||
*
|
|
||||||
* @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 void
|
|
||||||
*/
|
|
||||||
public function unshift($value, string $key = null): void
|
|
||||||
{
|
|
||||||
if (is_null($key)) {
|
|
||||||
array_unshift($this->items, $value);
|
|
||||||
} else {
|
|
||||||
$this->items = [$key => $value] + $this->items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 给每个元素执行个回调
|
|
||||||
*
|
|
||||||
* @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, '.')) {
|
|
||||||
list($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':
|
|
||||||
list($min, $max) = is_string($value) ? explode(',', $value) : $value;
|
|
||||||
return is_scalar($result) && $result >= $min && $result <= $max;
|
|
||||||
case 'not between':
|
|
||||||
list($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 $columnKey 键名
|
|
||||||
* @param string $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 = null)
|
|
||||||
{
|
|
||||||
return $this->sort(function ($a, $b) use ($field, $order) {
|
|
||||||
$fieldA = $a[$field] ?? null;
|
|
||||||
$fieldB = $b[$field] ?? null;
|
|
||||||
|
|
||||||
return 'desc' == strtolower($order) ? strcmp($fieldB, $fieldA) : strcmp($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
|
|
||||||
public function offsetExists($offset)
|
|
||||||
{
|
|
||||||
return array_key_exists($offset, $this->items);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetGet($offset)
|
|
||||||
{
|
|
||||||
return $this->items[$offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetSet($offset, $value)
|
|
||||||
{
|
|
||||||
if (is_null($offset)) {
|
|
||||||
$this->items[] = $value;
|
|
||||||
} else {
|
|
||||||
$this->items[$offset] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetUnset($offset)
|
|
||||||
{
|
|
||||||
unset($this->items[$offset]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Countable
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->items);
|
|
||||||
}
|
|
||||||
|
|
||||||
//IteratorAggregate
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new ArrayIterator($this->items);
|
|
||||||
}
|
|
||||||
|
|
||||||
//JsonSerializable
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace think\contract;
|
|
||||||
|
|
||||||
interface Arrayable
|
|
||||||
{
|
|
||||||
public function toArray(): array;
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace think\contract;
|
|
||||||
|
|
||||||
interface Jsonable
|
|
||||||
{
|
|
||||||
public function toJson(int $options = JSON_UNESCAPED_UNICODE): string;
|
|
||||||
}
|
|
279
vendor/topthink/think-helper/src/helper.php
vendored
279
vendor/topthink/think-helper/src/helper.php
vendored
@ -1,279 +0,0 @@
|
|||||||
<?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
634
vendor/topthink/think-helper/src/helper/Arr.php
vendored
@ -1,634 +0,0 @@
|
|||||||
<?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
234
vendor/topthink/think-helper/src/helper/Str.php
vendored
@ -1,234 +0,0 @@
|
|||||||
<?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', '', $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');
|
|
||||||
}
|
|
||||||
}
|
|
1
vendor/topthink/think-mongo/.gitignore
vendored
1
vendor/topthink/think-mongo/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
.idea
|
|
3
vendor/topthink/think-mongo/README.md
vendored
3
vendor/topthink/think-mongo/README.md
vendored
@ -21,6 +21,3 @@ Db::name('demo')
|
|||||||
->order('id','desc')
|
->order('id','desc')
|
||||||
->select();
|
->select();
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
1.*版本支持ThinkPHP 5.0
|
|
||||||
2.*版本支持ThinkPHP 5.1
|
|
||||||
|
144
vendor/topthink/think-mongo/src/Builder.php
vendored
144
vendor/topthink/think-mongo/src/Builder.php
vendored
@ -2,6 +2,8 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
@ -14,9 +16,10 @@ use MongoDB\BSON\ObjectID;
|
|||||||
use MongoDB\BSON\Regex;
|
use MongoDB\BSON\Regex;
|
||||||
use MongoDB\Driver\BulkWrite;
|
use MongoDB\Driver\BulkWrite;
|
||||||
use MongoDB\Driver\Command;
|
use MongoDB\Driver\Command;
|
||||||
use MongoDB\Driver\Exception\InvalidArgumentException;
|
|
||||||
use MongoDB\Driver\Query as MongoQuery;
|
use MongoDB\Driver\Query as MongoQuery;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
use think\mongo\Connection;
|
||||||
|
use think\mongo\Query;
|
||||||
|
|
||||||
class Builder
|
class Builder
|
||||||
{
|
{
|
||||||
@ -29,7 +32,7 @@ class Builder
|
|||||||
// 最后插入ID
|
// 最后插入ID
|
||||||
protected $insertId = [];
|
protected $insertId = [];
|
||||||
// 查询表达式
|
// 查询表达式
|
||||||
protected $exp = ['<>' => 'ne', 'neq' => 'ne', '=' => 'eq', '>' => 'gt', '>=' => 'gte', '<' => 'lt', '<=' => 'lte', 'in' => 'in', 'not in' => 'nin', 'nin' => 'nin', 'mod' => 'mod', 'exists' => 'exists', 'null' => 'null', 'notnull' => 'not null', 'not null' => 'not null', 'regex' => 'regex', 'type' => 'type', 'all' => 'all', '> time' => '> time', '< time' => '< time', 'between' => 'between', 'not between' => 'not between', 'between time' => 'between time', 'not between time' => 'not between time', 'notbetween time' => 'not between time', 'like' => 'like', 'near' => 'near', 'size' => 'size'];
|
protected $exp = ['<>' => 'ne', 'neq' => 'ne', '=' => 'eq', '>' => 'gt', '>=' => 'gte', '<' => 'lt', '<=' => 'lte', 'in' => 'in', 'not in' => 'nin', 'nin' => 'nin', 'mod' => 'mod', 'exists' => 'exists', 'regex' => 'regex', 'type' => 'type', 'all' => 'all', '> time' => '> time', '< time' => '< time', 'between' => 'between', 'not between' => 'not between', 'between time' => 'between time', 'not between time' => 'not between time', 'notbetween time' => 'not between time', 'like' => 'like', 'near' => 'near'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 架构函数
|
* 架构函数
|
||||||
@ -51,9 +54,6 @@ class Builder
|
|||||||
*/
|
*/
|
||||||
protected function parseKey($key)
|
protected function parseKey($key)
|
||||||
{
|
{
|
||||||
if (0 === strpos($key, '__TABLE__.')) {
|
|
||||||
list($collection, $key) = explode('.', $key, 2);
|
|
||||||
}
|
|
||||||
if ('id' == $key && $this->connection->getConfig('pk_convert_id')) {
|
if ('id' == $key && $this->connection->getConfig('pk_convert_id')) {
|
||||||
$key = '_id';
|
$key = '_id';
|
||||||
}
|
}
|
||||||
@ -69,12 +69,8 @@ class Builder
|
|||||||
*/
|
*/
|
||||||
protected function parseValue($value, $field = '')
|
protected function parseValue($value, $field = '')
|
||||||
{
|
{
|
||||||
if ('_id' == $field && 'ObjectID' == $this->connection->getConfig('pk_type') && is_string($value)) {
|
if ('_id' == $field && !($value instanceof ObjectID)) {
|
||||||
try {
|
return new ObjectID($value);
|
||||||
return new ObjectID($value);
|
|
||||||
} catch (InvalidArgumentException $e) {
|
|
||||||
return new ObjectID();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
@ -124,7 +120,7 @@ class Builder
|
|||||||
$result = [];
|
$result = [];
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
$item = $this->parseKey($key);
|
$item = $this->parseKey($key);
|
||||||
if (is_array($val) && isset($val[0]) && is_string($val[0]) && 0 === strpos($val[0], '$')) {
|
if (is_array($val) && isset($val[0]) && in_array($val[0], ['$inc', '$set', '$unset', '$push', '$pushall', '$addtoset', '$pop', '$pull', '$pullall'])) {
|
||||||
$result[$val[0]][$item] = $this->parseValue($val[1], $key);
|
$result[$val[0]][$item] = $this->parseValue($val[1], $key);
|
||||||
} else {
|
} else {
|
||||||
$result['$set'][$item] = $this->parseValue($val, $key);
|
$result['$set'][$item] = $this->parseValue($val, $key);
|
||||||
@ -139,7 +135,7 @@ class Builder
|
|||||||
* @param mixed $where
|
* @param mixed $where
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function parseWhere($where, $options = [])
|
public function parseWhere($where)
|
||||||
{
|
{
|
||||||
if (empty($where)) {
|
if (empty($where)) {
|
||||||
$where = [];
|
$where = [];
|
||||||
@ -152,7 +148,7 @@ class Builder
|
|||||||
// 使用闭包查询
|
// 使用闭包查询
|
||||||
$query = new Query($this->connection);
|
$query = new Query($this->connection);
|
||||||
call_user_func_array($value, [ & $query]);
|
call_user_func_array($value, [ & $query]);
|
||||||
$filter[$logic][] = $this->parseWhere($query->getOptions('where'), $options);
|
$filter[$logic][] = $this->parseWhere($query->getOptions('where')[$logic]);
|
||||||
} else {
|
} else {
|
||||||
if (strpos($field, '|')) {
|
if (strpos($field, '|')) {
|
||||||
// 不同字段使用相同查询条件(OR)
|
// 不同字段使用相同查询条件(OR)
|
||||||
@ -174,14 +170,6 @@ class Builder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options['soft_delete'])) {
|
|
||||||
// 附加软删除条件
|
|
||||||
list($field, $condition) = $options['soft_delete'];
|
|
||||||
|
|
||||||
$filter['$and'][] = $this->parseWhereItem($field, $condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $filter;
|
return $filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,22 +185,14 @@ class Builder
|
|||||||
|
|
||||||
// 对一个字段使用多个查询条件
|
// 对一个字段使用多个查询条件
|
||||||
if (is_array($exp)) {
|
if (is_array($exp)) {
|
||||||
$data = [];
|
foreach ($val as $item) {
|
||||||
foreach ($val as $value) {
|
$str[] = $this->parseWhereItem($key, $item);
|
||||||
$exp = $value[0];
|
|
||||||
$value = $value[1];
|
|
||||||
if (!in_array($exp, $this->exp)) {
|
|
||||||
$exp = strtolower($exp);
|
|
||||||
if (isset($this->exp[$exp])) {
|
|
||||||
$exp = $this->exp[$exp];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$k = '$' . $exp;
|
|
||||||
$data[$k] = $value;
|
|
||||||
}
|
}
|
||||||
$query[$key] = $data;
|
return $str;
|
||||||
return $query;
|
}
|
||||||
} elseif (!in_array($exp, $this->exp)) {
|
|
||||||
|
// 检测操作符
|
||||||
|
if (!in_array($exp, $this->exp)) {
|
||||||
$exp = strtolower($exp);
|
$exp = strtolower($exp);
|
||||||
if (isset($this->exp[$exp])) {
|
if (isset($this->exp[$exp])) {
|
||||||
$exp = $this->exp[$exp];
|
$exp = $this->exp[$exp];
|
||||||
@ -229,11 +209,6 @@ class Builder
|
|||||||
// 比较运算
|
// 比较运算
|
||||||
$k = '$' . $exp;
|
$k = '$' . $exp;
|
||||||
$query[$key] = [$k => $this->parseValue($value, $key)];
|
$query[$key] = [$k => $this->parseValue($value, $key)];
|
||||||
} elseif ('null' == $exp) {
|
|
||||||
// NULL 查询
|
|
||||||
$query[$key] = null;
|
|
||||||
} elseif ('not null' == $exp) {
|
|
||||||
$query[$key] = ['$ne' => null];
|
|
||||||
} elseif ('all' == $exp) {
|
} elseif ('all' == $exp) {
|
||||||
// 满足所有指定条件
|
// 满足所有指定条件
|
||||||
$query[$key] = ['$all', $this->parseValue($value, $key)];
|
$query[$key] = ['$all', $this->parseValue($value, $key)];
|
||||||
@ -281,9 +256,6 @@ class Builder
|
|||||||
} elseif ('near' == $exp) {
|
} elseif ('near' == $exp) {
|
||||||
// 经纬度查询
|
// 经纬度查询
|
||||||
$query[$key] = ['$near' => $this->parseValue($value, $key)];
|
$query[$key] = ['$near' => $this->parseValue($value, $key)];
|
||||||
} elseif ('size' == $exp) {
|
|
||||||
// 元素长度查询
|
|
||||||
$query[$key] = ['$size' => intval($value)];
|
|
||||||
} else {
|
} else {
|
||||||
// 普通查询
|
// 普通查询
|
||||||
$query[$key] = $this->parseValue($value, $key);
|
$query[$key] = $this->parseValue($value, $key);
|
||||||
@ -354,8 +326,6 @@ class Builder
|
|||||||
public function insertAll($dataSet, $options = [])
|
public function insertAll($dataSet, $options = [])
|
||||||
{
|
{
|
||||||
$bulk = new BulkWrite;
|
$bulk = new BulkWrite;
|
||||||
|
|
||||||
$this->insertId = [];
|
|
||||||
foreach ($dataSet as $data) {
|
foreach ($dataSet as $data) {
|
||||||
// 分析并处理数据
|
// 分析并处理数据
|
||||||
$data = $this->parseData($data, $options);
|
$data = $this->parseData($data, $options);
|
||||||
@ -377,7 +347,7 @@ class Builder
|
|||||||
public function update($data, $options = [])
|
public function update($data, $options = [])
|
||||||
{
|
{
|
||||||
$data = $this->parseSet($data, $options);
|
$data = $this->parseSet($data, $options);
|
||||||
$where = $this->parseWhere($options['where'], $options);
|
$where = $this->parseWhere($options['where']);
|
||||||
|
|
||||||
if (1 == $options['limit']) {
|
if (1 == $options['limit']) {
|
||||||
$updateOptions = ['multi' => false];
|
$updateOptions = ['multi' => false];
|
||||||
@ -398,7 +368,7 @@ class Builder
|
|||||||
*/
|
*/
|
||||||
public function delete($options)
|
public function delete($options)
|
||||||
{
|
{
|
||||||
$where = $this->parseWhere($options['where'], $options);
|
$where = $this->parseWhere($options['where']);
|
||||||
$bulk = new BulkWrite;
|
$bulk = new BulkWrite;
|
||||||
if (1 == $options['limit']) {
|
if (1 == $options['limit']) {
|
||||||
$deleteOptions = ['limit' => 1];
|
$deleteOptions = ['limit' => 1];
|
||||||
@ -418,7 +388,7 @@ class Builder
|
|||||||
*/
|
*/
|
||||||
public function select($options)
|
public function select($options)
|
||||||
{
|
{
|
||||||
$where = $this->parseWhere($options['where'], $options);
|
$where = $this->parseWhere($options['where']);
|
||||||
$query = new MongoQuery($where, $options);
|
$query = new MongoQuery($where, $options);
|
||||||
$this->log('find', $where, $options);
|
$this->log('find', $where, $options);
|
||||||
return $query;
|
return $query;
|
||||||
@ -433,7 +403,7 @@ class Builder
|
|||||||
public function count($options)
|
public function count($options)
|
||||||
{
|
{
|
||||||
$cmd['count'] = $options['table'];
|
$cmd['count'] = $options['table'];
|
||||||
$cmd['query'] = $this->parseWhere($options['where'], $options);
|
$cmd['query'] = $this->parseWhere($options['where']);
|
||||||
foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
|
foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
|
||||||
if (isset($options[$option])) {
|
if (isset($options[$option])) {
|
||||||
$cmd[$option] = $options[$option];
|
$cmd[$option] = $options[$option];
|
||||||
@ -444,76 +414,6 @@ class Builder
|
|||||||
return $command;
|
return $command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 聚合查询命令
|
|
||||||
* @access public
|
|
||||||
* @param array $options 参数
|
|
||||||
* @param array $extra 指令和字段
|
|
||||||
* @return Command
|
|
||||||
*/
|
|
||||||
public function aggregate($options, $extra)
|
|
||||||
{
|
|
||||||
list($fun, $field) = $extra;
|
|
||||||
$pipeline = [
|
|
||||||
['$match' => (object) $this->parseWhere($options['where'], $options)],
|
|
||||||
['$group' => ['_id' => null, 'aggregate' => ['$' . $fun => '$' . $field]]],
|
|
||||||
];
|
|
||||||
$cmd = [
|
|
||||||
'aggregate' => $options['table'],
|
|
||||||
'allowDiskUse' => true,
|
|
||||||
'pipeline' => $pipeline,
|
|
||||||
'cursor' => new \stdClass,
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach (['explain', 'collation', 'bypassDocumentValidation', 'readConcern'] as $option) {
|
|
||||||
if (isset($options[$option])) {
|
|
||||||
$cmd[$option] = $options[$option];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$command = new Command($cmd);
|
|
||||||
$this->log('aggregate', $cmd);
|
|
||||||
return $command;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 多聚合查询命令, 可以对多个字段进行 group by 操作
|
|
||||||
*
|
|
||||||
* @param array $options 参数
|
|
||||||
* @param array $extra 指令和字段
|
|
||||||
* @return Command
|
|
||||||
*/
|
|
||||||
public function multiAggregate($options, $extra)
|
|
||||||
{
|
|
||||||
list($aggregate, $groupBy) = $extra;
|
|
||||||
$groups = ['_id' => []];
|
|
||||||
foreach ($groupBy as $field) {
|
|
||||||
$groups['_id'][$field] = '$' . $field;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($aggregate as $fun => $field) {
|
|
||||||
$groups[$field . '_' . $fun] = ['$' . $fun => '$' . $field];
|
|
||||||
}
|
|
||||||
$pipeline = [
|
|
||||||
['$match' => (object) $this->parseWhere($options['where'], $options)],
|
|
||||||
['$group' => $groups],
|
|
||||||
];
|
|
||||||
$cmd = [
|
|
||||||
'aggregate' => $options['table'],
|
|
||||||
'allowDiskUse' => true,
|
|
||||||
'pipeline' => $pipeline,
|
|
||||||
'cursor' => new \stdClass,
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach (['explain', 'collation', 'bypassDocumentValidation', 'readConcern'] as $option) {
|
|
||||||
if (isset($options[$option])) {
|
|
||||||
$cmd[$option] = $options[$option];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$command = new Command($cmd);
|
|
||||||
$this->log('group', $cmd);
|
|
||||||
return $command;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成distinct命令
|
* 生成distinct命令
|
||||||
* @access public
|
* @access public
|
||||||
@ -529,7 +429,7 @@ class Builder
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($options['where'])) {
|
if (!empty($options['where'])) {
|
||||||
$cmd['query'] = $this->parseWhere($options['where'], $options);
|
$cmd['query'] = $this->parseWhere($options['where']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['maxTimeMS'])) {
|
if (isset($options['maxTimeMS'])) {
|
||||||
|
184
vendor/topthink/think-mongo/src/Connection.php
vendored
184
vendor/topthink/think-mongo/src/Connection.php
vendored
@ -2,6 +2,8 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
@ -9,9 +11,9 @@
|
|||||||
|
|
||||||
namespace think\mongo;
|
namespace think\mongo;
|
||||||
|
|
||||||
use MongoDB\BSON\ObjectID;
|
|
||||||
use MongoDB\Driver\BulkWrite;
|
use MongoDB\Driver\BulkWrite;
|
||||||
use MongoDB\Driver\Command;
|
use MongoDB\Driver\Command;
|
||||||
|
use MongoDB\Driver\Cursor;
|
||||||
use MongoDB\Driver\Exception\AuthenticationException;
|
use MongoDB\Driver\Exception\AuthenticationException;
|
||||||
use MongoDB\Driver\Exception\BulkWriteException;
|
use MongoDB\Driver\Exception\BulkWriteException;
|
||||||
use MongoDB\Driver\Exception\ConnectionException;
|
use MongoDB\Driver\Exception\ConnectionException;
|
||||||
@ -21,10 +23,12 @@ use MongoDB\Driver\Manager;
|
|||||||
use MongoDB\Driver\Query as MongoQuery;
|
use MongoDB\Driver\Query as MongoQuery;
|
||||||
use MongoDB\Driver\ReadPreference;
|
use MongoDB\Driver\ReadPreference;
|
||||||
use MongoDB\Driver\WriteConcern;
|
use MongoDB\Driver\WriteConcern;
|
||||||
|
use think\Collection;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use think\Debug;
|
use think\Debug;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\Log;
|
use think\Log;
|
||||||
|
use think\mongo\Query as Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mongo数据库驱动
|
* Mongo数据库驱动
|
||||||
@ -34,6 +38,8 @@ class Connection
|
|||||||
protected $dbName = ''; // dbName
|
protected $dbName = ''; // dbName
|
||||||
/** @var string 当前SQL指令 */
|
/** @var string 当前SQL指令 */
|
||||||
protected $queryStr = '';
|
protected $queryStr = '';
|
||||||
|
// 查询数据集类型
|
||||||
|
protected $resultSetType = 'array';
|
||||||
// 查询数据类型
|
// 查询数据类型
|
||||||
protected $typeMap = 'array';
|
protected $typeMap = 'array';
|
||||||
protected $mongo; // MongoDb Object
|
protected $mongo; // MongoDb Object
|
||||||
@ -59,57 +65,51 @@ class Connection
|
|||||||
// 数据库连接参数配置
|
// 数据库连接参数配置
|
||||||
protected $config = [
|
protected $config = [
|
||||||
// 数据库类型
|
// 数据库类型
|
||||||
'type' => '',
|
'type' => '',
|
||||||
// 服务器地址
|
// 服务器地址
|
||||||
'hostname' => '',
|
'hostname' => '',
|
||||||
// 数据库名
|
// 数据库名
|
||||||
'database' => '',
|
'database' => '',
|
||||||
// 是否是复制集
|
|
||||||
'is_replica_set' => false,
|
|
||||||
// 用户名
|
// 用户名
|
||||||
'username' => '',
|
'username' => '',
|
||||||
// 密码
|
// 密码
|
||||||
'password' => '',
|
'password' => '',
|
||||||
// 端口
|
// 端口
|
||||||
'hostport' => '',
|
'hostport' => '',
|
||||||
// 连接dsn
|
// 连接dsn
|
||||||
'dsn' => '',
|
'dsn' => '',
|
||||||
// 数据库连接参数
|
// 数据库连接参数
|
||||||
'params' => [],
|
'params' => [],
|
||||||
// 数据库编码默认采用utf8
|
// 数据库编码默认采用utf8
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
// 主键名
|
// 主键名
|
||||||
'pk' => '_id',
|
'pk' => '_id',
|
||||||
// 主键类型
|
|
||||||
'pk_type' => 'ObjectID',
|
|
||||||
// 数据库表前缀
|
// 数据库表前缀
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
// 数据库调试模式
|
// 数据库调试模式
|
||||||
'debug' => false,
|
'debug' => false,
|
||||||
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
|
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
|
||||||
'deploy' => 0,
|
'deploy' => 0,
|
||||||
// 数据库读写是否分离 主从式有效
|
// 数据库读写是否分离 主从式有效
|
||||||
'rw_separate' => false,
|
'rw_separate' => false,
|
||||||
// 读写分离后 主服务器数量
|
// 读写分离后 主服务器数量
|
||||||
'master_num' => 1,
|
'master_num' => 1,
|
||||||
// 指定从服务器序号
|
// 指定从服务器序号
|
||||||
'slave_no' => '',
|
'slave_no' => '',
|
||||||
// 是否严格检查字段是否存在
|
// 是否严格检查字段是否存在
|
||||||
'fields_strict' => true,
|
'fields_strict' => true,
|
||||||
// 数据集返回类型
|
// 数据集返回类型
|
||||||
'resultset_type' => 'array',
|
'resultset_type' => 'array',
|
||||||
// 自动写入时间戳字段
|
// 自动写入时间戳字段
|
||||||
'auto_timestamp' => false,
|
'auto_timestamp' => false,
|
||||||
// 时间字段取出后的默认时间格式
|
|
||||||
'datetime_format' => 'Y-m-d H:i:s',
|
|
||||||
// 是否需要进行SQL性能分析
|
// 是否需要进行SQL性能分析
|
||||||
'sql_explain' => false,
|
'sql_explain' => false,
|
||||||
// 是否_id转换为id
|
// 是否_id转换为id
|
||||||
'pk_convert_id' => false,
|
'pk_convert_id' => false,
|
||||||
// typeMap
|
// typeMap
|
||||||
'type_map' => ['root' => 'array', 'document' => 'array'],
|
'type_map' => ['root' => 'array', 'document' => 'array'],
|
||||||
// Query对象
|
// Query对象
|
||||||
'query' => '\\think\\mongo\\Query',
|
'query' => '\\think\\mongo\\Query',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,11 +145,14 @@ class Connection
|
|||||||
}
|
}
|
||||||
$this->dbName = $config['database'];
|
$this->dbName = $config['database'];
|
||||||
$this->typeMap = $config['type_map'];
|
$this->typeMap = $config['type_map'];
|
||||||
|
// 记录数据集返回类型
|
||||||
|
if (isset($config['resultset_type'])) {
|
||||||
|
$this->resultSetType = $config['resultset_type'];
|
||||||
|
}
|
||||||
if ($config['pk_convert_id'] && '_id' == $config['pk']) {
|
if ($config['pk_convert_id'] && '_id' == $config['pk']) {
|
||||||
$this->config['pk'] = 'id';
|
$this->config['pk'] = 'id';
|
||||||
}
|
}
|
||||||
$host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
|
$host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . '/' . ($config['database'] ? "{$config['database']}" : '');
|
||||||
if ($config['debug']) {
|
if ($config['debug']) {
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
}
|
}
|
||||||
@ -162,18 +165,6 @@ class Connection
|
|||||||
return $this->links[$linkNum];
|
return $this->links[$linkNum];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定当前使用的查询对象
|
|
||||||
* @access public
|
|
||||||
* @param Query $query 查询对象
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setQuery($query, $model = 'db')
|
|
||||||
{
|
|
||||||
$this->query[$model] = $query;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建指定模型的查询对象
|
* 创建指定模型的查询对象
|
||||||
* @access public
|
* @access public
|
||||||
@ -181,11 +172,11 @@ class Connection
|
|||||||
* @param string $queryClass 查询对象类名
|
* @param string $queryClass 查询对象类名
|
||||||
* @return Query
|
* @return Query
|
||||||
*/
|
*/
|
||||||
public function getQuery($model = 'db', $queryClass = '')
|
public function model($model, $queryClass = '')
|
||||||
{
|
{
|
||||||
if (!isset($this->query[$model])) {
|
if (!isset($this->query[$model])) {
|
||||||
$class = $queryClass ?: $this->config['query'];
|
$class = $queryClass ?: $this->config['query'];
|
||||||
$this->query[$model] = new $class($this, 'db' == $model ? '' : $model);
|
$this->query[$model] = new $class($this, $model);
|
||||||
}
|
}
|
||||||
return $this->query[$model];
|
return $this->query[$model];
|
||||||
}
|
}
|
||||||
@ -199,7 +190,11 @@ class Connection
|
|||||||
*/
|
*/
|
||||||
public function __call($method, $args)
|
public function __call($method, $args)
|
||||||
{
|
{
|
||||||
return call_user_func_array([$this->getQuery(), $method], $args);
|
if (!isset($this->query['database'])) {
|
||||||
|
$class = $this->config['query'];
|
||||||
|
$this->query['database'] = new $class($this);
|
||||||
|
}
|
||||||
|
return call_user_func_array([$this->query['database'], $method], $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,7 +228,7 @@ class Connection
|
|||||||
public function getMongo()
|
public function getMongo()
|
||||||
{
|
{
|
||||||
if (!$this->mongo) {
|
if (!$this->mongo) {
|
||||||
return;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return $this->mongo;
|
return $this->mongo;
|
||||||
}
|
}
|
||||||
@ -300,7 +295,7 @@ class Connection
|
|||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function command(Command $command, $dbName = '', ReadPreference $readPreference = null, $class = false, $typeMap = null)
|
public function command(Command $command, $dbName = '', ReadPreference $readPreference = null, $class = false, $typeMap)
|
||||||
{
|
{
|
||||||
$this->initConnect(false);
|
$this->initConnect(false);
|
||||||
Db::$queryTimes++;
|
Db::$queryTimes++;
|
||||||
@ -308,7 +303,7 @@ class Connection
|
|||||||
$this->debug(true);
|
$this->debug(true);
|
||||||
$dbName = $dbName ?: $this->dbName;
|
$dbName = $dbName ?: $this->dbName;
|
||||||
if ($this->config['debug'] && !empty($this->queryStr)) {
|
if ($this->config['debug'] && !empty($this->queryStr)) {
|
||||||
$this->queryStr = 'db.' . $this->queryStr;
|
$this->queryStr = 'db.' . $dbName . '.' . $this->queryStr;
|
||||||
}
|
}
|
||||||
$this->cursor = $this->mongo->executeCommand($dbName, $command, $readPreference);
|
$this->cursor = $this->mongo->executeCommand($dbName, $command, $readPreference);
|
||||||
$this->debug(false);
|
$this->debug(false);
|
||||||
@ -344,7 +339,13 @@ class Connection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->numRows = count($result);
|
$this->numRows = count($result);
|
||||||
|
if (!empty($class)) {
|
||||||
|
// 返回指定数据集对象类
|
||||||
|
$result = new $class($result);
|
||||||
|
} elseif ('collection' == $this->resultSetType) {
|
||||||
|
// 返回数据集Collection对象
|
||||||
|
$result = new Collection($result);
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,9 +416,6 @@ class Connection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
switch (strtolower($type)) {
|
switch (strtolower($type)) {
|
||||||
case 'aggregate':
|
|
||||||
$this->queryStr = 'runCommand(' . ($data ? json_encode($data) : '') . ');';
|
|
||||||
break;
|
|
||||||
case 'find':
|
case 'find':
|
||||||
$this->queryStr = $type . '(' . ($data ? json_encode($data) : '') . ')';
|
$this->queryStr = $type . '(' . ($data ? json_encode($data) : '') . ')';
|
||||||
if (isset($options['sort'])) {
|
if (isset($options['sort'])) {
|
||||||
@ -524,11 +522,10 @@ class Connection
|
|||||||
*/
|
*/
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
$this->mongo = null;
|
if ($this->mongo) {
|
||||||
$this->cursor = null;
|
$this->mongo = null;
|
||||||
$this->linkRead = null;
|
$this->cursor = null;
|
||||||
$this->linkWrite = null;
|
}
|
||||||
$this->links = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -579,11 +576,7 @@ class Connection
|
|||||||
// 主从式采用读写分离
|
// 主从式采用读写分离
|
||||||
if ($master) // 主服务器写入
|
if ($master) // 主服务器写入
|
||||||
{
|
{
|
||||||
if ($this->config['is_replica_set']) {
|
$r = $m;
|
||||||
return $this->replicaSetConnect();
|
|
||||||
} else {
|
|
||||||
$r = $m;
|
|
||||||
}
|
|
||||||
} elseif (is_numeric($this->config['slave_no'])) {
|
} elseif (is_numeric($this->config['slave_no'])) {
|
||||||
// 指定服务器读
|
// 指定服务器读
|
||||||
$r = $this->config['slave_no'];
|
$r = $this->config['slave_no'];
|
||||||
@ -602,69 +595,6 @@ class Connection
|
|||||||
return $this->connect($dbConfig, $r);
|
return $this->connect($dbConfig, $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建基于复制集的连接
|
|
||||||
* @return Manager
|
|
||||||
*/
|
|
||||||
public function replicaSetConnect()
|
|
||||||
{
|
|
||||||
$this->dbName = $this->config['database'];
|
|
||||||
$this->typeMap = $this->config['type_map'];
|
|
||||||
if ($this->config['debug']) {
|
|
||||||
$startTime = microtime(true);
|
|
||||||
}
|
|
||||||
$this->config['params']['replicaSet'] = $this->config['database'];
|
|
||||||
$manager = new Manager($this->buildUrl(), $this->config['params']);
|
|
||||||
if ($this->config['debug']) {
|
|
||||||
// 记录数据库连接信息
|
|
||||||
Log::record('[ DB ] CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $this->config['dsn'], 'sql');
|
|
||||||
}
|
|
||||||
return $manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据配置信息 生成适用于链接复制集的 URL
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildUrl()
|
|
||||||
{
|
|
||||||
$url = 'mongodb://' . ($this->config['username'] ? "{$this->config['username']}" : '') . ($this->config['password'] ? ":{$this->config['password']}@" : '');
|
|
||||||
$hostList = explode(',', $this->config['hostname']);
|
|
||||||
$portList = explode(',', $this->config['hostport']);
|
|
||||||
for ($i = 0; $i < count($hostList); $i++) {
|
|
||||||
$url = $url . $hostList[$i] . ':' . $portList[0] . ',';
|
|
||||||
}
|
|
||||||
return rtrim($url, ",") . '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 启动事务
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
* @throws \PDOException
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function startTrans()
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用于非自动提交状态下面的查询提交
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
* @throws PDOException
|
|
||||||
*/
|
|
||||||
public function commit()
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 事务回滚
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
* @throws PDOException
|
|
||||||
*/
|
|
||||||
public function rollback()
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 析构方法
|
* 析构方法
|
||||||
* @access public
|
* @access public
|
||||||
|
664
vendor/topthink/think-mongo/src/Query.php
vendored
664
vendor/topthink/think-mongo/src/Query.php
vendored
@ -2,6 +2,8 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
@ -31,14 +33,16 @@ use think\Exception;
|
|||||||
use think\exception\DbException;
|
use think\exception\DbException;
|
||||||
use think\Loader;
|
use think\Loader;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
|
use think\mongo\Builder;
|
||||||
|
use think\mongo\Connection;
|
||||||
use think\Paginator;
|
use think\Paginator;
|
||||||
|
|
||||||
class Query
|
class Query
|
||||||
{
|
{
|
||||||
// 数据库Connection对象实例
|
// 数据库Connection对象实例
|
||||||
protected $connection;
|
protected $connection;
|
||||||
// 数据库Builder对象实例
|
// 数据库驱动类型
|
||||||
protected $builder;
|
protected $driver;
|
||||||
// 当前模型类名称
|
// 当前模型类名称
|
||||||
protected $model;
|
protected $model;
|
||||||
// 当前数据表名称(含前缀)
|
// 当前数据表名称(含前缀)
|
||||||
@ -53,8 +57,6 @@ class Query
|
|||||||
protected $options = [];
|
protected $options = [];
|
||||||
// 数据表信息
|
// 数据表信息
|
||||||
protected static $info = [];
|
protected static $info = [];
|
||||||
// 回调事件
|
|
||||||
private static $event = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 架构函数
|
* 架构函数
|
||||||
@ -67,8 +69,7 @@ class Query
|
|||||||
$this->connection = $connection ?: Db::connect([], true);
|
$this->connection = $connection ?: Db::connect([], true);
|
||||||
$this->prefix = $this->connection->getConfig('prefix');
|
$this->prefix = $this->connection->getConfig('prefix');
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
// 设置当前连接的Builder对象
|
$this->builder = new Builder($this->connection, $this);
|
||||||
$this->setBuilder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,20 +117,9 @@ class Query
|
|||||||
public function connect($config)
|
public function connect($config)
|
||||||
{
|
{
|
||||||
$this->connection = Db::connect($config);
|
$this->connection = Db::connect($config);
|
||||||
$this->setBuilder();
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置当前的数据库Builder对象
|
|
||||||
* @access protected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function setBuilder()
|
|
||||||
{
|
|
||||||
$this->builder = new Builder($this->connection, $this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定默认的数据表名(不含前缀)
|
* 指定默认的数据表名(不含前缀)
|
||||||
* @access public
|
* @access public
|
||||||
@ -186,38 +176,6 @@ class Query
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 去除某个查询条件
|
|
||||||
* @access public
|
|
||||||
* @param string $field 查询字段
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function removeWhereField($field, $logic = 'and')
|
|
||||||
{
|
|
||||||
$logic = '$' . strtoupper($logic);
|
|
||||||
if (isset($this->options['where'][$logic][$field])) {
|
|
||||||
unset($this->options['where'][$logic][$field]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 去除查询参数
|
|
||||||
* @access public
|
|
||||||
* @param string|bool $option 参数名 true 表示去除所有参数
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function removeOption($option = true)
|
|
||||||
{
|
|
||||||
if (true === $option) {
|
|
||||||
$this->options = [];
|
|
||||||
} elseif (is_string($option) && isset($this->options[$option])) {
|
|
||||||
unset($this->options[$option]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将SQL语句中的__TABLE_NAME__字符串替换成带前缀的表名(小写)
|
* 将SQL语句中的__TABLE_NAME__字符串替换成带前缀的表名(小写)
|
||||||
* @access public
|
* @access public
|
||||||
@ -356,7 +314,7 @@ class Query
|
|||||||
$result = $data[$field];
|
$result = $data[$field];
|
||||||
if (isset($cache)) {
|
if (isset($cache)) {
|
||||||
// 缓存数据
|
// 缓存数据
|
||||||
$this->cacheData($key, $result, $cache);
|
Cache::set($key, $result, $cache['expire']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 清空查询条件
|
// 清空查询条件
|
||||||
@ -385,8 +343,8 @@ class Query
|
|||||||
$result = Cache::get($guid);
|
$result = Cache::get($guid);
|
||||||
}
|
}
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
if (isset($this->options['projection'])) {
|
if (isset($this->options['field'])) {
|
||||||
unset($this->options['projection']);
|
unset($this->options['field']);
|
||||||
}
|
}
|
||||||
if ($key && '*' != $field) {
|
if ($key && '*' != $field) {
|
||||||
$field = $key . ',' . $field;
|
$field = $key . ',' . $field;
|
||||||
@ -419,7 +377,7 @@ class Query
|
|||||||
|
|
||||||
if (isset($cache) && isset($guid)) {
|
if (isset($cache) && isset($guid)) {
|
||||||
// 缓存数据
|
// 缓存数据
|
||||||
$this->cacheData($guid, $result, $cache);
|
Cache::set($guid, $result, $cache['expire']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 清空查询条件
|
// 清空查询条件
|
||||||
@ -491,85 +449,6 @@ class Query
|
|||||||
return $result[0]['n'];
|
return $result[0]['n'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 多聚合操作
|
|
||||||
*
|
|
||||||
* @param array $aggregate 聚合指令, 可以聚合多个参数, 如 ['sum' => 'field1', 'avg' => 'field2']
|
|
||||||
* @param array $groupBy 类似mysql里面的group字段, 可以传入多个字段, 如 ['field_a', 'field_b', 'field_c']
|
|
||||||
* @return array 查询结果
|
|
||||||
*/
|
|
||||||
public function multiAggregate($aggregate, $groupBy)
|
|
||||||
{
|
|
||||||
$result = $this->cmd('multiAggregate', [$aggregate, $groupBy]);
|
|
||||||
$result = isset($result[0]['result']) ? $result[0]['result'] : [];
|
|
||||||
foreach ($result as &$row) {
|
|
||||||
if (isset($row['_id']) && !empty($row['_id'])) {
|
|
||||||
foreach ($row['_id'] as $k => $v) {
|
|
||||||
$row[$k] = $v;
|
|
||||||
}
|
|
||||||
unset($row['_id']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 聚合查询
|
|
||||||
* @access public
|
|
||||||
* @param string $aggregate 聚合指令
|
|
||||||
* @param string $field 字段名
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function aggregate($aggregate, $field)
|
|
||||||
{
|
|
||||||
$result = $this->cmd('aggregate', [$aggregate, $field]);
|
|
||||||
return isset($result[0]['aggregate']) ? $result[0]['aggregate'] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MAX查询
|
|
||||||
* @access public
|
|
||||||
* @param string $field 字段名
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function max($field)
|
|
||||||
{
|
|
||||||
return $this->aggregate('max', $field);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MIN查询
|
|
||||||
* @access public
|
|
||||||
* @param string $field 字段名
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function min($field)
|
|
||||||
{
|
|
||||||
return $this->aggregate('min', $field);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SUM查询
|
|
||||||
* @access public
|
|
||||||
* @param string $field 字段名
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function sum($field)
|
|
||||||
{
|
|
||||||
return $this->aggregate('sum', $field);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AVG查询
|
|
||||||
* @access public
|
|
||||||
* @param string $field 字段名
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function avg($field)
|
|
||||||
{
|
|
||||||
return $this->aggregate('avg', $field);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置记录的某个字段值
|
* 设置记录的某个字段值
|
||||||
* 支持使用数据库字段和方法
|
* 支持使用数据库字段和方法
|
||||||
@ -674,55 +553,6 @@ class Query
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置数据
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 字段名或者数据
|
|
||||||
* @param mixed $value 字段值
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function data($field, $value = null)
|
|
||||||
{
|
|
||||||
if (is_array($field)) {
|
|
||||||
$this->options['data'] = isset($this->options['data']) ? array_merge($this->options['data'], $field) : $field;
|
|
||||||
} else {
|
|
||||||
$this->options['data'][$field] = $value;
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字段值增长
|
|
||||||
* @access public
|
|
||||||
* @param string|array $field 字段名
|
|
||||||
* @param integer $step 增长值
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function inc($field, $step = 1)
|
|
||||||
{
|
|
||||||
$fields = is_string($field) ? explode(',', $field) : $field;
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$this->data($field, ['$inc', $step]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字段值减少
|
|
||||||
* @access public
|
|
||||||
* @param string|array $field 字段名
|
|
||||||
* @param integer $step 减少值
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function dec($field, $step = 1)
|
|
||||||
{
|
|
||||||
$fields = is_string($field) ? explode(',', $field) : $field;
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$this->data($field, ['$inc', -1 * $step]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定AND查询条件
|
* 指定AND查询条件
|
||||||
* @access public
|
* @access public
|
||||||
@ -735,7 +565,7 @@ class Query
|
|||||||
{
|
{
|
||||||
$param = func_get_args();
|
$param = func_get_args();
|
||||||
array_shift($param);
|
array_shift($param);
|
||||||
$this->parseWhereExp('and', $field, $op, $condition, $param);
|
$this->parseWhereExp('$and', $field, $op, $condition, $param);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,7 +581,7 @@ class Query
|
|||||||
{
|
{
|
||||||
$param = func_get_args();
|
$param = func_get_args();
|
||||||
array_shift($param);
|
array_shift($param);
|
||||||
$this->parseWhereExp('or', $field, $op, $condition, $param);
|
$this->parseWhereExp('$or', $field, $op, $condition, $param);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -767,117 +597,7 @@ class Query
|
|||||||
{
|
{
|
||||||
$param = func_get_args();
|
$param = func_get_args();
|
||||||
array_shift($param);
|
array_shift($param);
|
||||||
$this->parseWhereExp('nor', $field, $op, $condition, $param);
|
$this->parseWhereExp('$nor', $field, $op, $condition, $param);
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定Null查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereNull($field, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'null', null);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定NotNull查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereNotNull($field, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'notnull', null);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定In查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param mixed $condition 查询条件
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereIn($field, $condition, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'in', $condition);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定NotIn查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param mixed $condition 查询条件
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereNotIn($field, $condition, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'not in', $condition);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定Like查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param mixed $condition 查询条件
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereLike($field, $condition, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'like', $condition);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定Between查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param mixed $condition 查询条件
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereBetween($field, $condition, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'between', $condition);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定NotBetween查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param mixed $condition 查询条件
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereNotBetween($field, $condition, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'not between', $condition);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定Exp查询条件
|
|
||||||
* @access public
|
|
||||||
* @param mixed $field 查询字段
|
|
||||||
* @param mixed $condition 查询条件
|
|
||||||
* @param string $logic 查询逻辑 and or xor
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function whereExp($field, $condition, $logic = 'and')
|
|
||||||
{
|
|
||||||
$this->parseWhereExp($logic, $field, 'exp', $condition);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -893,7 +613,6 @@ class Query
|
|||||||
*/
|
*/
|
||||||
protected function parseWhereExp($logic, $field, $op, $condition, $param = [])
|
protected function parseWhereExp($logic, $field, $op, $condition, $param = [])
|
||||||
{
|
{
|
||||||
$logic = '$' . strtolower($logic);
|
|
||||||
if ($field instanceof \Closure) {
|
if ($field instanceof \Closure) {
|
||||||
$this->options['where'][$logic][] = is_string($op) ? [$op, $field] : $field;
|
$this->options['where'][$logic][] = is_string($op) ? [$op, $field] : $field;
|
||||||
return;
|
return;
|
||||||
@ -911,9 +630,6 @@ class Query
|
|||||||
}
|
}
|
||||||
} elseif (is_array($op)) {
|
} elseif (is_array($op)) {
|
||||||
$where[$field] = $param;
|
$where[$field] = $param;
|
||||||
} elseif (in_array(strtolower($op), ['null', 'notnull', 'not null'])) {
|
|
||||||
// null查询
|
|
||||||
$where[$field] = [$op, ''];
|
|
||||||
} elseif (is_null($condition)) {
|
} elseif (is_null($condition)) {
|
||||||
// 字段相等查询
|
// 字段相等查询
|
||||||
$where[$field] = ['=', $op];
|
$where[$field] = ['=', $op];
|
||||||
@ -945,7 +661,7 @@ class Query
|
|||||||
switch (strtolower($op)) {
|
switch (strtolower($op)) {
|
||||||
case 'today':
|
case 'today':
|
||||||
case 'd':
|
case 'd':
|
||||||
$range = ['today', 'tomorrow'];
|
$range = 'today';
|
||||||
break;
|
break;
|
||||||
case 'week':
|
case 'week':
|
||||||
case 'w':
|
case 'w':
|
||||||
@ -971,8 +687,6 @@ class Query
|
|||||||
case 'last year':
|
case 'last year':
|
||||||
$range = [mktime(0, 0, 0, 1, 1, $date['year'] - 1), mktime(0, 0, 0, 1, 1, $date['year'])];
|
$range = [mktime(0, 0, 0, 1, 1, $date['year'] - 1), mktime(0, 0, 0, 1, 1, $date['year'])];
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
$range = $op;
|
|
||||||
}
|
}
|
||||||
$op = is_array($range) ? 'between' : '>';
|
$op = is_array($range) ? 'between' : '>';
|
||||||
}
|
}
|
||||||
@ -993,7 +707,7 @@ class Query
|
|||||||
* list_rows:每页数量
|
* list_rows:每页数量
|
||||||
* type:分页类名,
|
* type:分页类名,
|
||||||
* namespace:分页类命名空间
|
* namespace:分页类命名空间
|
||||||
* @return \think\Paginator
|
* @return \think\paginator\Collection
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
*/
|
*/
|
||||||
public function paginate($listRows = null, $simple = false, $config = [])
|
public function paginate($listRows = null, $simple = false, $config = [])
|
||||||
@ -1034,26 +748,14 @@ class Query
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定当前操作的collection
|
|
||||||
* @access public
|
|
||||||
* @param string $collection
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function collection($collection)
|
|
||||||
{
|
|
||||||
return $this->table($collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询缓存
|
* 查询缓存
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $key 缓存key
|
* @param mixed $key
|
||||||
* @param integer $expire 缓存有效期
|
* @param integer $expire
|
||||||
* @param string $tag 缓存标签
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function cache($key = true, $expire = null, $tag = null)
|
public function cache($key = true, $expire = null)
|
||||||
{
|
{
|
||||||
// 增加快捷调用方式 cache(10) 等同于 cache(true, 10)
|
// 增加快捷调用方式 cache(10) 等同于 cache(true, 10)
|
||||||
if (is_numeric($key) && is_null($expire)) {
|
if (is_numeric($key) && is_null($expire)) {
|
||||||
@ -1061,22 +763,11 @@ class Query
|
|||||||
$key = true;
|
$key = true;
|
||||||
}
|
}
|
||||||
if (false !== $key) {
|
if (false !== $key) {
|
||||||
$this->options['cache'] = ['key' => $key, 'expire' => $expire, 'tag' => $tag];
|
$this->options['cache'] = ['key' => $key, 'expire' => $expire];
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置软删除字段及条件(暂无支持)
|
|
||||||
* @access public
|
|
||||||
* @param false|string $field 查询字段
|
|
||||||
* @param mixed $condition 查询条件
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function useSoftDelete($field, $condition = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不主动获取数据集
|
* 不主动获取数据集
|
||||||
* @access public
|
* @access public
|
||||||
@ -1085,7 +776,19 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function fetchCursor($cursor = true)
|
public function fetchCursor($cursor = true)
|
||||||
{
|
{
|
||||||
$this->options['fetch_cursor'] = $cursor;
|
$this->options['fetch_class'] = $cursor;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定数据集返回对象
|
||||||
|
* @access public
|
||||||
|
* @param string $class 指定返回的数据集对象类名
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function fetchClass($class)
|
||||||
|
{
|
||||||
|
$this->options['fetch_class'] = $class;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1125,7 +828,7 @@ class Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* awaitData
|
* 设置查询数据不存在是否抛出异常
|
||||||
* @access public
|
* @access public
|
||||||
* @param bool $awaitData
|
* @param bool $awaitData
|
||||||
* @return $this
|
* @return $this
|
||||||
@ -1232,18 +935,6 @@ class Query
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* collation
|
|
||||||
* @access public
|
|
||||||
* @param array $collation
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function collation($collation)
|
|
||||||
{
|
|
||||||
$this->options['collation'] = $collation;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置返回字段
|
* 设置返回字段
|
||||||
* @access public
|
* @access public
|
||||||
@ -1300,19 +991,6 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function with($with)
|
public function with($with)
|
||||||
{
|
{
|
||||||
$this->options['with'] = $with;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关联统计
|
|
||||||
* @access public
|
|
||||||
* @param string|array $relation 关联方法名
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function withCount($relation)
|
|
||||||
{
|
|
||||||
$this->options['with_count'] = $relation;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1475,9 +1153,7 @@ class Query
|
|||||||
/**
|
/**
|
||||||
* 插入记录
|
* 插入记录
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $data 数据
|
* @param mixed $data 数据
|
||||||
* @param boolean $replace 是否replace(目前无效)
|
|
||||||
* @param boolean $getLastInsID 返回自增主键
|
|
||||||
* @return WriteResult
|
* @return WriteResult
|
||||||
* @throws AuthenticationException
|
* @throws AuthenticationException
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
@ -1485,33 +1161,18 @@ class Query
|
|||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @throws BulkWriteException
|
* @throws BulkWriteException
|
||||||
*/
|
*/
|
||||||
public function insert(array $data, $replace = null, $getLastInsID = false)
|
public function insert(array $data)
|
||||||
{
|
{
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
throw new Exception('miss data to insert');
|
throw new Exception('miss data to insert');
|
||||||
}
|
}
|
||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
$data = array_merge($options['data'], $data);
|
|
||||||
// 生成bulk对象
|
// 生成bulk对象
|
||||||
$bulk = $this->builder->insert($data, $options);
|
$bulk = $this->builder->insert($data, $options);
|
||||||
$writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : null;
|
$writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : null;
|
||||||
$writeResult = $this->execute($options['table'], $bulk, $writeConcern);
|
$writeResult = $this->execute($options['table'], $bulk, $writeConcern);
|
||||||
$result = $writeResult->getInsertedCount();
|
return $writeResult->getInsertedCount();
|
||||||
if ($result) {
|
|
||||||
$lastInsId = $this->getLastInsID();
|
|
||||||
if ($lastInsId) {
|
|
||||||
$pk = $this->getPk();
|
|
||||||
$data[$pk] = $lastInsId;
|
|
||||||
}
|
|
||||||
$options['data'] = $data;
|
|
||||||
$this->trigger('after_insert', $options);
|
|
||||||
|
|
||||||
if ($getLastInsID) {
|
|
||||||
return $lastInsId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1527,7 +1188,8 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function insertGetId(array $data)
|
public function insertGetId(array $data)
|
||||||
{
|
{
|
||||||
return $this->insert($data, null, true);
|
$this->insert($data);
|
||||||
|
return $this->getLastInsID();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1571,12 +1233,8 @@ class Query
|
|||||||
public function update(array $data)
|
public function update(array $data)
|
||||||
{
|
{
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
$data = array_merge($options['data'], $data);
|
|
||||||
if (isset($options['cache']) && is_string($options['cache']['key'])) {
|
|
||||||
$key = $options['cache']['key'];
|
|
||||||
}
|
|
||||||
$pk = $this->getPk();
|
|
||||||
if (empty($options['where'])) {
|
if (empty($options['where'])) {
|
||||||
|
$pk = $this->getPk();
|
||||||
// 如果存在主键数据 则自动作为更新条件
|
// 如果存在主键数据 则自动作为更新条件
|
||||||
if (is_string($pk) && isset($data[$pk])) {
|
if (is_string($pk) && isset($data[$pk])) {
|
||||||
$where[$pk] = $data[$pk];
|
$where[$pk] = $data[$pk];
|
||||||
@ -1600,8 +1258,6 @@ class Query
|
|||||||
} else {
|
} else {
|
||||||
$options['where']['$and'] = $where;
|
$options['where']['$and'] = $where;
|
||||||
}
|
}
|
||||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['$and'][$pk])) {
|
|
||||||
$key = $this->getCacheKey($options['where']['$and'][$pk], $options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成bulkWrite对象
|
// 生成bulkWrite对象
|
||||||
@ -1613,18 +1269,7 @@ class Query
|
|||||||
// 删除缓存
|
// 删除缓存
|
||||||
Cache::rm($key);
|
Cache::rm($key);
|
||||||
}
|
}
|
||||||
$result = $writeResult->getModifiedCount();
|
return $writeResult->getModifiedCount();
|
||||||
if ($result) {
|
|
||||||
if (isset($where[$pk])) {
|
|
||||||
$data[$pk] = $where[$pk];
|
|
||||||
} elseif (is_string($pk) && isset($key) && strpos($key, '|')) {
|
|
||||||
list($a, $val) = explode('|', $key);
|
|
||||||
$data[$pk] = $val;
|
|
||||||
}
|
|
||||||
$options['data'] = $data;
|
|
||||||
$this->trigger('after_update', $options);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1643,7 +1288,7 @@ class Query
|
|||||||
{
|
{
|
||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
$pk = $this->getPk();
|
|
||||||
if (!is_null($data) && true !== $data) {
|
if (!is_null($data) && true !== $data) {
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
// 缓存标识
|
// 缓存标识
|
||||||
@ -1651,8 +1296,6 @@ class Query
|
|||||||
}
|
}
|
||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['$and'][$pk])) {
|
|
||||||
$key = $this->getCacheKey($options['where']['$and'][$pk], $options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true !== $data && empty($options['where'])) {
|
if (true !== $data && empty($options['where'])) {
|
||||||
@ -1670,33 +1313,7 @@ class Query
|
|||||||
// 删除缓存
|
// 删除缓存
|
||||||
Cache::rm($key);
|
Cache::rm($key);
|
||||||
}
|
}
|
||||||
$result = $writeResult->getDeletedCount();
|
return $writeResult->getDeletedCount();
|
||||||
if ($result) {
|
|
||||||
if (!is_array($data) && is_string($pk) && isset($key) && strpos($key, '|')) {
|
|
||||||
list($a, $val) = explode('|', $key);
|
|
||||||
$item[$pk] = $val;
|
|
||||||
$data = $item;
|
|
||||||
}
|
|
||||||
$options['data'] = $data;
|
|
||||||
$this->trigger('after_delete', $options);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行查询但只返回Cursor对象
|
|
||||||
* @access public
|
|
||||||
* @return Cursor
|
|
||||||
*/
|
|
||||||
public function getCursor()
|
|
||||||
{
|
|
||||||
// 分析查询表达式
|
|
||||||
$options = $this->parseExpress();
|
|
||||||
// 生成MongoQuery对象
|
|
||||||
$query = $this->builder->select($options);
|
|
||||||
// 执行查询操作
|
|
||||||
$readPreference = isset($options['readPreference']) ? $options['readPreference'] : null;
|
|
||||||
return $this->query($options['table'], $query, $readPreference, true, $options['typeMap']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1737,103 +1354,53 @@ class Query
|
|||||||
if (!$resultSet) {
|
if (!$resultSet) {
|
||||||
// 生成MongoQuery对象
|
// 生成MongoQuery对象
|
||||||
$query = $this->builder->select($options);
|
$query = $this->builder->select($options);
|
||||||
|
// 执行查询操作
|
||||||
|
$readPreference = isset($options['readPreference']) ? $options['readPreference'] : null;
|
||||||
|
$resultSet = $this->query($options['table'], $query, $readPreference, $options['fetch_class'], $options['typeMap']);
|
||||||
|
|
||||||
$options['data'] = $data;
|
if ($resultSet instanceof Cursor) {
|
||||||
if ($resultSet = $this->trigger('before_select', $options)) {
|
// 返回MongoDB\Driver\Cursor对象
|
||||||
} else {
|
return $resultSet;
|
||||||
// 执行查询操作
|
|
||||||
$readPreference = isset($options['readPreference']) ? $options['readPreference'] : null;
|
|
||||||
$resultSet = $this->query($options['table'], $query, $readPreference, $options['fetch_cursor'], $options['typeMap']);
|
|
||||||
|
|
||||||
if ($resultSet instanceof Cursor) {
|
|
||||||
// 返回MongoDB\Driver\Cursor对象
|
|
||||||
return $resultSet;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($cache)) {
|
if (isset($cache)) {
|
||||||
// 缓存数据集
|
// 缓存数据集
|
||||||
$this->cacheData($key, $resultSet, $cache);
|
Cache::set($key, $resultSet, $cache['expire']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据列表读取后的处理
|
// 返回结果处理
|
||||||
if (!empty($this->model)) {
|
if ($resultSet) {
|
||||||
// 生成模型对象
|
// 数据列表读取后的处理
|
||||||
$modelName = $this->model;
|
if (!empty($this->model)) {
|
||||||
if (count($resultSet) > 0) {
|
// 生成模型对象
|
||||||
|
$model = $this->model;
|
||||||
foreach ($resultSet as $key => $result) {
|
foreach ($resultSet as $key => $result) {
|
||||||
/** @var Model $result */
|
/** @var Model $result */
|
||||||
$model = new $modelName($result);
|
$result = new $model($result);
|
||||||
$model->isUpdate(true);
|
$result->isUpdate(true);
|
||||||
|
|
||||||
// 关联查询
|
// 关联查询
|
||||||
if (!empty($options['relation'])) {
|
if (!empty($options['relation'])) {
|
||||||
$model->relationQuery($options['relation']);
|
$result->relationQuery($options['relation']);
|
||||||
}
|
}
|
||||||
// 关联统计
|
$resultSet[$key] = $result;
|
||||||
if (!empty($options['with_count'])) {
|
|
||||||
$model->relationCount($model, $options['with_count']);
|
|
||||||
}
|
|
||||||
$resultSet[$key] = $model;
|
|
||||||
}
|
}
|
||||||
if (!empty($options['with'])) {
|
if (!empty($options['with'])) {
|
||||||
// 预载入
|
// 预载入
|
||||||
$model->eagerlyResultSet($resultSet, $options['with']);
|
$resultSet = $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : '');
|
||||||
}
|
}
|
||||||
// 模型数据集转换
|
|
||||||
$resultSet = $model->toCollection($resultSet);
|
|
||||||
} else {
|
|
||||||
$resultSet = (new $modelName)->toCollection($resultSet);
|
|
||||||
}
|
}
|
||||||
} elseif ('collection' == $this->connection->getConfig('resultset_type')) {
|
} elseif (!empty($options['fail'])) {
|
||||||
// 返回Collection对象
|
|
||||||
$resultSet = new Collection($resultSet);
|
|
||||||
}
|
|
||||||
if (!empty($options['fail']) && count($resultSet) == 0) {
|
|
||||||
$this->throwNotFound($options);
|
$this->throwNotFound($options);
|
||||||
}
|
}
|
||||||
return $resultSet;
|
return $resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存数据
|
|
||||||
* @access public
|
|
||||||
* @param string $key 缓存标识
|
|
||||||
* @param mixed $data 缓存数据
|
|
||||||
* @param array $config 缓存参数
|
|
||||||
*/
|
|
||||||
protected function cacheData($key, $data, $config = [])
|
|
||||||
{
|
|
||||||
if (isset($config['tag'])) {
|
|
||||||
Cache::tag($config['tag'])->set($key, $data, $config['expire']);
|
|
||||||
} else {
|
|
||||||
Cache::set($key, $data, $config['expire']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成缓存标识
|
|
||||||
* @access public
|
|
||||||
* @param mixed $value 缓存数据
|
|
||||||
* @param array $options 缓存参数
|
|
||||||
*/
|
|
||||||
protected function getCacheKey($value, $options)
|
|
||||||
{
|
|
||||||
if (is_scalar($value)) {
|
|
||||||
$data = $value;
|
|
||||||
} elseif (is_array($value) && '=' == $value[0]) {
|
|
||||||
$data = $value[1];
|
|
||||||
}
|
|
||||||
if (isset($data)) {
|
|
||||||
return 'mongo:' . $options['table'] . '|' . $data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找单条记录
|
* 查找单条记录
|
||||||
* @access public
|
* @access public
|
||||||
* @param array|string|Query|\Closure $data
|
* @param array|string|Query|\Closure $data
|
||||||
* @return array|null|Cursor|string|Model
|
* @return array|false|Cursor|string|Model
|
||||||
* @throws ModelNotFoundException
|
* @throws ModelNotFoundException
|
||||||
* @throws DataNotFoundException
|
* @throws DataNotFoundException
|
||||||
* @throws AuthenticationException
|
* @throws AuthenticationException
|
||||||
@ -1851,12 +1418,10 @@ class Query
|
|||||||
}
|
}
|
||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
$pk = $this->getPk();
|
|
||||||
if (!is_null($data)) {
|
if (!is_null($data)) {
|
||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
} elseif (!empty($options['cache']) && true === $options['cache']['key'] && is_string($pk) && isset($options['where']['$and'][$pk])) {
|
|
||||||
$key = $this->getCacheKey($options['where']['$and'][$pk], $options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$options['limit'] = 1;
|
$options['limit'] = 1;
|
||||||
@ -1866,69 +1431,52 @@ class Query
|
|||||||
$cache = $options['cache'];
|
$cache = $options['cache'];
|
||||||
if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
|
if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
|
||||||
$key = 'mongo:' . $options['table'] . '|' . $data;
|
$key = 'mongo:' . $options['table'] . '|' . $data;
|
||||||
} elseif (!isset($key)) {
|
} else {
|
||||||
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
||||||
}
|
}
|
||||||
$result = Cache::get($key);
|
$result = Cache::get($key);
|
||||||
}
|
}
|
||||||
if (false === $result) {
|
if (!$result) {
|
||||||
// 生成查询SQL
|
// 生成查询SQL
|
||||||
$query = $this->builder->select($options);
|
$query = $this->builder->select($options);
|
||||||
if (is_string($pk)) {
|
// 执行查询
|
||||||
if (!is_array($data)) {
|
$readPreference = isset($options['readPreference']) ? $options['readPreference'] : null;
|
||||||
if (isset($key) && strpos($key, '|')) {
|
$result = $this->query($options['table'], $query, $readPreference, $options['fetch_class'], $options['typeMap']);
|
||||||
list($a, $val) = explode('|', $key);
|
|
||||||
$item[$pk] = $val;
|
|
||||||
} else {
|
|
||||||
$item[$pk] = $data;
|
|
||||||
}
|
|
||||||
$data = $item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$options['data'] = $data;
|
|
||||||
// 事件回调
|
|
||||||
if ($result = $this->trigger('before_find', $options)) {
|
|
||||||
} else {
|
|
||||||
// 执行查询
|
|
||||||
$readPreference = isset($options['readPreference']) ? $options['readPreference'] : null;
|
|
||||||
$resultSet = $this->query($options['table'], $query, $readPreference, $options['fetch_cursor'], $options['typeMap']);
|
|
||||||
|
|
||||||
if ($resultSet instanceof Cursor) {
|
if ($result instanceof Cursor) {
|
||||||
// 返回MongoDB\Driver\Cursor对象
|
// 返回MongoDB\Driver\Cursor对象
|
||||||
return $resultSet;
|
return $result;
|
||||||
}
|
|
||||||
$result = isset($resultSet[0]) ? $resultSet[0] : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($cache)) {
|
if (isset($cache)) {
|
||||||
// 缓存数据
|
// 缓存数据
|
||||||
$this->cacheData($key, $result, $cache);
|
Cache::set($key, $result, $cache['expire']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据处理
|
// 数据处理
|
||||||
if (!empty($result)) {
|
if (!empty($result[0])) {
|
||||||
|
$data = $result[0];
|
||||||
if (!empty($this->model)) {
|
if (!empty($this->model)) {
|
||||||
// 返回模型对象
|
// 返回模型对象
|
||||||
$model = $this->model;
|
$model = $this->model;
|
||||||
$result = new $model($result);
|
$data = new $model($data);
|
||||||
$result->isUpdate(true, isset($options['where']['$and']) ? $options['where']['$and'] : null);
|
$data->isUpdate(true, isset($options['where']['$and']) ? $options['where']['$and'] : null);
|
||||||
// 关联查询
|
// 关联查询
|
||||||
if (!empty($options['relation'])) {
|
if (!empty($options['relation'])) {
|
||||||
$result->relationQuery($options['relation']);
|
$data->relationQuery($options['relation']);
|
||||||
}
|
}
|
||||||
if (!empty($options['with'])) {
|
if (!empty($options['with'])) {
|
||||||
// 预载入
|
// 预载入
|
||||||
$result->eagerlyResult($result, $options['with']);
|
$data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : '');
|
||||||
}
|
|
||||||
// 关联统计
|
|
||||||
if (!empty($options['with_count'])) {
|
|
||||||
$result->relationCount($result, $options['with_count']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (!empty($options['fail'])) {
|
} elseif (!empty($options['fail'])) {
|
||||||
$this->throwNotFound($options);
|
$this->throwNotFound($options);
|
||||||
|
} else {
|
||||||
|
$data = null;
|
||||||
}
|
}
|
||||||
return $result;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2036,11 +1584,6 @@ class Query
|
|||||||
$guid = md5($tableName);
|
$guid = md5($tableName);
|
||||||
if (!isset(self::$info[$guid])) {
|
if (!isset(self::$info[$guid])) {
|
||||||
$result = $this->table($tableName)->find();
|
$result = $this->table($tableName)->find();
|
||||||
if ($result instanceof Model) {
|
|
||||||
$result = $result->toArray();
|
|
||||||
} elseif (!$result) {
|
|
||||||
$result = [];
|
|
||||||
}
|
|
||||||
$fields = array_keys($result);
|
$fields = array_keys($result);
|
||||||
$type = [];
|
$type = [];
|
||||||
foreach ($result as $key => $val) {
|
foreach ($result as $key => $val) {
|
||||||
@ -2074,10 +1617,8 @@ class Query
|
|||||||
$options['table'] = $this->getTable();
|
$options['table'] = $this->getTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (['where', 'data'] as $name) {
|
if (!isset($options['where'])) {
|
||||||
if (!isset($options[$name])) {
|
$options['where'] = [];
|
||||||
$options[$name] = [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$modifiers = empty($options['modifiers']) ? [] : $options['modifiers'];
|
$modifiers = empty($options['modifiers']) ? [] : $options['modifiers'];
|
||||||
@ -2105,7 +1646,7 @@ class Query
|
|||||||
$options['limit'] = 0;
|
$options['limit'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (['master', 'fetch_cursor'] as $name) {
|
foreach (['master', 'fetch_class'] as $name) {
|
||||||
if (!isset($options[$name])) {
|
if (!isset($options[$name])) {
|
||||||
$options[$name] = false;
|
$options[$name] = false;
|
||||||
}
|
}
|
||||||
@ -2125,33 +1666,4 @@ class Query
|
|||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册回调方法
|
|
||||||
* @access public
|
|
||||||
* @param string $event 事件名
|
|
||||||
* @param callable $callback 回调方法
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function event($event, $callback)
|
|
||||||
{
|
|
||||||
self::$event[$event] = $callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 触发事件
|
|
||||||
* @access protected
|
|
||||||
* @param string $event 事件名
|
|
||||||
* @param mixed $params 额外参数
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function trigger($event, $params = [])
|
|
||||||
{
|
|
||||||
$result = false;
|
|
||||||
if (isset(self::$event[$event])) {
|
|
||||||
$callback = self::$event[$event];
|
|
||||||
$result = call_user_func_array($callback, [$params, $this]);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
11
vendor/topthink/think-queue/README.md
vendored
11
vendor/topthink/think-queue/README.md
vendored
@ -4,18 +4,17 @@
|
|||||||
> composer require topthink/think-queue
|
> composer require topthink/think-queue
|
||||||
|
|
||||||
## 配置
|
## 配置
|
||||||
> 配置文件位于 `application/extra/queue.php`
|
|
||||||
### 公共配置
|
### 公共配置
|
||||||
|
|
||||||
```
|
```
|
||||||
[
|
'queue'=>[
|
||||||
'connector'=>'sync' //驱动类型,可选择 sync(默认):同步执行,database:数据库驱动,redis:Redis驱动,topthink:Topthink驱动
|
'type'=>'sync' //驱动类型,可选择 sync(默认):同步执行,database:数据库驱动,redis:Redis驱动,topthink:Topthink驱动
|
||||||
//或其他自定义的完整的类名
|
//或其他自定义的完整的类名
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
### 驱动配置
|
### 驱动配置
|
||||||
> 各个驱动的具体可用配置项在`think\queue\connector`目录下各个驱动类里的`options`属性中,写在上面的`queue`配置里即可覆盖
|
> 各个驱动的具体可用配置项在`think\queue\driver`目录下各个驱动类里的`options`属性中,写在上面的`queue`配置里即可覆盖
|
||||||
|
|
||||||
|
|
||||||
## 使用 Database
|
## 使用 Database
|
||||||
@ -109,7 +108,7 @@ class Job2{
|
|||||||
|
|
||||||
|
|
||||||
## 发布任务
|
## 发布任务
|
||||||
> `think\Queue::push($job, $data = '', $queue = null)` 和 `think\Queue::later($delay, $job, $data = '', $queue = null)` 两个方法,前者是立即执行,后者是在`$delay`秒后执行
|
> `think\queue\Queue:push($job, $data = '', $queue = null)` 和 `think\queue\Queue::later($delay, $job, $data = '', $queue = null)` 两个方法,前者是立即执行,后者是在`$delay`秒后执行
|
||||||
|
|
||||||
`$job` 是任务名
|
`$job` 是任务名
|
||||||
单模块的,且命名空间是`app\job`的,比如上面的例子一,写`Job1`类名即可
|
单模块的,且命名空间是`app\job`的,比如上面的例子一,写`Job1`类名即可
|
||||||
@ -129,4 +128,4 @@ class Job2{
|
|||||||
|
|
||||||
两种,具体的可选参数可以输入命令加 --help 查看
|
两种,具体的可选参数可以输入命令加 --help 查看
|
||||||
|
|
||||||
>可配合supervisor使用,保证进程常驻
|
>可配合supervisor使用,保证进程常驻
|
18
vendor/topthink/think-queue/composer.json
vendored
18
vendor/topthink/think-queue/composer.json
vendored
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "topthink/think-queue",
|
"name": "topthink/think-queue",
|
||||||
"description": "The ThinkPHP5 Queue Package",
|
"description": "The ThinkPHP5 Queue Package",
|
||||||
"type": "think-extend",
|
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "yunwuxin",
|
"name": "yunwuxin",
|
||||||
@ -9,24 +8,13 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
"minimum-stability": "dev",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"think\\": "src"
|
"think\\queue\\": "src"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/common.php"
|
"src/config.php"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"topthink/think-helper": ">=1.0.4",
|
|
||||||
"topthink/think-installer": ">=1.0.10"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"topthink/framework": "~5.0.0"
|
|
||||||
},
|
|
||||||
"extra": {
|
|
||||||
"think-config": {
|
|
||||||
"queue": "src/config.php"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace think\queue;
|
namespace think\queue;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use think\App;
|
use think\Config;
|
||||||
|
|
||||||
abstract class Job
|
abstract class Job
|
||||||
{
|
{
|
||||||
@ -147,7 +147,7 @@ abstract class Job
|
|||||||
list($module, $name) = explode('/', $name, 2);
|
list($module, $name) = explode('/', $name, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = App::$namespace . ($module ? '\\' . strtolower($module) : '') . '\\job\\' . $name;
|
$name = Config::get('app_namespace') . ($module ? '\\' . strtolower($module) : '') . '\\job\\' . $name;
|
||||||
}
|
}
|
||||||
if (class_exists($name)) {
|
if (class_exists($name)) {
|
||||||
return new $name();
|
return new $name();
|
||||||
@ -210,4 +210,4 @@ abstract class Job
|
|||||||
{
|
{
|
||||||
return $this->queue;
|
return $this->queue;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\queue;
|
namespace think\queue;
|
||||||
|
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use think\Process;
|
use think\Process;
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ class Listener
|
|||||||
$this->handleWorkerOutput($type, $line);
|
$this->handleWorkerOutput($type, $line);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if ($this->memoryExceeded($memory)) {
|
if ($this->memoryExceeded($memory)) {
|
||||||
$this->stop();
|
$this->stop();
|
||||||
}
|
}
|
||||||
@ -161,4 +163,4 @@ class Listener
|
|||||||
{
|
{
|
||||||
$this->maxTries = $tries;
|
$this->maxTries = $tries;
|
||||||
}
|
}
|
||||||
}
|
}
|
84
vendor/topthink/think-queue/src/Queue.php
vendored
84
vendor/topthink/think-queue/src/Queue.php
vendored
@ -9,41 +9,75 @@
|
|||||||
// | Author: yunwuxin <448901948@qq.com>
|
// | Author: yunwuxin <448901948@qq.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think;
|
namespace think\queue;
|
||||||
|
|
||||||
use think\helper\Str;
|
use think\Config;
|
||||||
use think\queue\Connector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Queue
|
|
||||||
* @package think\queue
|
|
||||||
*
|
|
||||||
* @method static push($job, $data = '', $queue = null)
|
|
||||||
* @method static later($delay, $job, $data = '', $queue = null)
|
|
||||||
* @method static pop($queue = null)
|
|
||||||
* @method static marshal()
|
|
||||||
*/
|
|
||||||
class Queue
|
class Queue
|
||||||
{
|
{
|
||||||
/** @var Connector */
|
protected static $instance = [];
|
||||||
protected static $connector;
|
|
||||||
|
|
||||||
private static function buildConnector()
|
/**
|
||||||
|
* 添加任务到队列
|
||||||
|
* @param $job
|
||||||
|
* @param string $data
|
||||||
|
* @param null $queue
|
||||||
|
*/
|
||||||
|
public static function push($job, $data = '', $queue = null)
|
||||||
|
{
|
||||||
|
self::handle()->push($job, $data, $queue);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加延迟任务到队列
|
||||||
|
* @param $delay
|
||||||
|
* @param $job
|
||||||
|
* @param string $data
|
||||||
|
* @param null $queue
|
||||||
|
*/
|
||||||
|
public static function later($delay, $job, $data = '', $queue = null)
|
||||||
|
{
|
||||||
|
self::handle()->later($delay, $job, $data, $queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取第一个任务
|
||||||
|
* @param null $queue
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function pop($queue = null)
|
||||||
|
{
|
||||||
|
if (!method_exists(self::handle(), 'pop'))
|
||||||
|
throw new \RuntimeException('pop queues not support for this type');
|
||||||
|
|
||||||
|
return self::handle()->pop($queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 由订阅的推送执行任务
|
||||||
|
*/
|
||||||
|
public static function marshal()
|
||||||
|
{
|
||||||
|
if (!method_exists(self::handle(), 'marshal'))
|
||||||
|
throw new \RuntimeException('push queues not support for this type');
|
||||||
|
|
||||||
|
self::handle()->marshal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function handle()
|
||||||
{
|
{
|
||||||
$options = Config::get('queue');
|
$options = Config::get('queue');
|
||||||
$type = !empty($options['connector']) ? $options['connector'] : 'Sync';
|
$type = !empty($options['type']) ? $options['type'] : 'Sync';
|
||||||
|
|
||||||
if (!isset(self::$connector)) {
|
if (!isset(self::$instance[$type])) {
|
||||||
|
|
||||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\queue\\connector\\' . Str::studly($type);
|
$class = false !== strpos($type, '\\') ? $type : '\\think\\queue\\driver\\' . ucwords($type);
|
||||||
|
|
||||||
self::$connector = new $class($options);
|
self::$instance[$type] = new $class($options);
|
||||||
}
|
}
|
||||||
return self::$connector;
|
return self::$instance[$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function __callStatic($name, $arguments)
|
}
|
||||||
{
|
|
||||||
return call_user_func_array([self::buildConnector(), $name], $arguments);
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,7 +13,6 @@ namespace think\queue;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use think\Hook;
|
use think\Hook;
|
||||||
use think\Queue;
|
|
||||||
|
|
||||||
class Worker
|
class Worker
|
||||||
{
|
{
|
||||||
@ -32,11 +31,9 @@ class Worker
|
|||||||
$job = $this->getNextJob($queue);
|
$job = $this->getNextJob($queue);
|
||||||
|
|
||||||
if (!is_null($job)) {
|
if (!is_null($job)) {
|
||||||
Hook::listen('worker_before_process', $queue);
|
|
||||||
return $this->process($job, $maxTries, $delay);
|
return $this->process($job, $maxTries, $delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::listen('worker_before_sleep', $queue);
|
|
||||||
$this->sleep($sleep);
|
$this->sleep($sleep);
|
||||||
|
|
||||||
return ['job' => null, 'failed' => false];
|
return ['job' => null, 'failed' => false];
|
||||||
@ -94,13 +91,9 @@ class Worker
|
|||||||
*/
|
*/
|
||||||
protected function logFailedJob(Job $job)
|
protected function logFailedJob(Job $job)
|
||||||
{
|
{
|
||||||
if (!$job->isDeleted()) {
|
if (Hook::listen('queue.failed', $job, null, true)) {
|
||||||
try {
|
$job->delete();
|
||||||
$job->delete();
|
$job->failed();
|
||||||
$job->failed();
|
|
||||||
} finally {
|
|
||||||
Hook::listen('queue_failed', $job);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['job' => $job, 'failed' => true];
|
return ['job' => $job, 'failed' => true];
|
||||||
@ -116,4 +109,4 @@ class Worker
|
|||||||
sleep($seconds);
|
sleep($seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\queue\command;
|
namespace think\queue\command;
|
||||||
|
|
||||||
|
|
||||||
use think\console\Command;
|
use think\console\Command;
|
||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
use think\console\input\Option;
|
use think\console\input\Option;
|
||||||
@ -36,7 +37,7 @@ class Listen extends Command
|
|||||||
|
|
||||||
public function initialize(Input $input, Output $output)
|
public function initialize(Input $input, Output $output)
|
||||||
{
|
{
|
||||||
$this->listener = new Listener($this->findCommandPath());
|
$this->listener = new Listener(getcwd());
|
||||||
$this->listener->setSleep($input->getOption('sleep'));
|
$this->listener->setSleep($input->getOption('sleep'));
|
||||||
$this->listener->setMaxTries($input->getOption('tries'));
|
$this->listener->setMaxTries($input->getOption('tries'));
|
||||||
|
|
||||||
@ -57,9 +58,4 @@ class Listen extends Command
|
|||||||
|
|
||||||
$this->listener->listen($queue, $delay, $memory, $timeout);
|
$this->listener->listen($queue, $delay, $memory, $timeout);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
protected function findCommandPath()
|
|
||||||
{
|
|
||||||
return defined('ROOT_PATH') ? ROOT_PATH : dirname($_SERVER['argv'][0]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\queue\command;
|
namespace think\queue\command;
|
||||||
|
|
||||||
|
|
||||||
use think\Cache;
|
use think\Cache;
|
||||||
use think\console\Command;
|
use think\console\Command;
|
||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
@ -28,4 +29,4 @@ class Restart extends Command
|
|||||||
Cache::set('think:queue:restart', time());
|
Cache::set('think:queue:restart', time());
|
||||||
$output->writeln("<info>Broadcasting queue restart signal.</info>");
|
$output->writeln("<info>Broadcasting queue restart signal.</info>");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ use think\console\Input;
|
|||||||
use think\console\input\Argument;
|
use think\console\input\Argument;
|
||||||
use think\console\input\Option;
|
use think\console\input\Option;
|
||||||
use think\console\Output;
|
use think\console\Output;
|
||||||
use think\Queue;
|
use think\queue\Queue;
|
||||||
use think\Url;
|
use think\Url;
|
||||||
|
|
||||||
class Subscribe extends Command
|
class Subscribe extends Command
|
||||||
@ -43,4 +43,4 @@ class Subscribe extends Command
|
|||||||
|
|
||||||
$output->write('<info>Queue subscriber added:</info> <comment>' . $input->getArgument('url') . '</comment>');
|
$output->write('<info>Queue subscriber added:</info> <comment>' . $input->getArgument('url') . '</comment>');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,6 @@ use think\console\Command;
|
|||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
use think\console\input\Option;
|
use think\console\input\Option;
|
||||||
use think\console\Output;
|
use think\console\Output;
|
||||||
use think\Hook;
|
|
||||||
use think\queue\Job;
|
use think\queue\Job;
|
||||||
use think\queue\Worker;
|
use think\queue\Worker;
|
||||||
use Exception;
|
use Exception;
|
||||||
@ -66,7 +65,6 @@ class Work extends Command
|
|||||||
$memory = $input->getOption('memory');
|
$memory = $input->getOption('memory');
|
||||||
|
|
||||||
if ($input->getOption('daemon')) {
|
if ($input->getOption('daemon')) {
|
||||||
Hook::listen('worker_daemon_start', $queue);
|
|
||||||
$this->daemon(
|
$this->daemon(
|
||||||
$queue, $delay, $memory,
|
$queue, $delay, $memory,
|
||||||
$input->getOption('sleep'), $input->getOption('tries')
|
$input->getOption('sleep'), $input->getOption('tries')
|
||||||
@ -109,13 +107,7 @@ class Work extends Command
|
|||||||
$queue, $delay, $sleep, $maxTries
|
$queue, $delay, $sleep, $maxTries
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $this->memoryExceeded($memory) ) {
|
if ($this->memoryExceeded($memory) || $this->queueShouldRestart($lastRestart)) {
|
||||||
Hook::listen('worker_memory_exceeded', $queue);
|
|
||||||
$this->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this->queueShouldRestart($lastRestart) ) {
|
|
||||||
Hook::listen('worker_queue_restart', $queue);
|
|
||||||
$this->stop();
|
$this->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,4 +199,4 @@ class Work extends Command
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
36
vendor/topthink/think-queue/src/common.php
vendored
36
vendor/topthink/think-queue/src/common.php
vendored
@ -1,36 +0,0 @@
|
|||||||
<?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>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
\think\Console::addDefaultCommands([
|
|
||||||
"think\\queue\\command\\Work",
|
|
||||||
"think\\queue\\command\\Restart",
|
|
||||||
"think\\queue\\command\\Listen",
|
|
||||||
"think\\queue\\command\\Subscribe"
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!function_exists('queue')) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加到队列
|
|
||||||
* @param $job
|
|
||||||
* @param string $data
|
|
||||||
* @param int $delay
|
|
||||||
* @param null $queue
|
|
||||||
*/
|
|
||||||
function queue($job, $data = '', $delay = 0, $queue = null)
|
|
||||||
{
|
|
||||||
if ($delay > 0) {
|
|
||||||
\think\Queue::later($delay, $job, $data, $queue);
|
|
||||||
} else {
|
|
||||||
\think\Queue::push($job, $data, $queue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
11
vendor/topthink/think-queue/src/config.php
vendored
11
vendor/topthink/think-queue/src/config.php
vendored
@ -2,13 +2,16 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: yunwuxin <448901948@qq.com>
|
// | Author: yunwuxin <448901948@qq.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
return [
|
\think\Console::addDefaultCommands([
|
||||||
'connector' => 'Sync'
|
"think\\queue\\command\\Work",
|
||||||
];
|
"think\\queue\\command\\Restart",
|
||||||
|
"think\\queue\\command\\Listen",
|
||||||
|
"think\\queue\\command\\Subscribe"
|
||||||
|
]);
|
@ -9,13 +9,12 @@
|
|||||||
// | Author: yunwuxin <448901948@qq.com>
|
// | Author: yunwuxin <448901948@qq.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think\queue\connector;
|
namespace think\queue\driver;
|
||||||
|
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use think\queue\Connector;
|
|
||||||
use think\queue\job\Database as DatabaseJob;
|
use think\queue\job\Database as DatabaseJob;
|
||||||
|
|
||||||
class Database extends Connector
|
class Database
|
||||||
{
|
{
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
@ -45,6 +44,12 @@ class Database extends Connector
|
|||||||
return $this->pushToDatabase($delay, $queue, $this->createPayload($job, $data));
|
return $this->pushToDatabase($delay, $queue, $this->createPayload($job, $data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function createPayload($job, $data)
|
||||||
|
{
|
||||||
|
return json_encode(['job' => $job, 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
public function pop($queue = null)
|
public function pop($queue = null)
|
||||||
{
|
{
|
||||||
$queue = $this->getQueue($queue);
|
$queue = $this->getQueue($queue);
|
||||||
@ -116,7 +121,7 @@ class Database extends Connector
|
|||||||
->order('id', 'asc')
|
->order('id', 'asc')
|
||||||
->find();
|
->find();
|
||||||
|
|
||||||
return $job ? (object) $job : null;
|
return $job ? (object)$job : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,7 +155,7 @@ class Database extends Connector
|
|||||||
->update([
|
->update([
|
||||||
'reserved' => 0,
|
'reserved' => 0,
|
||||||
'reserved_at' => null,
|
'reserved_at' => null,
|
||||||
'attempts' => ['inc', 1]
|
'attempts' => ['exp', 'attempts + 1']
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,4 +173,4 @@ class Database extends Connector
|
|||||||
{
|
{
|
||||||
return $queue ?: $this->options['default'];
|
return $queue ?: $this->options['default'];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,14 +9,13 @@
|
|||||||
// | Author: yunwuxin <448901948@qq.com>
|
// | Author: yunwuxin <448901948@qq.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think\queue\connector;
|
namespace think\queue\driver;
|
||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use think\helper\Str;
|
|
||||||
use think\queue\Connector;
|
|
||||||
use think\queue\job\Redis as RedisJob;
|
use think\queue\job\Redis as RedisJob;
|
||||||
|
|
||||||
class Redis extends Connector
|
class Redis
|
||||||
{
|
{
|
||||||
/** @var \Redis */
|
/** @var \Redis */
|
||||||
protected $redis;
|
protected $redis;
|
||||||
@ -48,7 +47,7 @@ class Redis extends Connector
|
|||||||
if ('' != $this->options['password']) {
|
if ('' != $this->options['password']) {
|
||||||
$this->redis->auth($this->options['password']);
|
$this->redis->auth($this->options['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != $this->options['select']) {
|
if (0 != $this->options['select']) {
|
||||||
$this->redis->select($this->options['select']);
|
$this->redis->select($this->options['select']);
|
||||||
}
|
}
|
||||||
@ -72,10 +71,8 @@ class Redis extends Connector
|
|||||||
|
|
||||||
$queue = $this->getQueue($queue);
|
$queue = $this->getQueue($queue);
|
||||||
|
|
||||||
$this->migrateExpiredJobs($queue . ':delayed', $queue, false);
|
|
||||||
|
|
||||||
if (!is_null($this->options['expire'])) {
|
if (!is_null($this->options['expire'])) {
|
||||||
$this->migrateExpiredJobs($queue . ':reserved', $queue);
|
$this->migrateAllExpiredJobs($queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
$job = $this->redis->lPop($queue);
|
$job = $this->redis->lPop($queue);
|
||||||
@ -110,11 +107,12 @@ class Redis extends Connector
|
|||||||
return json_decode($payload, true)['id'];
|
return json_decode($payload, true)['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createPayload($job, $data = '', $queue = null)
|
|
||||||
|
protected function createPayload($job, $data)
|
||||||
{
|
{
|
||||||
$payload = $this->setMeta(
|
$payload = json_encode(['job' => $job, 'data' => $data]);
|
||||||
parent::createPayload($job, $data), 'id', $this->getRandomId()
|
|
||||||
);
|
$payload = $this->setMeta($payload, 'id', $this->getRandomId());
|
||||||
|
|
||||||
return $this->setMeta($payload, 'attempts', 1);
|
return $this->setMeta($payload, 'attempts', 1);
|
||||||
}
|
}
|
||||||
@ -131,6 +129,19 @@ class Redis extends Connector
|
|||||||
$this->redis->zRem($this->getQueue($queue) . ':reserved', $job);
|
$this->redis->zRem($this->getQueue($queue) . ':reserved', $job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移动所有任务
|
||||||
|
*
|
||||||
|
* @param string $queue
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function migrateAllExpiredJobs($queue)
|
||||||
|
{
|
||||||
|
$this->migrateExpiredJobs($queue . ':delayed', $queue, false);
|
||||||
|
|
||||||
|
$this->migrateExpiredJobs($queue . ':reserved', $queue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移动延迟任务
|
* 移动延迟任务
|
||||||
*
|
*
|
||||||
@ -171,6 +182,7 @@ class Redis extends Connector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有到期任务
|
* 获取所有到期任务
|
||||||
*
|
*
|
||||||
@ -183,6 +195,7 @@ class Redis extends Connector
|
|||||||
return $this->redis->zRangeByScore($from, '-inf', $time);
|
return $this->redis->zRangeByScore($from, '-inf', $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除过期任务
|
* 删除过期任务
|
||||||
*
|
*
|
||||||
@ -220,7 +233,14 @@ class Redis extends Connector
|
|||||||
*/
|
*/
|
||||||
protected function getRandomId()
|
protected function getRandomId()
|
||||||
{
|
{
|
||||||
return Str::random(32);
|
return uniqid();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setMeta($payload, $key, $value)
|
||||||
|
{
|
||||||
|
$payload = json_decode($payload, true);
|
||||||
|
$payload[$key] = $value;
|
||||||
|
return json_encode($payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -9,14 +9,13 @@
|
|||||||
// | Author: yunwuxin <448901948@qq.com>
|
// | Author: yunwuxin <448901948@qq.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think\queue\connector;
|
namespace think\queue\driver;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use think\queue\Connector;
|
|
||||||
use think\queue\job\Sync as SyncJob;
|
use think\queue\job\Sync as SyncJob;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Sync extends Connector
|
class Sync
|
||||||
{
|
{
|
||||||
|
|
||||||
public function push($job, $data = '', $queue = null)
|
public function push($job, $data = '', $queue = null)
|
||||||
@ -54,4 +53,8 @@ class Sync extends Connector
|
|||||||
return new SyncJob($payload);
|
return new SyncJob($payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
protected function createPayload($job, $data = '', $queue = null)
|
||||||
|
{
|
||||||
|
return json_encode(['job' => $job, 'data' => $data]);
|
||||||
|
}
|
||||||
|
}
|
@ -9,15 +9,14 @@
|
|||||||
// | Author: yunwuxin <448901948@qq.com>
|
// | Author: yunwuxin <448901948@qq.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think\queue\connector;
|
namespace think\queue\driver;
|
||||||
|
|
||||||
use think\exception\HttpException;
|
use think\exception\HttpException;
|
||||||
use think\queue\Connector;
|
|
||||||
use think\Request;
|
use think\Request;
|
||||||
use think\queue\job\Topthink as TopthinkJob;
|
use think\queue\job\Topthink as TopthinkJob;
|
||||||
use think\Response;
|
use think\Response;
|
||||||
|
|
||||||
class Topthink extends Connector
|
class Topthink
|
||||||
{
|
{
|
||||||
protected $options = [
|
protected $options = [
|
||||||
'token' => '',
|
'token' => '',
|
||||||
@ -170,7 +169,7 @@ class Topthink extends Connector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->reportHttpError($this->last_status, "Service unavailable");
|
$this->reportHttpError($this->last_status, "Service unavailable");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function jsonDecode($response)
|
protected static function jsonDecode($response)
|
||||||
@ -196,6 +195,11 @@ class Topthink extends Connector
|
|||||||
throw new HttpException($status, "http error: {$status} | {$text}");
|
throw new HttpException($status, "http error: {$status} | {$text}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function createPayload($job, $data = '')
|
||||||
|
{
|
||||||
|
return json_encode(['job' => $job, 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marshal out the pushed job and payload.
|
* Marshal out the pushed job and payload.
|
||||||
*
|
*
|
||||||
@ -210,6 +214,11 @@ class Topthink extends Connector
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getQueue($queue)
|
||||||
|
{
|
||||||
|
return $queue ?: $this->options['default'];
|
||||||
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
if ($this->curl != null) {
|
if ($this->curl != null) {
|
||||||
@ -217,9 +226,4 @@ class Topthink extends Connector
|
|||||||
$this->curl = null;
|
$this->curl = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function pop($queue = null)
|
|
||||||
{
|
|
||||||
throw new \RuntimeException('pop queues not support for this type');
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@
|
|||||||
namespace think\queue\job;
|
namespace think\queue\job;
|
||||||
|
|
||||||
use think\queue\Job;
|
use think\queue\Job;
|
||||||
use think\queue\connector\Database as DatabaseQueue;
|
use think\queue\driver\Database as DatabaseQueue;
|
||||||
|
|
||||||
class Database extends Job
|
class Database extends Job
|
||||||
{
|
{
|
||||||
@ -74,7 +74,7 @@ class Database extends Job
|
|||||||
*/
|
*/
|
||||||
public function attempts()
|
public function attempts()
|
||||||
{
|
{
|
||||||
return (int) $this->job->attempts;
|
return (int)$this->job->attempts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,4 +85,4 @@ class Database extends Job
|
|||||||
{
|
{
|
||||||
return $this->job->payload;
|
return $this->job->payload;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,12 +11,14 @@
|
|||||||
|
|
||||||
namespace think\queue\job;
|
namespace think\queue\job;
|
||||||
|
|
||||||
|
|
||||||
use think\queue\Job;
|
use think\queue\Job;
|
||||||
use think\queue\connector\Redis as RedisQueue;
|
use think\queue\driver\Redis as RedisQueue;
|
||||||
|
|
||||||
class Redis extends Job
|
class Redis extends Job
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The redis queue instance.
|
* The redis queue instance.
|
||||||
* @var RedisQueue
|
* @var RedisQueue
|
||||||
@ -63,6 +65,7 @@ class Redis extends Job
|
|||||||
return $this->job;
|
return $this->job;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除任务
|
* 删除任务
|
||||||
*
|
*
|
||||||
@ -89,4 +92,4 @@ class Redis extends Job
|
|||||||
|
|
||||||
$this->redis->release($this->queue, $this->job, $delay, $this->attempts() + 1);
|
$this->redis->release($this->queue, $this->job, $delay, $this->attempts() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\queue\job;
|
namespace think\queue\job;
|
||||||
|
|
||||||
|
|
||||||
use think\queue\Job;
|
use think\queue\Job;
|
||||||
|
|
||||||
class Sync extends Job
|
class Sync extends Job
|
||||||
@ -53,4 +54,4 @@ class Sync extends Job
|
|||||||
{
|
{
|
||||||
return $this->payload;
|
return $this->payload;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
namespace think\queue\job;
|
namespace think\queue\job;
|
||||||
|
|
||||||
|
|
||||||
use think\queue\Job;
|
use think\queue\Job;
|
||||||
use think\queue\connector\Topthink as TopthinkQueue;
|
use think\queue\driver\Topthink as TopthinkQueue;
|
||||||
|
|
||||||
class Topthink extends Job
|
class Topthink extends Job
|
||||||
{
|
{
|
||||||
@ -54,7 +55,7 @@ class Topthink extends Job
|
|||||||
*/
|
*/
|
||||||
public function attempts()
|
public function attempts()
|
||||||
{
|
{
|
||||||
return (int) $this->job->attempts;
|
return (int)$this->job->attempts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
@ -82,4 +83,4 @@ class Topthink extends Job
|
|||||||
return $this->job->payload;
|
return $this->job->payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,36 +0,0 @@
|
|||||||
<?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>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace think\queue;
|
|
||||||
|
|
||||||
class CallQueuedHandler
|
|
||||||
{
|
|
||||||
|
|
||||||
public function call(Job $job, array $data)
|
|
||||||
{
|
|
||||||
$command = unserialize($data['command']);
|
|
||||||
|
|
||||||
call_user_func([$command, 'handle']);
|
|
||||||
|
|
||||||
if (!$job->isDeletedOrReleased()) {
|
|
||||||
$job->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function failed(array $data)
|
|
||||||
{
|
|
||||||
$command = unserialize($data['command']);
|
|
||||||
|
|
||||||
if (method_exists($command, 'failed')) {
|
|
||||||
$command->failed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
<?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>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace think\queue;
|
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
abstract class Connector
|
|
||||||
{
|
|
||||||
protected $options = [];
|
|
||||||
|
|
||||||
abstract public function push($job, $data = '', $queue = null);
|
|
||||||
|
|
||||||
abstract public function later($delay, $job, $data = '', $queue = null);
|
|
||||||
|
|
||||||
abstract public function pop($queue = null);
|
|
||||||
|
|
||||||
public function marshal()
|
|
||||||
{
|
|
||||||
throw new \RuntimeException('pop queues not support for this type');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createPayload($job, $data = '', $queue = null)
|
|
||||||
{
|
|
||||||
if (is_object($job)) {
|
|
||||||
$payload = json_encode([
|
|
||||||
'job' => 'think\queue\CallQueuedHandler@call',
|
|
||||||
'data' => [
|
|
||||||
'commandName' => get_class($job),
|
|
||||||
'command' => serialize(clone $job),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$payload = json_encode($this->createPlainPayload($job, $data));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
|
||||||
throw new InvalidArgumentException('Unable to create payload: ' . json_last_error_msg());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createPlainPayload($job, $data)
|
|
||||||
{
|
|
||||||
return ['job' => $job, 'data' => $data];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setMeta($payload, $key, $value)
|
|
||||||
{
|
|
||||||
$payload = json_decode($payload, true);
|
|
||||||
$payload[$key] = $value;
|
|
||||||
$payload = json_encode($payload);
|
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
|
||||||
throw new InvalidArgumentException('Unable to create payload: ' . json_last_error_msg());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $payload;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
<?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>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace think\queue;
|
|
||||||
|
|
||||||
trait Queueable
|
|
||||||
{
|
|
||||||
|
|
||||||
/** @var string 队列名称 */
|
|
||||||
public $queue;
|
|
||||||
|
|
||||||
/** @var integer 延迟时间 */
|
|
||||||
public $delay;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置队列名
|
|
||||||
* @param $queue
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function queue($queue)
|
|
||||||
{
|
|
||||||
$this->queue = $queue;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置延迟时间
|
|
||||||
* @param $delay
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function delay($delay)
|
|
||||||
{
|
|
||||||
$this->delay = $delay;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
<?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>
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace think\queue;
|
|
||||||
|
|
||||||
interface ShouldQueue
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user