diff --git a/app/common/controller/BaseController.php b/app/common/controller/BaseController.php index cbd5604..2e414b3 100644 --- a/app/common/controller/BaseController.php +++ b/app/common/controller/BaseController.php @@ -16,7 +16,6 @@ use think\facade\Request; use think\facade\View; use think\facade\Db; use think\facade\Session; -use think\facade\Cache; use app\BaseController as BaseCtrl; /** @@ -62,28 +61,28 @@ class BaseController extends BaseCtrl private function setUid() { if(Session::has('user_id')) { - $this->uid = Session::get('user_id'); + $this->uid = Session::get('user_id') ?? -1; } } private function setUser() { if(Session::has('user_id')) { - $this->uid = Session::get('user_id'); + $this->uid = Session::get('user_id') ?? -1; } } // 显示子导航subnav protected function showSubnav() { + $subCateList = []; // 没有点击任何分类,点击首页获取全部分类信息 //1.查询父分类id $pCate = Db::name('cate')->field('id,pid,ename,catename,is_hot')->where(['ename'=>input('ename'),'status'=>1,'delete_time'=>0])->find(); - if(empty($pCate)) { // 没有点击任何分类,点击首页获取全部分类信息 - $subCateList = []; - } else { // 点击分类,获取子分类信息 + if(!is_null($pCate)) { // 点击分类,获取子分类信息 $parentId = $pCate['id']; $subCate = Db::name('cate')->field('id,ename,catename,is_hot,pid')->where(['pid'=>$parentId,'status'=>1,'delete_time'=>0])->select()->toArray(); + if(!empty($subCate)) { // 有子分类 $subCateList = array2tree($subCate); } else { //无子分类 @@ -106,16 +105,13 @@ class BaseController extends BaseCtrl //显示当前登录用户 protected function showUser($id) { - $user = Cache::get('user'.$id); - if(!$user){ - //1.查询用户 - $user = Db::name('user') - ->alias('u') - ->join('user_viprule v','v.vip = u.vip') - ->field('u.id as id,v.id as vid,name,nickname,user_img,sex,area_id,auth,city,phone,email,active,sign,point,u.vip as vip,nick,u.create_time as cteate_time') - ->find($id); - Cache::tag('user')->set('user'.$id, $user, 600); - } + if($id == -1) return []; + //1.查询用户 + $user = Db::name('user') + ->alias('u') + ->join('user_viprule v','v.vip = u.vip') + ->field('u.id as id,v.id as vid,name,nickname,user_img,sex,area_id,auth,city,phone,email,active,sign,point,u.vip as vip,nick,u.create_time as create_time') + ->find((int)$id); return $user; } diff --git a/app/common/lib/SqlFile.php b/app/common/lib/SqlFile.php index c843ae2..9f111bd 100644 --- a/app/common/lib/SqlFile.php +++ b/app/common/lib/SqlFile.php @@ -2,11 +2,11 @@ /* * @Author: TaoLer <317927823@qq.com> * @Date: 2021-12-06 16:04:50 - * @LastEditTime: 2022-08-16 14:16:40 + * @LastEditTime: 2024-04-12 19:32:40 * @LastEditors: TaoLer * @Description: 优化版 * @FilePath: \TaoLer\app\common\lib\SqlFile.php - * Copyright (c) 2020~2022 https://www.aieok.com All rights reserved. + * Copyright (c) 2020~2024 https://www.aieok.com All rights reserved. */ declare (strict_types = 1); @@ -84,6 +84,9 @@ class SqlFile if (file_exists($sqlFile)) { $sqlArr = self::loadSqlFile($sqlFile); if(!empty($sqlArr)) { + $orginal = 'tao_'; //sql默认表前缀 + $prefix = config('database.mysql.prefix'); // 现在表前缀 + ($orginal == $prefix) ? true : $sqlArr = str_replace(" `{$orginal}", " `{$prefix}", $sqlArr); //替换数组中表前缀 foreach($sqlArr as $v){ try { Db::execute($v); diff --git a/app/common/model/Article.php b/app/common/model/Article.php index 5d4739e..db89579 100644 --- a/app/common/model/Article.php +++ b/app/common/model/Article.php @@ -110,10 +110,10 @@ class Article extends Model */ public function getArtTop(int $num) { - return Cache::remember('topArticle', function() use($num){ + $topIdArr = $this::where(['is_top' => 1, 'status' => 1])->limit($num)->column('id'); return $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,pv,upzip,has_img,has_video,has_audio,read_type') - ->where(['is_top' => 1, 'status' => 1]) + ->where('id', 'in', $topIdArr) ->with([ 'cate' => function (Query $query) { $query->where('delete_time', 0)->field('id,catename,ename'); @@ -122,8 +122,7 @@ class Article extends Model $query->field('id,name,nickname,user_img'); } ])->withCount(['comments']) - ->order('create_time', 'desc') - ->limit($num) + ->order('id', 'desc') ->append(['url']) ->select() ->toArray(); @@ -151,8 +150,9 @@ class Article extends Model } ]) ->withCount(['comments']) ->where('status', '=', 1) - ->order('create_time','desc') + ->order('id','desc') ->limit($num) + ->hidden(['art_pass']) ->append(['url']) ->select(); @@ -163,7 +163,7 @@ class Article extends Model /** * 热点文章 - * @param int $num 热点列表数量 + * @param int $num 热点列表数量 评论或者pv排序 * @return \think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException @@ -171,17 +171,48 @@ class Article extends Model */ public function getArtHot(int $num) { - $artHot = $this::field('id,cate_id,title,create_time') - ->withCount('comments') - ->where(['status' => 1]) - ->whereMonth('create_time') - ->order('comments_count','desc') - ->limit($num) - ->withCache(600) - ->append(['url']) - ->select(); + return Cache::remember('article_hot', function() use($num){ + $comments = Comment::field('article_id,count(*) as count') + ->where('comment.delete_time',0) + ->hasWhere('article',['status' =>1, 'delete_time' => 0]) + ->group('article_id') + ->order('count','desc') + ->limit($num) + ->select(); + $idArr = []; + foreach($comments as $v) { + $idArr[] = $v->article_id; + } + $where = []; + if(count($idArr)) { + // 评论数 + $where = [ + ['id', 'in', $idArr] + ]; - return $artHot; + $artHot = $this::field('id,cate_id,title,create_time') + ->withCount('comments') + ->where($where) + //->whereYear('create_time') + // ->order('comments_count','desc') + ->append(['url']) + ->select(); + } else { + // pv数 + $where = [ + ['status', '=', 1] + ]; + $artHot = $this::field('id,cate_id,title,create_time') + ->withCount('comments') + ->where($where) + ->whereMonth('create_time') + ->order('pv','desc') + ->limit($num) + ->append(['url']) + ->select(); + } + return $artHot; + }, 3600); } /** @@ -223,12 +254,6 @@ class Article extends Model */ public function getCateList(string $ename, string $type, int $page = 1) { - $where = []; - $cateId = Cate::where('ename',$ename)->value('id'); - if($cateId){ - $where[] = ['cate_id' ,'=', $cateId]; - } - switch ($type) { //查询文章,15个分1页 case 'jie': @@ -244,10 +269,28 @@ class Article extends Model $where[] = ['jie','=', 0]; break; } + $where[] = ['status', '=', 1]; - return Cache::remember('cate_list_'.$ename.$type.$page, function() use($where,$page){ - return $this::field('id,cate_id,user_id,title,content,title_color,create_time,is_top,is_hot,pv,jie,upzip,has_img,has_video,has_audio,read_type,art_pass') + return Cache::remember('cate_list_'.$ename.$type.$page, function() use($where,$ename,$page){ + $cateId = Cate::where('ename',$ename)->value('id'); + if($cateId){ + $where[] = ['cate_id' ,'=', $cateId]; + } + + $list = $this::field('id')->where($where)->order(['id'=>'desc'])->paginate([ + 'list_rows' => 15, + 'page' => $page + ])->toArray(); + + $idArr = []; + if($list['total'] > 0) { + foreach($list['data'] as $v) { + $idArr[] = $v['id']; + } + } + + $data = $this::field('id,cate_id,user_id,title,content,title_color,create_time,is_top,is_hot,pv,jie,upzip,has_img,has_video,has_audio,read_type,art_pass') ->with([ 'cate' => function($query) { $query->field('id,catename,ename'); @@ -256,13 +299,19 @@ class Article extends Model $query->field('id,name,nickname,user_img,vip'); } ])->withCount(['comments']) - ->where($where) - ->limit(15) - ->order(['create_time'=>'desc']) - ->paginate([ - 'list_rows' => 15, - 'page' => $page - ])->append(['url'])->toArray(); + ->where('id','in',$idArr) + ->order(['id'=>'desc']) + ->append(['url']) + ->hidden(['art_pass']) + ->select() + ->toArray(); + return [ + 'total' => $list['total'], + 'per_page' => $list['per_page'], + 'current_page' => $list['current_page'], + 'last_page' => $list['last_page'], + 'data' => $data + ]; }, 600); } @@ -273,7 +322,7 @@ class Article extends Model $query->where(['delete_time'=>0,'status'=>1])->field('id,ename'); }]) ->where(['user_id' => $id,'status' => 1]) - ->order(['create_time'=>'desc']) + ->order('id','desc') ->append(['url']) ->limit(25) ->cache(3600) @@ -296,7 +345,7 @@ class Article extends Model $map[] = ['title','like','%'.$keywords.'%']; $res = Article::where($map) ->withCount('comments') - ->order('create_time','desc') + ->order('id','desc') ->append(['url']) ->paginate(10); @@ -363,23 +412,33 @@ class Article extends Model * @param [type] $cid 当前分类ID * @return void|array */ - public function getPrevNextArticle($id,$cid) + public function getPrevNextArticle($id, $cid) { //上一篇 - $previous = $this::field('id,title,cate_id') - ->where([ - ['id', '<', $id], + $pIds = $this::where([ + ['id', '>=', $id], // >= <= 条件可以使用索引 ['cate_id', '=', $cid], ['status', '=',1] - ])->order('id desc')->limit(1)->append(['url'])->select()->toArray(); + ])->order('id asc')->limit(2)->column('id'); + if(count($pIds) === 2) { + $previous = $this::field('id,title,cate_id')->append(['url'])->find($pIds[1])->toArray(); + } else { + $previous = []; + } + //下一篇 - $next = $this::field('id,title,cate_id') - ->where([ - ['id', '>', $id], + $nids = $this::where([ + ['id', '<=', $id], ['cate_id', '=', $cid], ['status', '=',1] - ])->order('id asc')->limit(1)->append(['url'])->select()->toArray(); + ])->order('id desc')->limit(2)->column('id'); + + if(count($nids) === 2) { + $next = $this::field('id,title,cate_id')->append(['url'])->find($nids[1])->toArray(); + } else { + $next = []; + } return ['previous' => $previous, 'next' => $next]; } @@ -398,7 +457,7 @@ class Article extends Model ]) ->where(['status' => 1]) ->where($where) - ->order('create_time', 'desc') + ->order('id', 'desc') ->paginate([ 'list_rows' => $limit, 'page' => $page @@ -418,7 +477,7 @@ class Article extends Model } ]) ->where($where) - ->order('create_time', 'desc') + ->order('id', 'desc') ->paginate([ 'list_rows' => $limit, 'page' => $page diff --git a/app/common/model/Cate.php b/app/common/model/Cate.php index 5a25eeb..d655ee2 100644 --- a/app/common/model/Cate.php +++ b/app/common/model/Cate.php @@ -63,12 +63,12 @@ class Cate extends Model public function del($id) { $cates = $this->field('id,pid')->with('article')->find($id); - $sonCate = $this->field('id,pid')->where('pid',$cates['id'])->find(); - if(empty($sonCate)) { - $res = $cates->together(['article'])->delete(); - return $res ? 1 : '删除失败'; + $sonCate = $this::where('pid',$cates['id'])->count(); + if($sonCate > 0) { + return '存在子分类,无法删除'; } - return '存在子分类,无法删除'; + $res = $cates->together(['article'])->delete(); + return $res ? 1 : '删除失败'; } // 分类表 @@ -121,11 +121,11 @@ class Cate extends Model public function getUrlAttr($value,$data) { // 栏目下存在帖子,则返回正常url,否则为死链 - $articleArr = Article::field('id')->where('cate_id', $data['id'])->find(); - if(empty($articleArr)) { - return 'javascript:void(0);'; + $articleCount = Article::where('cate_id', $data['id'])->count(); + if($articleCount > 0) { + return (string) url('cate',['ename' => $data['ename']]); } - return (string) url('cate',['ename' => $data['ename']]);; + return 'javascript:void(0);'; } diff --git a/app/common/model/MessageTo.php b/app/common/model/MessageTo.php index cf4738c..e264a1b 100644 --- a/app/common/model/MessageTo.php +++ b/app/common/model/MessageTo.php @@ -33,12 +33,11 @@ class MessageTo extends Model //得到消息数 public function getMsgNum($id) { - $msg = $this::where(['receve_id'=>$id,'is_read'=>0])->column('id'); - if($num = count($msg)) { - return $num; - } else { - return 0; + $msgNum = $this::where(['receve_id'=>$id,'is_read'=>0])->count('id'); + if($msgNum) { + return $msgNum; } + return 0; } diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index e00ad97..6b2f3f1 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -50,6 +50,7 @@ class Article extends BaseController //分类列表 $artList = $this->model->getCateList($ename,$type,$page); + // halt($artList); // 热议文章 $artHot = $this->model->getArtHot(10); @@ -118,15 +119,15 @@ class Article extends BaseController //上一篇下一篇 $upDownArt = $this->model->getPrevNextArticle($id,$artDetail['cate_id']); - if(empty($upDownArt['previous'][0])) { + if(empty($upDownArt['previous'])) { $previous = '前面已经没有了!'; } else { - $previous = ''; + $previous = ''; } - if(empty($upDownArt['next'][0])) { + if(empty($upDownArt['next'])) { $next = '已经是最新的内容了!'; } else { - $next = ''; + $next = ''; } //评论 @@ -440,7 +441,7 @@ class Article extends BaseController */ public function delete() { - $article = $this->model->find(input('id')); + $article = $this->model->find((int)input('id')); $result = $article->together(['comments'])->delete(); if($result) { return Msgres::success('delete_success'); diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 1b36cb4..fa14c81 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -11,7 +11,6 @@ namespace app\index\controller; use app\common\controller\BaseController; -use app\common\lib\facade\HttpHelper; use think\facade\View; use think\facade\Request; use think\facade\Db; @@ -32,6 +31,22 @@ class Index extends BaseController */ public function index() { + + // $res = get_addons_info('callme1'); +// halt($res); + // $htmlString = "

这是一个链接和其他文本。

"; + // $cleanString = preg_replace("/]*>(.*?)<\/a>/is", "", $htmlString); + // //$cleanString = preg_replace("(]*>|)","",$htmlString); + // echo $cleanString; + + // $ip = file_get_contents('https://myip.ipip.net'); + // echo "My public IP address is: " . $ip; + // $alipay = AlipayFactory::createPayMethod(); + // $weixin = WeixinFactory::createPayMethod(); + // $a = $alipay->index(); + // $b= $weixin->index(); + // var_dump($a,$b); + $types = input('type'); //置顶文章 $artTop = Article::getArtTop(5); diff --git a/app/index/controller/Message.php b/app/index/controller/Message.php index d4ea961..9640860 100644 --- a/app/index/controller/Message.php +++ b/app/index/controller/Message.php @@ -11,7 +11,6 @@ namespace app\index\controller; use app\common\controller\BaseController; -use think\facade\Session; use think\facade\Request; use think\facade\Db; use app\common\model\Message as MessageModel; @@ -25,12 +24,8 @@ class Message extends BaseController { $messgeto = new MessageTo(); $num = $messgeto->getMsgNum($this->uid); - if($num){ - $res = ['status' =>0,'count' => $num, 'msg' => 'ok']; - } else { - $res = ['status' =>0,'count' => 0, 'msg' => 'no message']; - } - return json($res); + if($num) return json(['status' =>0,'count' => $num, 'msg' => 'ok']); + return json(['status' =>0,'count' => 0, 'msg' => 'no message']); } //消息查询 @@ -82,18 +77,20 @@ class Message extends BaseController $uid = $this->uid; $id = Request::only(['id']); + if($id['id'] == 'true'){ - //删除所有此用户消息 - $msg = Db::name('message_to')->where(['receve_id'=>$uid,'delete_time'=>0])->useSoftDelete('delete_time',time())->delete(); + // id为'true' 删除所有此用户消息 + $msg = Db::name('message_to')->where(['receve_id' => $uid])->delete(); } else { //删除单条消息 - $msg = Db::name('message_to')->where('id',$id['id'])->useSoftDelete('delete_time',time())->delete(); + $msg = Db::name('message_to')->where('id', $id['id'])->delete(); } if($msg){ $res = ['status'=>0]; + return $res; } - return $res; + } diff --git a/app/index/controller/User.php b/app/index/controller/User.php index 9e4af32..0e46263 100644 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -301,11 +301,8 @@ class User extends BaseController public function home($id) { //用户 - $u = Cache::get('user'.$id); - if(!$u){ - $u = Db::name('user')->field('name,nickname,city,sex,sign,user_img,point,vip,create_time')->cache(3600)->find($id); - } - + $u = Db::name('user')->field('name,nickname,city,sex,sign,user_img,point,vip,create_time')->find($id); + $article = new Article(); $arts = $article->getUserArtList((int) $id); @@ -320,7 +317,7 @@ class User extends BaseController ->field('a.id,a.title,t.ename,c.content,c.create_time,c.delete_time,c.status') ->where(['a.delete_time'=>0,'c.delete_time'=>0,'c.status'=>1]) ->where('c.user_id',$id) - ->order(['c.create_time'=>'desc']) + ->order(['c.id'=>'desc']) ->limit(10) ->cache(3600)->select(); diff --git a/app/install/data/taoler.sql b/app/install/data/taoler.sql index e611f55..ab73084 100644 --- a/app/install/data/taoler.sql +++ b/app/install/data/taoler.sql @@ -430,7 +430,8 @@ CREATE TABLE `tao_message_to` ( `create_time` int NOT NULL DEFAULT 0 COMMENT '创建时间', `update_time` int NOT NULL DEFAULT 0 COMMENT '更新时间', `delete_time` int NOT NULL DEFAULT 0 COMMENT '删除时间', - PRIMARY KEY (`id`) USING BTREE + PRIMARY KEY (`id`) USING BTREE, + INDEX `idx_mesto_receveid`(`receve_id`) USING BTREE COMMENT '收件人ID' ) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '消息详细表' ROW_FORMAT = Dynamic; -- ---------------------------- diff --git a/composer.lock b/composer.lock index e193c8e..65fe03c 100644 --- a/composer.lock +++ b/composer.lock @@ -799,16 +799,16 @@ }, { "name": "jaeger/querylist", - "version": "V4.2.8", + "version": "V4.2.9", "source": { "type": "git", "url": "https://github.com/jae-jae/QueryList.git", - "reference": "39dc0ca9c668bec7a793e20472ccd7d26ef89ea4" + "reference": "7aae3aed38214d3d7096174faf49f6c41b2dd550" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jae-jae/QueryList/zipball/39dc0ca9c668bec7a793e20472ccd7d26ef89ea4", - "reference": "39dc0ca9c668bec7a793e20472ccd7d26ef89ea4", + "url": "https://api.github.com/repos/jae-jae/QueryList/zipball/7aae3aed38214d3d7096174faf49f6c41b2dd550", + "reference": "7aae3aed38214d3d7096174faf49f6c41b2dd550", "shasum": "" }, "require": { @@ -816,11 +816,10 @@ "jaeger/g-http": "^1.1", "jaeger/phpquery-single": "^1", "php": ">=7.1", - "tightenco/collect": ">5.0" + "symfony/var-dumper": ">3.4" }, "require-dev": { - "phpunit/phpunit": "^8.5", - "symfony/var-dumper": "^3.3" + "phpunit/phpunit": "^8.5" }, "type": "library", "autoload": { @@ -847,7 +846,7 @@ ], "support": { "issues": "https://github.com/jae-jae/QueryList/issues", - "source": "https://github.com/jae-jae/QueryList/tree/V4.2.8" + "source": "https://github.com/jae-jae/QueryList/tree/V4.2.9" }, "funding": [ { @@ -855,7 +854,7 @@ "type": "open_collective" } ], - "time": "2021-07-05T06:07:58+00:00" + "time": "2024-04-12T06:29:50+00:00" }, { "name": "laravel/serializable-closure", @@ -2404,61 +2403,6 @@ }, "time": "2022-04-16T23:08:43+00:00" }, - { - "name": "tightenco/collect", - "version": "v8.83.27", - "source": { - "type": "git", - "url": "https://github.com/tighten/collect.git", - "reference": "07eed6cf7441c7a69c379fdcb118eec1a1fdd0e6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/tighten/collect/zipball/07eed6cf7441c7a69c379fdcb118eec1a1fdd0e6", - "reference": "07eed6cf7441c7a69c379fdcb118eec1a1fdd0e6", - "shasum": "" - }, - "require": { - "php": "^7.3|^8.0", - "symfony/var-dumper": "^3.4 || ^4.0 || ^5.0 || ^6.0" - }, - "require-dev": { - "mockery/mockery": "^1.0", - "nesbot/carbon": "^2.23.0", - "phpunit/phpunit": "^8.3" - }, - "type": "library", - "autoload": { - "files": [ - "src/Collect/Support/helpers.php", - "src/Collect/Support/alias.php" - ], - "psr-4": { - "Tightenco\\Collect\\": "src/Collect" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" - } - ], - "description": "Collect - Illuminate Collections as a separate package.", - "keywords": [ - "collection", - "laravel" - ], - "support": { - "issues": "https://github.com/tighten/collect/issues", - "source": "https://github.com/tighten/collect/tree/v8.83.27" - }, - "abandoned": "illuminate/collections", - "time": "2023-01-13T18:05:42+00:00" - }, { "name": "topthink/framework", "version": "v6.1.4", diff --git a/config/taoler.php b/config/taoler.php index e0b5f84..f73a77e 100644 --- a/config/taoler.php +++ b/config/taoler.php @@ -16,7 +16,7 @@ return [ // 应用名,此项不可更改 'appname' => 'TaoLer', // 版本配置 - 'version' => '2.5.5', + 'version' => '2.5.6', // 加盐 'salt' => 'taoler', // 数据库备份目录 diff --git a/public/static/res/css/global.css b/public/static/res/css/global.css index 2657d74..de73aca 100644 --- a/public/static/res/css/global.css +++ b/public/static/res/css/global.css @@ -434,7 +434,6 @@ body .layui-edit-face .layui-layer-content{padding:0; background-color:#fff; co .jie-row li i, .jie-row li em, .jie-row li cite{font-size:12px; color:#999; font-style: normal;} .jie-row li .mine-edit{margin-left:15px; padding:0 6px; background-color: #8FCDA0; color:#fff; font-size:12px;} .jie-row li em{position:absolute; right:0; top:0;} -.jie-row li .jie-user{} .jie-row li .jie-title{max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;} .jie-row li .jie-user img{position:relative; top: 16px; width: 35px; height: 35px;} @@ -792,7 +791,7 @@ p { margin: 0; white-space: normal; word-break: break-all; - -webkit-user-select: none; + /* -webkit-user-select: none; */ } code[class*="language-"], pre[class*="language-"] { diff --git a/public/static/res/mods/index.js b/public/static/res/mods/index.js index a93bcf8..9792c33 100644 --- a/public/static/res/mods/index.js +++ b/public/static/res/mods/index.js @@ -1,21 +1,16 @@ /** TaoLer社区修改 www.aieok.com @Name: Fly社区主入口 - 2021-5.21 + 2024-4.7 */ -layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util', 'imgcom'], function(exports){ +layui.define(['layer', 'form', 'util'], function(exports){ var $ = layui.jquery ,layer = layui.layer - ,laytpl = layui.laytpl ,form = layui.form - ,element = layui.element - ,upload = layui.upload ,util = layui.util - ,imgcom = layui.imgcom ,device = layui.device() - ,DISABLED = 'layui-btn-disabled'; var uid = layui.cache.user.uid; var login = $('.fly-nav-user').attr('userlogin'); @@ -93,522 +88,13 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util', 'imgcom'], ,form: {} - //简易编辑器 - ,layEditor: function(options){ - var html = ['
' - ,'' - ,'' - ,'' - ,'' - ,'' - ,'' - ,'' - ,'' - ,'hr' - ,'' - ,'
'].join(''); + //简易编辑器 -移除 -2024/4/7 - var closeTips = function(){ - layer.close(mod.face.index); - }; - - var log = {}, mod = { - //加粗 - strong: function(editor){ - var str = window.getSelection().toString(); - if(!str == ''){ - //var strB = ''+ str + ''; - layui.focusInsert(editor[0], '[strong]'+ str + '[/strong]'); - //console.log(str); - // console.log(strB); - } - }, - face: function(editor, self){ //插入表情 - var str = '', ul, face = fly.faces; - for(var key in face){ - str += '
  • '; - } - str = ''; - - layer.close(mod.face.index); - mod.face.index = layer.tips(str, self, { - tips: 3 - ,time: 0 - ,skin: 'layui-edit-face' - ,tipsMore: true - }); - - $(document).off('click', closeTips).on('click', closeTips); - - $('#LAY-editface li').on('click', function(){ - var title = $(this).attr('title') + ' '; - layui.focusInsert(editor[0], 'face' + title); - editor.trigger('keyup'); - }); - } - ,picture: function(editor){ //插入图片 - //判断登陆 - if(uid == -1){ - layer.msg('请登录再发图', {icon: 6}, function(){ - location.href = login; - }) - return false; - } - - layer.open({ - type: 1 - ,id: 'fly-jie-upload' - ,title: '插入图片' - ,area: 'auto' - ,shade: false - //,area: '465px' - ,fixed: false - ,offset: [ - editor.offset().top - $(window).scrollTop() + 'px' - ,editor.offset().left + 'px' - ] - ,skin: 'layui-layer-border' - ,content: [''].join('') - ,success: function(layero, index){ - var image = layero.find('input[name="image"]'); - - //执行上传实例 - upload.render({ - elem: '#uploadImg' - ,accept: 'images' - ,acceptMime: 'image/*' - ,exts: 'jpg|png|gif|bmp|jpeg' - ,url: uploads - ,data: {type:'image'} - ,auto: false - //,bindAction: '#img-button' //指向一个按钮触发上传 - //,field: 'image' - ,size: 10240 - ,choose: function (obj) { //选择文件后的回调 - imgcom.uploads(obj); - } - ,done: function(res){ - if(res.status == 0){ - //console.log(res.url); - image.val(res.url); - } else { - layer.msg(res.msg, {icon: 5}); - } - } - ,error: function(){ - layer.msg('系统错误,请联系管理员'); - } - }); - - form.on('submit(uploadImages)', function(data){ - var field = data.field; - if(!field.image) return image.focus(); - layui.focusInsert(editor[0], 'img['+ field.image + '] '); - layer.close(index); - editor.trigger('keyup'); - }); - } - }); - } - ,href: function(editor){ //超链接 - layer.prompt({ - title: '请输入合法链接' - ,shade: false - ,fixed: false - ,id: 'LAY_flyedit_href' - ,offset: [ - editor.offset().top - $(window).scrollTop() + 1 + 'px' - ,editor.offset().left + 1 + 'px' - ] - }, function(val, index, elem){ - if(!/^http(s*):\/\/[\S]/.test(val)){ - layer.tips('请务必 http 或 https 开头', elem, {tips:1}) - return; - } - layui.focusInsert(editor[0], ' a('+ val +')['+ val + '] '); - layer.close(index); - editor.trigger('keyup'); - }); - } - ,quote: function(editor){ //引用 - layer.prompt({ - title: '请输入引用内容' - ,formType: 2 - ,maxlength: 10000 - ,shade: false - ,id: 'LAY_flyedit_quote' - ,offset: [ - editor.offset().top - $(window).scrollTop() + 1 + 'px' - ,editor.offset().left + 1 + 'px' - ] - ,area: ['300px', '100px'] - }, function(val, index, elem){ - layui.focusInsert(editor[0], '[quote]\n '+ val + '\n[/quote]\n'); - layer.close(index); - editor.trigger('keyup'); - }); - } - ,code: function(editor){ //插入代码 - layer.prompt({ - title: '请贴入代码' - ,formType: 2 - ,maxlength: 10000 - ,shade: false - ,id: 'LAY_flyedit_code' - ,area: ['800px', '360px'] - }, function(val, index, elem){ - layui.focusInsert(editor[0], '[pre]\n'+ val + '\n[/pre]\n'); - layer.close(index); - editor.trigger('keyup'); - }); - } - ,hr: function(editor){ //插入水平分割线 - layui.focusInsert(editor[0], '[hr]\n'); - editor.trigger('keyup'); - } - ,video: function(editor){ //插入视频 - //判断登陆 - if(uid == -1){ - layer.msg('请登录再发视频', {icon: 6}, function(){ - location.href = login; - }) - return false; - } - layer.open({ - type: 1 - ,id: 'fly-jie-video-upload' - ,title: '插入视频' - ,area: 'auto' - ,shade: false - //,area: '465px' - ,fixed: false - ,offset: [ - editor.offset().top - $(window).scrollTop() + 'px' - ,editor.offset().left + 'px' - ] - ,skin: 'layui-layer-border' - ,content: [''].join('') - ,success: function(layero, index){ - var video = layero.find('input[name="video"]'), cover = layero.find('input[name="cover"]'); - - //上传视频 - upload.render({ - url: uploads - ,data: {type:'video'} - ,accept: 'video' - ,acceptMime: 'video/mp4' - ,exts: 'mp4' - ,elem: '#layedit-video' - ,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。 - layer.load(2); //上传loading - } - ,done: function(res){ - if(res.status == 0){ - video.val(res.url); - } else { - layer.msg(res.msg, {icon: 5}); - } - layer.closeAll('loading'); - } - }); - //上传图片 - upload.render({ - elem: '#video-img' - ,accept: 'images' - ,acceptMime: 'image/*' - ,exts: 'jpg|png|gif|bmp|jpeg' - ,url: uploads - ,data: {type:'image'} - ,auto: false - //,bindAction: '#img-button' //指向一个按钮触发上传 - //,field: 'image' - ,size: 10240 - ,choose: function (obj) { //选择文件后的回调 - imgcom.uploads(obj); - } - ,done: function(res){ - if(res.status == 0){ - cover.val(res.url); - } else { - layer.msg(res.msg, {icon: 5}); - } - } - ,error: function(){ - layer.msg('系统错误,请联系管理员'); - } - }); - form.on('submit(uploadImages)', function(data){ - var field = data.field; - if(!field.video) return video.focus(); - layui.focusInsert(editor[0], 'video('+field.cover+')['+ field.video + '] '); - layer.close(index); - }); - } - }); - } - ,audio: function(editor){ //插入音频 - //判断登陆 - if(uid == -1){ - layer.msg('请登录再发布', {icon: 6}, function(){ - location.href = login; - }) - return false; - } - layer.open({ - type: 1 - ,id: 'fly-jie-audio-upload' - ,title: '插入音频' - ,area: 'auto' - ,shade: false - //,area: '465px' - ,fixed: false - ,offset: [ - editor.offset().top - $(window).scrollTop() + 'px' - ,editor.offset().left + 'px' - ] - ,skin: 'layui-layer-border' - ,content: [''].join('') - ,success: function(layero, index){ - var loding,audio = layero.find('input[name="audio"]'); - - upload.render({ - url: uploads - ,data: {type:'audio'} - ,elem: '#fly-jie-audio-upload .upload-audio' - ,accept: 'audio' - ,acceptMime: 'audio/*' - ,exts: 'mp3|m4a' - ,before: function(obj){ - //loding = layer.msg('文件上传中,请稍等哦', { icon: 16 ,shade:0.3,time:0 }); - layer.load(2); //上传loading - } - ,done: function(res){ - - if(res.status == 0){ - audio.val(res.url); - } else { - layer.msg(res.msg, {icon: 5}); - } - layer.closeAll('loading'); - } - }); - form.on('submit(uploadImages)', function(data){ - var field = data.field; - if(!field.audio) return audio.focus(); - layui.focusInsert(editor[0], 'audio['+ field.audio + '] '); - layer.close(index); - }); - } - }); - } - ,preview: function(editor, span){ //预览 - var othis = $(span), getContent = function(){ - var content = editor.val(); - return /^\{html\}/.test(content) ? content.replace(/^\{html\}/, '') : fly.content(content) - }, isMobile = device.ios || device.android; - - if(mod.preview.isOpen) return layer.close(mod.preview.index); - - mod.preview.index = layer.open({ - type: 1 - ,title: '预览' - ,shade: false - ,offset: 'r' - ,id: 'LAY_flyedit_preview' - ,area: [ - isMobile ? '100%' : '775px' - ,'100%' - ] - ,scrollbar: isMobile ? false : true - ,anim: -1 - ,isOutAnim: false - ,content: '
    '+ getContent() +'
    ' - ,success: function(layero){ - editor.on('keyup', function(val){ - layero.find('.detail-body').html(getContent()); - }); - mod.preview.isOpen = true; - othis.addClass('layui-this'); - } - ,end: function(){ - delete mod.preview.isOpen; - othis.removeClass('layui-this'); - } - }); - } -}; - - layui.use('face', function(face){ - options = options || {}; - fly.faces = face; - $(options.elem).each(function(index){ - var that = this, othis = $(that), parent = othis.parent(); - parent.prepend(html); - parent.find('.fly-edit span').on('click', function(event){ - var type = $(this).attr('type'); - mod[type].call(that, othis, this); - if(type === 'face'){ - event.stopPropagation() - } - }); - }); - }); - - } - - ,escape: function(html){ - return String(html||'').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&') - .replace(//g, '>').replace(/'/g, ''').replace(/"/g, '"'); - } - - //内容转义 - ,content: function(content){ - var util = fly - ,item = fly.faces; - - //支持的html标签 - var html = function(end){ - return new RegExp('\\n*\\|\\-'+ (end||'') +'(div|span|p|button|table|thead|th|tbody|tr|td|ul|li|ol|li|dl|dt|dd|h2|h3|h4|h5)([\\s\\S]*?)\\-\\|\\n*', 'g'); - }; - - - //XSS - content = util.escape(content||'') - - //转义图片 - .replace(/img\[([^\s]+?)\]/g, function(img){ - return '
    '; - }) - - //转义@ - .replace(/@(\S+)(\s+?|$)/g, '@$1$2') - - //转义表情 - .replace(/face\[([^\s\[\]]+?)\]/g, function(face){ - var alt = face.replace(/^face/g, ''); - return ''+ alt +''; - }) - - //转义脚本 - .replace(/a(\(javascript:)(.+)(;*\))/g, 'a(javascript:layer.msg(\'非法脚本\');)') - - //转义链接 - .replace(/a\([\s\S]+?\)\[[\s\S]*?\]/g, function(str){ - var href = (str.match(/a\(([\s\S]+?)\)\[/)||[])[1]; - var text = (str.match(/\)\[([\s\S]*?)\]/)||[])[1]; - if(!href) return str; - var rel = /^(http(s)*:\/\/)\b(?!(\w+\.)*(sentsin.com|layui.com))\b/.test(href.replace(/\s/g, '')); - return ''+ (text||href) +''; - }) - - //转义横线 - .replace(/\[hr\]\n*/g, '
    ') - - //转义表格 - .replace(/\[table\]([\s\S]*)\[\/table\]\n*/g, function(str){ - return str.replace(/\[(thead|th|tbody|tr|td)\]\n*/g, '<$1>') - .replace(/\n*\[\/(thead|th|tbody|tr|td)\]\n*/g, '') - - .replace(/\[table\]\n*/g, '') - .replace(/\n*\[\/table\]\n*/g, '
    '); - }) - - //转义 div/span - .replace(/\n*\[(div|span)([\s\S]*?)\]([\s\S]*?)\[\/(div|span)\]\n*/g, function(str){ - return str.replace(/\[(div|span)([\s\S]*?)\]\n*/g, '<$1 $2>') - .replace(/\n*\[\/(div|span)\]\n*/g, ''); - }) - - //转义列表 - .replace(/\[ul\]([\s\S]*)\[\/ul\]\n*/g, function(str){ - return str.replace(/\[li\]\n*/g, '
  • ') - .replace(/\n*\[\/li\]\n*/g, '
  • ') - - .replace(/\[ul\]\n*/g, ''); - }) - - //转义代码 - .replace(/\[pre\]([\s\S]*)\[\/pre\]\n*/g, function(str){ - return str.replace(/\[pre\]\n*/g, '
    ')
    -                    .replace(/\n*\[\/pre\]\n*/g, '
    '); - }) - - //转义引用 - .replace(/\[quote\]([\s\S]*)\[\/quote\]\n*/g, function(str){ - return str.replace(/\[quote\]\n*/g, '
    ') - .replace(/\n*\[\/quote\]\n*/g, '
    '); - }) - - //转义加粗 - .replace(/\[strong\]([\s\S]*)\[\/strong\]\n*/g, function(str){ - return str.replace(/\[strong\]\n*/g,'') - .replace(/\n*\[\/strong\]\n*/g, ''); - }) - - //转义换行 - .replace(/\n/g, '
    ') - - //转义视频 - .replace(/video\(.*?\)\[([^\s]+?)\]/g, function(str){ - var cover = (str.match(/video\(([\s\S]+?)\)\[/)||[])[1]; - var video = (str.match(/\)\[([^\s]+?)\]/)||[])[1]; - cover = cover ? cover : '/static/res/images/video_cover.jpg'; - return ''; - }) - //转义音频 - .replace(/audio\[([^\s]+?)\]/g, function(audio){ - return ''; - }) - - return content; - } - //新消息通知 ,newmsg: function(){ var elemUser = $('.fly-nav-user'); - var messageNums = elemUser.attr('msg-url'), - messageRead = elemUser.attr('readMsg-url'); + var messageNums = elemUser.attr('msg-url'); + var messageRead = elemUser.attr('readMsg-url'); if(uid != -1 && elemUser[0]){ fly.json(messageNums, { _: new Date().getTime() @@ -813,9 +299,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util', 'imgcom'], } //加载编辑器 - // fly.layEditor({ - // elem: '.fly-editor' - // }); + //手机设备的简单适配 用户中心底部左侧栏导航 var treeMobile = $('.site-tree-mobile') diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php index 24f86d2..805d730 100644 --- a/vendor/composer/autoload_files.php +++ b/vendor/composer/autoload_files.php @@ -11,13 +11,11 @@ return array( '7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php', 'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php', 'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php', - 'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', + 'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', '25072dd6e2470089de65ae7bf11d3109' => $vendorDir . '/symfony/polyfill-php72/bootstrap.php', '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php', - 'fe62ba7e10580d903cc46d808b5961a4' => $vendorDir . '/tightenco/collect/src/Collect/Support/helpers.php', - 'caf31cc6ec7cf2241cb6f12c226c3846' => $vendorDir . '/tightenco/collect/src/Collect/Support/alias.php', '6b998e7ad3182c0d21d23780badfa07b' => $vendorDir . '/yansongda/supports/src/Functions.php', 'b33e3d135e5d9e47d845c576147bda89' => $vendorDir . '/php-di/php-di/src/functions.php', '223fa6f9b46fbe5d6b44c5ff847bfceb' => $vendorDir . '/taoser/think-addons/src/helper.php', diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index a7b402e..29ab455 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -21,7 +21,6 @@ return array( 'Yansongda\\Supports\\' => array($vendorDir . '/yansongda/supports/src'), 'Yansongda\\Pay\\' => array($vendorDir . '/yansongda/pay/src'), 'Workerman\\' => array($vendorDir . '/workerman/workerman'), - 'Tightenco\\Collect\\' => array($vendorDir . '/tightenco/collect/src/Collect'), 'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'), 'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index b974c2b..e5d50d4 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -12,13 +12,11 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2 '7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php', 'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php', 'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php', - 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', + 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', '25072dd6e2470089de65ae7bf11d3109' => __DIR__ . '/..' . '/symfony/polyfill-php72/bootstrap.php', '667aeda72477189d0494fecd327c3641' => __DIR__ . '/..' . '/symfony/var-dumper/Resources/functions/dump.php', - 'fe62ba7e10580d903cc46d808b5961a4' => __DIR__ . '/..' . '/tightenco/collect/src/Collect/Support/helpers.php', - 'caf31cc6ec7cf2241cb6f12c226c3846' => __DIR__ . '/..' . '/tightenco/collect/src/Collect/Support/alias.php', '6b998e7ad3182c0d21d23780badfa07b' => __DIR__ . '/..' . '/yansongda/supports/src/Functions.php', 'b33e3d135e5d9e47d845c576147bda89' => __DIR__ . '/..' . '/php-di/php-di/src/functions.php', '223fa6f9b46fbe5d6b44c5ff847bfceb' => __DIR__ . '/..' . '/taoser/think-addons/src/helper.php', @@ -61,10 +59,6 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2 array ( 'Workerman\\' => 10, ), - 'T' => - array ( - 'Tightenco\\Collect\\' => 18, - ), 'S' => array ( 'Symfony\\Polyfill\\Php80\\' => 23, @@ -206,10 +200,6 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2 array ( 0 => __DIR__ . '/..' . '/workerman/workerman', ), - 'Tightenco\\Collect\\' => - array ( - 0 => __DIR__ . '/..' . '/tightenco/collect/src/Collect', - ), 'Symfony\\Polyfill\\Php80\\' => array ( 0 => __DIR__ . '/..' . '/symfony/polyfill-php80', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 21ad9ff..444eb68 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -847,17 +847,17 @@ }, { "name": "jaeger/querylist", - "version": "V4.2.8", - "version_normalized": "4.2.8.0", + "version": "V4.2.9", + "version_normalized": "4.2.9.0", "source": { "type": "git", "url": "https://github.com/jae-jae/QueryList.git", - "reference": "39dc0ca9c668bec7a793e20472ccd7d26ef89ea4" + "reference": "7aae3aed38214d3d7096174faf49f6c41b2dd550" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jae-jae/QueryList/zipball/39dc0ca9c668bec7a793e20472ccd7d26ef89ea4", - "reference": "39dc0ca9c668bec7a793e20472ccd7d26ef89ea4", + "url": "https://api.github.com/repos/jae-jae/QueryList/zipball/7aae3aed38214d3d7096174faf49f6c41b2dd550", + "reference": "7aae3aed38214d3d7096174faf49f6c41b2dd550", "shasum": "" }, "require": { @@ -865,13 +865,12 @@ "jaeger/g-http": "^1.1", "jaeger/phpquery-single": "^1", "php": ">=7.1", - "tightenco/collect": ">5.0" + "symfony/var-dumper": ">3.4" }, "require-dev": { - "phpunit/phpunit": "^8.5", - "symfony/var-dumper": "^3.3" + "phpunit/phpunit": "^8.5" }, - "time": "2021-07-05T06:07:58+00:00", + "time": "2024-04-12T06:29:50+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -898,7 +897,7 @@ ], "support": { "issues": "https://github.com/jae-jae/QueryList/issues", - "source": "https://github.com/jae-jae/QueryList/tree/V4.2.8" + "source": "https://github.com/jae-jae/QueryList/tree/V4.2.9" }, "funding": [ { @@ -2578,69 +2577,6 @@ }, "install-path": "../taoser/think-setarr" }, - { - "name": "tightenco/collect", - "version": "v8.83.27", - "version_normalized": "8.83.27.0", - "source": { - "type": "git", - "url": "https://github.com/tighten/collect.git", - "reference": "07eed6cf7441c7a69c379fdcb118eec1a1fdd0e6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/tighten/collect/zipball/07eed6cf7441c7a69c379fdcb118eec1a1fdd0e6", - "reference": "07eed6cf7441c7a69c379fdcb118eec1a1fdd0e6", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, - "require": { - "php": "^7.3|^8.0", - "symfony/var-dumper": "^3.4 || ^4.0 || ^5.0 || ^6.0" - }, - "require-dev": { - "mockery/mockery": "^1.0", - "nesbot/carbon": "^2.23.0", - "phpunit/phpunit": "^8.3" - }, - "time": "2023-01-13T18:05:42+00:00", - "type": "library", - "installation-source": "dist", - "autoload": { - "files": [ - "src/Collect/Support/helpers.php", - "src/Collect/Support/alias.php" - ], - "psr-4": { - "Tightenco\\Collect\\": "src/Collect" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" - } - ], - "description": "Collect - Illuminate Collections as a separate package.", - "keywords": [ - "collection", - "laravel" - ], - "support": { - "issues": "https://github.com/tighten/collect/issues", - "source": "https://github.com/tighten/collect/tree/v8.83.27" - }, - "install-path": "../tightenco/collect" - }, { "name": "topthink/framework", "version": "v6.1.4", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index ac1fbfd..20a1d3e 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'taoser/taoler', 'pretty_version' => '2.3.10.x-dev', 'version' => '2.3.10.9999999-dev', - 'reference' => '2e95b716720018a27230c873200926631e74e781', + 'reference' => '158340e85a56ec3bd70563cef0bf1491468d7370', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -119,9 +119,9 @@ 'dev_requirement' => false, ), 'jaeger/querylist' => array( - 'pretty_version' => 'V4.2.8', - 'version' => '4.2.8.0', - 'reference' => '39dc0ca9c668bec7a793e20472ccd7d26ef89ea4', + 'pretty_version' => 'V4.2.9', + 'version' => '4.2.9.0', + 'reference' => '7aae3aed38214d3d7096174faf49f6c41b2dd550', 'type' => 'library', 'install_path' => __DIR__ . '/../jaeger/querylist', 'aliases' => array(), @@ -358,7 +358,7 @@ 'taoser/taoler' => array( 'pretty_version' => '2.3.10.x-dev', 'version' => '2.3.10.9999999-dev', - 'reference' => '2e95b716720018a27230c873200926631e74e781', + 'reference' => '158340e85a56ec3bd70563cef0bf1491468d7370', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -391,15 +391,6 @@ 'aliases' => array(), 'dev_requirement' => false, ), - 'tightenco/collect' => array( - 'pretty_version' => 'v8.83.27', - 'version' => '8.83.27.0', - 'reference' => '07eed6cf7441c7a69c379fdcb118eec1a1fdd0e6', - 'type' => 'library', - 'install_path' => __DIR__ . '/../tightenco/collect', - 'aliases' => array(), - 'dev_requirement' => false, - ), 'topthink/framework' => array( 'pretty_version' => 'v6.1.4', 'version' => '6.1.4.0', diff --git a/vendor/jaeger/querylist/.github/FUNDING.yml b/vendor/jaeger/querylist/.github/FUNDING.yml deleted file mode 100644 index c53fd16..0000000 --- a/vendor/jaeger/querylist/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: querylist # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/vendor/jaeger/querylist/.gitignore b/vendor/jaeger/querylist/.gitignore deleted file mode 100644 index e2ee195..0000000 --- a/vendor/jaeger/querylist/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/vendor/ -.idea/ -composer.lock -.DS_Store -*.cache \ No newline at end of file diff --git a/vendor/jaeger/querylist/composer.json b/vendor/jaeger/querylist/composer.json index e1bcefe..19cb6b9 100644 --- a/vendor/jaeger/querylist/composer.json +++ b/vendor/jaeger/querylist/composer.json @@ -8,7 +8,7 @@ "jaeger/phpquery-single": "^1", "jaeger/g-http": "^1.1", "ext-dom": "*", - "tightenco/collect": ">5.0" + "symfony/var-dumper": ">3.4" }, "suggest":{ @@ -26,12 +26,15 @@ } }, "autoload-dev": { + "files": [ + "src/Collect/Support/helpers.php", + "src/Collect/Support/alias.php" + ], "psr-4": { "Tests\\": "tests/" } }, "require-dev": { - "symfony/var-dumper": "^3.3", "phpunit/phpunit": "^8.5" }, "scripts": { diff --git a/vendor/jaeger/querylist/phpunit.xml b/vendor/jaeger/querylist/phpunit.xml deleted file mode 100644 index ba72a84..0000000 --- a/vendor/jaeger/querylist/phpunit.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - ./tests - - - - - - src - - - - \ No newline at end of file diff --git a/vendor/jaeger/querylist/src/Collect/Conditionable/HigherOrderWhenProxy.php b/vendor/jaeger/querylist/src/Collect/Conditionable/HigherOrderWhenProxy.php new file mode 100644 index 0000000..96ea367 --- /dev/null +++ b/vendor/jaeger/querylist/src/Collect/Conditionable/HigherOrderWhenProxy.php @@ -0,0 +1,109 @@ +target = $target; + } + + /** + * Set the condition on the proxy. + * + * @param bool $condition + * @return $this + */ + public function condition($condition) + { + [$this->condition, $this->hasCondition] = [$condition, true]; + + return $this; + } + + /** + * Indicate that the condition should be negated. + * + * @return $this + */ + public function negateConditionOnCapture() + { + $this->negateConditionOnCapture = true; + + return $this; + } + + /** + * Proxy accessing an attribute onto the target. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + if (! $this->hasCondition) { + $condition = $this->target->{$key}; + + return $this->condition($this->negateConditionOnCapture ? ! $condition : $condition); + } + + return $this->condition + ? $this->target->{$key} + : $this->target; + } + + /** + * Proxy a method call on the target. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + if (! $this->hasCondition) { + $condition = $this->target->{$method}(...$parameters); + + return $this->condition($this->negateConditionOnCapture ? ! $condition : $condition); + } + + return $this->condition + ? $this->target->{$method}(...$parameters) + : $this->target; + } +} diff --git a/vendor/jaeger/querylist/src/Collect/Contracts/Support/Arrayable.php b/vendor/jaeger/querylist/src/Collect/Contracts/Support/Arrayable.php new file mode 100644 index 0000000..bcf60e2 --- /dev/null +++ b/vendor/jaeger/querylist/src/Collect/Contracts/Support/Arrayable.php @@ -0,0 +1,17 @@ + + */ + public function toArray(); +} diff --git a/vendor/tightenco/collect/src/Collect/Contracts/Support/CanBeEscapedWhenCastToString.php b/vendor/jaeger/querylist/src/Collect/Contracts/Support/CanBeEscapedWhenCastToString.php similarity index 86% rename from vendor/tightenco/collect/src/Collect/Contracts/Support/CanBeEscapedWhenCastToString.php rename to vendor/jaeger/querylist/src/Collect/Contracts/Support/CanBeEscapedWhenCastToString.php index 6f3ba00..699993b 100644 --- a/vendor/tightenco/collect/src/Collect/Contracts/Support/CanBeEscapedWhenCastToString.php +++ b/vendor/jaeger/querylist/src/Collect/Contracts/Support/CanBeEscapedWhenCastToString.php @@ -1,6 +1,6 @@ offsetExists($key); } + if (is_float($key)) { + $key = (string) $key; + } + return array_key_exists($key, $array); } @@ -252,7 +257,7 @@ class Arr * Remove one or many array items from a given array using "dot" notation. * * @param array $array - * @param array|string $keys + * @param array|string|int|float $keys * @return void */ public static function forget(&$array, $keys) @@ -281,7 +286,7 @@ class Arr while (count($parts) > 1) { $part = array_shift($parts); - if (isset($array[$part]) && is_array($array[$part])) { + if (isset($array[$part]) && static::accessible($array[$part])) { $array = &$array[$part]; } else { continue 2; @@ -314,7 +319,7 @@ class Arr return $array[$key]; } - if (strpos($key, '.') === false) { + if (! str_contains($key, '.')) { return $array[$key] ?? value($default); } @@ -423,6 +428,59 @@ class Arr return ! self::isAssoc($array); } + /** + * Join all items using a string. The final items can use a separate glue string. + * + * @param array $array + * @param string $glue + * @param string $finalGlue + * @return string + */ + public static function join($array, $glue, $finalGlue = '') + { + if ($finalGlue === '') { + return implode($glue, $array); + } + + if (count($array) === 0) { + return ''; + } + + if (count($array) === 1) { + return end($array); + } + + $finalItem = array_pop($array); + + return implode($glue, $array).$finalGlue.$finalItem; + } + + /** + * Key an associative array by a field or using a callback. + * + * @param array $array + * @param callable|array|string $keyBy + * @return array + */ + public static function keyBy($array, $keyBy) + { + return Collection::make($array)->keyBy($keyBy)->all(); + } + + /** + * Prepend the key names of an associative array. + * + * @param array $array + * @param string $prependWith + * @return array + */ + public static function prependKeysWith($array, $prependWith) + { + return Collection::make($array)->mapWithKeys(function ($item, $key) use ($prependWith) { + return [$prependWith.$key => $item]; + })->all(); + } + /** * Get a subset of the items from the given array. * @@ -487,6 +545,26 @@ class Arr return [$value, $key]; } + /** + * Run a map over each of the items in the array. + * + * @param array $array + * @param callable $callback + * @return array + */ + public static function map(array $array, callable $callback) + { + $keys = array_keys($array); + + try { + $items = array_map($callback, $array, $keys); + } catch (ArgumentCountError) { + $items = array_map($callback, $array); + } + + return array_combine($keys, $items); + } + /** * Push an item onto the beginning of an array. * @@ -539,7 +617,7 @@ class Arr * * @param array $array * @param int|null $number - * @param bool|false $preserveKeys + * @param bool $preserveKeys * @return mixed * * @throws \InvalidArgumentException @@ -587,7 +665,7 @@ class Arr * If no key is given to the method, the entire array will be replaced. * * @param array $array - * @param string|null $key + * @param string|int|null $key * @param mixed $value * @return array */ @@ -653,6 +731,18 @@ class Arr return Collection::make($array)->sortBy($callback)->all(); } + /** + * Sort the array in descending order using the given callback or "dot" notation. + * + * @param array $array + * @param callable|array|string|null $callback + * @return array + */ + public static function sortDesc($array, $callback = null) + { + return Collection::make($array)->sortByDesc($callback)->all(); + } + /** * Recursively sort an array by keys and values. * @@ -705,6 +795,29 @@ class Arr return implode(' ', $classes); } + /** + * Conditionally compile styles from an array into a style list. + * + * @param array $array + * @return string + */ + public static function toCssStyles($array) + { + $styleList = static::wrap($array); + + $styles = []; + + foreach ($styleList as $class => $constraint) { + if (is_numeric($class)) { + $styles[] = Str::finish($constraint, ';'); + } elseif ($constraint) { + $styles[] = Str::finish($class, ';'); + } + } + + return implode(' ', $styles); + } + /** * Filter the array using the given callback. * @@ -725,9 +838,7 @@ class Arr */ public static function whereNotNull($array) { - return static::where($array, function ($value) { - return ! is_null($value); - }); + return static::where($array, fn ($value) => ! is_null($value)); } /** diff --git a/vendor/tightenco/collect/src/Collect/Support/Collection.php b/vendor/jaeger/querylist/src/Collect/Support/Collection.php similarity index 73% rename from vendor/tightenco/collect/src/Collect/Support/Collection.php rename to vendor/jaeger/querylist/src/Collect/Support/Collection.php index 0dc7323..34457a2 100644 --- a/vendor/tightenco/collect/src/Collect/Support/Collection.php +++ b/vendor/jaeger/querylist/src/Collect/Support/Collection.php @@ -1,29 +1,40 @@ + * @implements \QL\Collect\Support\Enumerable + */ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerable { + /** + * @use \QL\Collect\Support\Traits\EnumeratesValues + */ use EnumeratesValues, Macroable; /** * The items contained in the collection. * - * @var array + * @var array */ protected $items = []; /** * Create a new collection. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable|null $items * @return void */ public function __construct($items = []) @@ -36,7 +47,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * * @param int $from * @param int $to - * @return static + * @return static */ public static function range($from, $to) { @@ -46,7 +57,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get all of the items in the collection. * - * @return array + * @return array */ public function all() { @@ -56,7 +67,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get a lazy collection for the items in this collection. * - * @return \Tightenco\Collect\Support\LazyCollection + * @return \QL\Collect\Support\LazyCollection */ public function lazy() { @@ -66,18 +77,16 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the average value of a given key. * - * @param callable|string|null $callback - * @return mixed + * @param (callable(TValue): float|int)|string|null $callback + * @return float|int|null */ public function avg($callback = null) { $callback = $this->valueRetriever($callback); - $items = $this->map(function ($value) use ($callback) { - return $callback($value); - })->filter(function ($value) { - return ! is_null($value); - }); + $items = $this + ->map(fn ($value) => $callback($value)) + ->filter(fn ($value) => ! is_null($value)); if ($count = $items->count()) { return $items->sum() / $count; @@ -87,15 +96,14 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the median of a given key. * - * @param string|array|null $key - * @return mixed + * @param string|array|null $key + * @return float|int|null */ public function median($key = null) { $values = (isset($key) ? $this->pluck($key) : $this) - ->filter(function ($item) { - return ! is_null($item); - })->sort()->values(); + ->filter(fn ($item) => ! is_null($item)) + ->sort()->values(); $count = $values->count(); @@ -117,8 +125,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the mode of a given key. * - * @param string|array|null $key - * @return array|null + * @param string|array|null $key + * @return array|null */ public function mode($key = null) { @@ -130,23 +138,20 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl $counts = new static; - $collection->each(function ($value) use ($counts) { - $counts[$value] = isset($counts[$value]) ? $counts[$value] + 1 : 1; - }); + $collection->each(fn ($value) => $counts[$value] = isset($counts[$value]) ? $counts[$value] + 1 : 1); $sorted = $counts->sort(); $highestValue = $sorted->last(); - return $sorted->filter(function ($value) use ($highestValue) { - return $value == $highestValue; - })->sort()->keys()->all(); + return $sorted->filter(fn ($value) => $value == $highestValue) + ->sort()->keys()->all(); } /** * Collapse the collection of items into a single array. * - * @return static + * @return static */ public function collapse() { @@ -156,7 +161,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Determine if an item exists in the collection. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value * @return bool @@ -176,6 +181,26 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl return $this->contains($this->operatorForWhere(...func_get_args())); } + /** + * Determine if an item exists, using strict comparison. + * + * @param (callable(TValue): bool)|TValue|array-key $key + * @param TValue|null $value + * @return bool + */ + public function containsStrict($key, $value = null) + { + if (func_num_args() === 2) { + return $this->contains(fn ($item) => data_get($item, $key) === $value); + } + + if ($this->useAsCallable($key)) { + return ! is_null($this->first($key)); + } + + return in_array($key, $this->items, true); + } + /** * Determine if an item is not contained in the collection. * @@ -192,8 +217,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Cross join with the given lists, returning all possible permutations. * - * @param mixed ...$lists - * @return static + * @template TCrossJoinKey + * @template TCrossJoinValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable ...$lists + * @return static> */ public function crossJoin(...$lists) { @@ -205,7 +233,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the items in the collection that are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diff($items) @@ -216,8 +244,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the items in the collection that are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TValue, TValue): int $callback * @return static */ public function diffUsing($items, callable $callback) @@ -228,7 +256,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the items in the collection whose keys and values are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diffAssoc($items) @@ -239,8 +267,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the items in the collection whose keys and values are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TKey, TKey): int $callback * @return static */ public function diffAssocUsing($items, callable $callback) @@ -251,7 +279,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the items in the collection whose keys are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diffKeys($items) @@ -262,8 +290,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the items in the collection whose keys are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TKey, TKey): int $callback * @return static */ public function diffKeysUsing($items, callable $callback) @@ -274,7 +302,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Retrieve duplicate items from the collection. * - * @param callable|string|null $callback + * @param (callable(TValue): bool)|string|null $callback * @param bool $strict * @return static */ @@ -302,7 +330,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Retrieve duplicate items from the collection using strict comparison. * - * @param callable|string|null $callback + * @param (callable(TValue): bool)|string|null $callback * @return static */ public function duplicatesStrict($callback = null) @@ -314,25 +342,21 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * Get the comparison function to detect duplicates. * * @param bool $strict - * @return \Closure + * @return callable(TValue, TValue): bool */ protected function duplicateComparator($strict) { if ($strict) { - return function ($a, $b) { - return $a === $b; - }; + return fn ($a, $b) => $a === $b; } - return function ($a, $b) { - return $a == $b; - }; + return fn ($a, $b) => $a == $b; } /** * Get all items except for those with the specified keys. * - * @param \Tightenco\Collect\Support\Collection|mixed $keys + * @param \QL\Collect\Support\Enumerable|array $keys * @return static */ public function except($keys) @@ -349,7 +373,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Run a filter over each of the items. * - * @param callable|null $callback + * @param (callable(TValue, TKey): bool)|null $callback * @return static */ public function filter(callable $callback = null) @@ -364,9 +388,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the first item from the collection passing the given truth test. * - * @param callable|null $callback - * @param mixed $default - * @return mixed + * @template TFirstDefault + * + * @param (callable(TValue, TKey): bool)|null $callback + * @param TFirstDefault|(\Closure(): TFirstDefault) $default + * @return TValue|TFirstDefault */ public function first(callable $callback = null, $default = null) { @@ -377,7 +403,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * Get a flattened array of the items in the collection. * * @param int $depth - * @return static + * @return static */ public function flatten($depth = INF) { @@ -387,7 +413,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Flip the items in the collection. * - * @return static + * @return static */ public function flip() { @@ -397,7 +423,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Remove an item from the collection by key. * - * @param string|int|array $keys + * @param TKey|array $keys * @return $this */ public function forget($keys) @@ -412,9 +438,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get an item from the collection by key. * - * @param mixed $key - * @param mixed $default - * @return mixed + * @template TGetDefault + * + * @param TKey $key + * @param TGetDefault|(\Closure(): TGetDefault) $default + * @return TValue|TGetDefault */ public function get($key, $default = null) { @@ -446,9 +474,9 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Group an associative array by a field or using a callback. * - * @param array|callable|string $groupBy + * @param (callable(TValue, TKey): array-key)|array|string $groupBy * @param bool $preserveKeys - * @return static + * @return static> */ public function groupBy($groupBy, $preserveKeys = false) { @@ -470,7 +498,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl } foreach ($groupKeys as $groupKey) { - $groupKey = is_bool($groupKey) ? (int) $groupKey : $groupKey; + $groupKey = match (true) { + is_bool($groupKey) => (int) $groupKey, + $groupKey instanceof \Stringable => (string) $groupKey, + default => $groupKey, + }; if (! array_key_exists($groupKey, $results)) { $results[$groupKey] = new static; @@ -492,8 +524,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Key an associative array by a field or using a callback. * - * @param callable|string $keyBy - * @return static + * @param (callable(TValue, TKey): array-key)|array|string $keyBy + * @return static */ public function keyBy($keyBy) { @@ -517,7 +549,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Determine if an item exists in the collection by key. * - * @param mixed $key + * @param TKey|array $key * @return bool */ public function has($key) @@ -559,12 +591,16 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Concatenate values of a given key as a string. * - * @param string $value + * @param callable|string $value * @param string|null $glue * @return string */ public function implode($value, $glue = null) { + if ($this->useAsCallable($value)) { + return implode($glue ?? '', $this->map($value)->all()); + } + $first = $this->first(); if (is_array($first) || (is_object($first) && ! $first instanceof \Illuminate\Support\Stringable)) { @@ -577,7 +613,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Intersect the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function intersect($items) @@ -585,10 +621,45 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl return new static(array_intersect($this->items, $this->getArrayableItems($items))); } + /** + * Intersect the collection with the given items, using the callback. + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TValue, TValue): int $callback + * @return static + */ + public function intersectUsing($items, callable $callback) + { + return new static(array_uintersect($this->items, $this->getArrayableItems($items), $callback)); + } + + /** + * Intersect the collection with the given items with additional index check. + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @return static + */ + public function intersectAssoc($items) + { + return new static(array_intersect_assoc($this->items, $this->getArrayableItems($items))); + } + + /** + * Intersect the collection with the given items with additional index check, using the callback. + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TValue, TValue): int $callback + * @return static + */ + public function intersectAssocUsing($items, callable $callback) + { + return new static(array_intersect_uassoc($this->items, $this->getArrayableItems($items), $callback)); + } + /** * Intersect the collection with the given items by key. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function intersectByKeys($items) @@ -651,7 +722,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the keys of the collection items. * - * @return static + * @return static */ public function keys() { @@ -661,9 +732,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the last item from the collection. * - * @param callable|null $callback - * @param mixed $default - * @return mixed + * @template TLastDefault + * + * @param (callable(TValue, TKey): bool)|null $callback + * @param TLastDefault|(\Closure(): TLastDefault) $default + * @return TValue|TLastDefault */ public function last(callable $callback = null, $default = null) { @@ -673,9 +746,9 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the values of a given key. * - * @param string|array|int|null $value + * @param string|int|array $value * @param string|null $key - * @return static + * @return static */ public function pluck($value, $key = null) { @@ -685,16 +758,14 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Run a map over each of the items. * - * @param callable $callback - * @return static + * @template TMapValue + * + * @param callable(TValue, TKey): TMapValue $callback + * @return static */ public function map(callable $callback) { - $keys = array_keys($this->items); - - $items = array_map($callback, $this->items, $keys); - - return new static(array_combine($keys, $items)); + return new static(Arr::map($this->items, $callback)); } /** @@ -702,8 +773,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapToDictionaryKey of array-key + * @template TMapToDictionaryValue + * + * @param callable(TValue, TKey): array $callback + * @return static> */ public function mapToDictionary(callable $callback) { @@ -731,8 +805,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapWithKeysKey of array-key + * @template TMapWithKeysValue + * + * @param callable(TValue, TKey): array $callback + * @return static */ public function mapWithKeys(callable $callback) { @@ -752,7 +829,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Merge the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function merge($items) @@ -763,8 +840,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Recursively merge the collection with the given items. * - * @param mixed $items - * @return static + * @template TMergeRecursiveValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @return static */ public function mergeRecursive($items) { @@ -774,8 +853,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Create a collection by using this collection for keys and another for its values. * - * @param mixed $values - * @return static + * @template TCombineValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values + * @return static */ public function combine($values) { @@ -785,7 +866,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Union the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function union($items) @@ -820,7 +901,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the items with the specified keys. * - * @param mixed $keys + * @param \QL\Collect\Support\Enumerable|array|string|null $keys * @return static */ public function only($keys) @@ -842,7 +923,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * Get and remove the last N items from the collection. * * @param int $count - * @return mixed + * @return static|TValue|null */ public function pop($count = 1) { @@ -868,8 +949,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Push an item onto the beginning of the collection. * - * @param mixed $value - * @param mixed $key + * @param TValue $value + * @param TKey $key * @return $this */ public function prepend($value, $key = null) @@ -882,7 +963,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Push one or more items onto the end of the collection. * - * @param mixed $values + * @param TValue ...$values * @return $this */ public function push(...$values) @@ -897,7 +978,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Push all of the given items onto the collection. * - * @param iterable $source + * @param iterable $source * @return static */ public function concat($source) @@ -914,9 +995,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get and remove an item from the collection. * - * @param mixed $key - * @param mixed $default - * @return mixed + * @template TPullDefault + * + * @param TKey $key + * @param TPullDefault|(\Closure(): TPullDefault) $default + * @return TValue|TPullDefault */ public function pull($key, $default = null) { @@ -926,8 +1009,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Put an item in the collection by key. * - * @param mixed $key - * @param mixed $value + * @param TKey $key + * @param TValue $value * @return $this */ public function put($key, $value) @@ -940,8 +1023,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get one or a specified number of items randomly from the collection. * - * @param int|null $number - * @return static|mixed + * @param (callable(self): int)|int|null $number + * @return static|TValue * * @throws \InvalidArgumentException */ @@ -951,13 +1034,17 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl return Arr::random($this->items); } + if (is_callable($number)) { + return new static(Arr::random($this->items, $number($this))); + } + return new static(Arr::random($this->items, $number)); } /** * Replace the collection items with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function replace($items) @@ -968,7 +1055,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Recursively replace the collection items with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function replaceRecursive($items) @@ -989,9 +1076,9 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Search the collection for a given value and return the corresponding key if successful. * - * @param mixed $value + * @param TValue|(callable(TValue,TKey): bool) $value * @param bool $strict - * @return mixed + * @return TKey|bool */ public function search($value, $strict = false) { @@ -1012,7 +1099,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * Get and remove the first N items from the collection. * * @param int $count - * @return mixed + * @return static|TValue|null */ public function shift($count = 1) { @@ -1051,7 +1138,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * * @param int $size * @param int $step - * @return static + * @return static */ public function sliding($size = 2, $step = 1) { @@ -1076,7 +1163,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Skip items in the collection until the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function skipUntil($value) @@ -1087,7 +1174,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Skip items in the collection while the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function skipWhile($value) @@ -1111,7 +1198,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * Split a collection into a certain number of groups. * * @param int $numberOfGroups - * @return static + * @return static */ public function split($numberOfGroups) { @@ -1148,7 +1235,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * Split a collection into a certain number of groups, and fill the first groups completely. * * @param int $numberOfGroups - * @return static + * @return static */ public function splitIn($numberOfGroups) { @@ -1158,13 +1245,13 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|string $key * @param mixed $operator * @param mixed $value - * @return mixed + * @return TValue * - * @throws \Tightenco\Collect\Support\ItemNotFoundException - * @throws \Tightenco\Collect\Support\MultipleItemsFoundException + * @throws \QL\Collect\Support\ItemNotFoundException + * @throws \QL\Collect\Support\MultipleItemsFoundException */ public function sole($key = null, $operator = null, $value = null) { @@ -1172,14 +1259,16 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl ? $this->operatorForWhere(...func_get_args()) : $key; - $items = $this->when($filter)->filter($filter); + $items = $this->unless($filter == null)->filter($filter); - if ($items->isEmpty()) { + $count = $items->count(); + + if ($count === 0) { throw new ItemNotFoundException; } - if ($items->count() > 1) { - throw new MultipleItemsFoundException; + if ($count > 1) { + throw new MultipleItemsFoundException($count); } return $items->first(); @@ -1188,12 +1277,12 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get the first item in the collection but throw an exception if no matching items exist. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|string $key * @param mixed $operator * @param mixed $value - * @return mixed + * @return TValue * - * @throws \Tightenco\Collect\Support\ItemNotFoundException + * @throws \QL\Collect\Support\ItemNotFoundException */ public function firstOrFail($key = null, $operator = null, $value = null) { @@ -1216,7 +1305,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * Chunk the collection into chunks of the given size. * * @param int $size - * @return static + * @return static */ public function chunk($size) { @@ -1236,8 +1325,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Chunk the collection into chunks with a callback. * - * @param callable $callback - * @return static + * @param callable(TValue, TKey, static): bool $callback + * @return static> */ public function chunkWhile(callable $callback) { @@ -1249,7 +1338,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Sort through each item with a callback. * - * @param callable|int|null $callback + * @param (callable(TValue, TValue): int)|null|int $callback * @return static */ public function sort($callback = null) @@ -1281,7 +1370,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Sort the collection using the given callback. * - * @param callable|array|string $callback + * @param array|(callable(TValue, TKey): mixed)|string $callback * @param int $options * @param bool $descending * @return static @@ -1319,14 +1408,14 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Sort the collection using multiple comparisons. * - * @param array $comparisons + * @param array $comparisons * @return static */ protected function sortByMany(array $comparisons = []) { $items = $this->items; - usort($items, function ($a, $b) use ($comparisons) { + uasort($items, function ($a, $b) use ($comparisons) { foreach ($comparisons as $comparison) { $comparison = Arr::wrap($comparison); @@ -1335,8 +1424,6 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl $ascending = Arr::get($comparison, 1, true) === true || Arr::get($comparison, 1, true) === 'asc'; - $result = 0; - if (! is_string($prop) && is_callable($prop)) { $result = $prop($a, $b); } else { @@ -1363,7 +1450,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Sort the collection in descending order using the given callback. * - * @param callable|string $callback + * @param array|(callable(TValue, TKey): mixed)|string $callback * @param int $options * @return static */ @@ -1402,7 +1489,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Sort the collection keys using a callback. * - * @param callable $callback + * @param callable(TKey, TKey): int $callback * @return static */ public function sortKeysUsing(callable $callback) @@ -1419,7 +1506,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * * @param int $offset * @param int|null $length - * @param mixed $replacement + * @param array $replacement * @return static */ public function splice($offset, $length = null, $replacement = []) @@ -1449,7 +1536,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Take items in the collection until the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function takeUntil($value) @@ -1460,7 +1547,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Take items in the collection while the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function takeWhile($value) @@ -1471,7 +1558,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Transform each item in the collection using a callback. * - * @param callable $callback + * @param callable(TValue, TKey): TValue $callback * @return $this */ public function transform(callable $callback) @@ -1494,7 +1581,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Return only unique items from the collection array. * - * @param string|callable|null $key + * @param (callable(TValue, TKey): mixed)|string|null $key * @param bool $strict * @return static */ @@ -1520,7 +1607,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Reset the keys on the underlying array. * - * @return static + * @return static */ public function values() { @@ -1533,18 +1620,16 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); * => [[1, 4], [2, 5], [3, 6]] * - * @param mixed ...$items - * @return static + * @template TZipValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable ...$items + * @return static> */ public function zip($items) { - $arrayableItems = array_map(function ($items) { - return $this->getArrayableItems($items); - }, func_get_args()); + $arrayableItems = array_map(fn ($items) => $this->getArrayableItems($items), func_get_args()); - $params = array_merge([function () { - return new static(func_get_args()); - }, $this->items], $arrayableItems); + $params = array_merge([fn () => new static(func_get_args()), $this->items], $arrayableItems); return new static(array_map(...$params)); } @@ -1552,9 +1637,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Pad collection to the specified length with a value. * + * @template TPadValue + * * @param int $size - * @param mixed $value - * @return static + * @param TPadValue $value + * @return static */ public function pad($size, $value) { @@ -1564,10 +1651,9 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get an iterator for the items. * - * @return \ArrayIterator + * @return \ArrayIterator */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->items); } @@ -1577,8 +1663,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl * * @return int */ - #[\ReturnTypeWillChange] - public function count() + public function count(): int { return count($this->items); } @@ -1586,8 +1671,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Count the number of items in the collection by a field or using a callback. * - * @param callable|string $countBy - * @return static + * @param (callable(TValue, TKey): array-key)|string|null $countBy + * @return static */ public function countBy($countBy = null) { @@ -1597,7 +1682,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Add an item to the collection. * - * @param mixed $item + * @param TValue $item * @return $this */ public function add($item) @@ -1610,7 +1695,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get a base Support collection instance from this collection. * - * @return \Tightenco\Collect\Support\Collection + * @return \QL\Collect\Support\Collection */ public function toBase() { @@ -1620,11 +1705,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Determine if an item exists at an offset. * - * @param mixed $key + * @param TKey $key * @return bool */ - #[\ReturnTypeWillChange] - public function offsetExists($key) + public function offsetExists($key): bool { return isset($this->items[$key]); } @@ -1632,11 +1716,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Get an item at a given offset. * - * @param mixed $key - * @return mixed + * @param TKey $key + * @return TValue */ - #[\ReturnTypeWillChange] - public function offsetGet($key) + public function offsetGet($key): mixed { return $this->items[$key]; } @@ -1644,12 +1727,11 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Set the item at a given offset. * - * @param mixed $key - * @param mixed $value + * @param TKey|null $key + * @param TValue $value * @return void */ - #[\ReturnTypeWillChange] - public function offsetSet($key, $value) + public function offsetSet($key, $value): void { if (is_null($key)) { $this->items[] = $value; @@ -1661,11 +1743,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl /** * Unset the item at a given offset. * - * @param mixed $key + * @param TKey $key * @return void */ - #[\ReturnTypeWillChange] - public function offsetUnset($key) + public function offsetUnset($key): void { unset($this->items[$key]); } diff --git a/vendor/tightenco/collect/src/Collect/Support/Enumerable.php b/vendor/jaeger/querylist/src/Collect/Support/Enumerable.php similarity index 56% rename from vendor/tightenco/collect/src/Collect/Support/Enumerable.php rename to vendor/jaeger/querylist/src/Collect/Support/Enumerable.php index 60af386..942d82e 100644 --- a/vendor/tightenco/collect/src/Collect/Support/Enumerable.php +++ b/vendor/jaeger/querylist/src/Collect/Support/Enumerable.php @@ -1,20 +1,32 @@ + * @extends \IteratorAggregate + */ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable { /** * Create a new collection instance if the value isn't one already. * - * @param mixed $items - * @return static + * @template TMakeKey of array-key + * @template TMakeValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable|null $items + * @return static */ public static function make($items = []); @@ -39,16 +51,21 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Wrap the given value in a collection if applicable. * - * @param mixed $value - * @return static + * @template TWrapValue + * + * @param iterable|TWrapValue $value + * @return static */ public static function wrap($value); /** * Get the underlying items from the given collection if applicable. * - * @param array|static $value - * @return array + * @template TUnwrapKey of array-key + * @template TUnwrapValue + * + * @param array|static $value + * @return array */ public static function unwrap($value); @@ -69,38 +86,38 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Alias for the "avg" method. * - * @param callable|string|null $callback - * @return mixed + * @param (callable(TValue): float|int)|string|null $callback + * @return float|int|null */ public function average($callback = null); /** * Get the median of a given key. * - * @param string|array|null $key - * @return mixed + * @param string|array|null $key + * @return float|int|null */ public function median($key = null); /** * Get the mode of a given key. * - * @param string|array|null $key - * @return array|null + * @param string|array|null $key + * @return array|null */ public function mode($key = null); /** * Collapse the items into a single enumerable. * - * @return static + * @return static */ public function collapse(); /** * Alias for the "contains" method. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value * @return bool @@ -110,8 +127,8 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Determine if an item exists, using strict comparison. * - * @param mixed $key - * @param mixed $value + * @param (callable(TValue): bool)|TValue|array-key $key + * @param TValue|null $value * @return bool */ public function containsStrict($key, $value = null); @@ -119,26 +136,39 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the average value of a given key. * - * @param callable|string|null $callback - * @return mixed + * @param (callable(TValue): float|int)|string|null $callback + * @return float|int|null */ public function avg($callback = null); /** * Determine if an item exists in the enumerable. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value * @return bool */ public function contains($key, $operator = null, $value = null); + /** + * Determine if an item is not contained in the collection. + * + * @param mixed $key + * @param mixed $operator + * @param mixed $value + * @return bool + */ + public function doesntContain($key, $operator = null, $value = null); + /** * Cross join with the given lists, returning all possible permutations. * - * @param mixed ...$lists - * @return static + * @template TCrossJoinKey + * @template TCrossJoinValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable ...$lists + * @return static> */ public function crossJoin(...$lists); @@ -146,7 +176,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Dump the collection and end the script. * * @param mixed ...$args - * @return void + * @return never */ public function dd(...$args); @@ -160,7 +190,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the items that are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diff($items); @@ -168,8 +198,8 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the items that are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TValue, TValue): int $callback * @return static */ public function diffUsing($items, callable $callback); @@ -177,7 +207,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the items whose keys and values are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diffAssoc($items); @@ -185,8 +215,8 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the items whose keys and values are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TKey, TKey): int $callback * @return static */ public function diffAssocUsing($items, callable $callback); @@ -194,7 +224,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the items whose keys are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diffKeys($items); @@ -202,8 +232,8 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the items whose keys are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TKey, TKey): int $callback * @return static */ public function diffKeysUsing($items, callable $callback); @@ -211,7 +241,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Retrieve duplicate items. * - * @param callable|string|null $callback + * @param (callable(TValue): bool)|string|null $callback * @param bool $strict * @return static */ @@ -220,7 +250,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Retrieve duplicate items using strict comparison. * - * @param callable|string|null $callback + * @param (callable(TValue): bool)|string|null $callback * @return static */ public function duplicatesStrict($callback = null); @@ -228,7 +258,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Execute a callback over each item. * - * @param callable $callback + * @param callable(TValue, TKey): mixed $callback * @return $this */ public function each(callable $callback); @@ -244,7 +274,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Determine if all items pass the given truth test. * - * @param string|callable $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value * @return bool @@ -254,7 +284,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get all items except for those with the specified keys. * - * @param mixed $keys + * @param \QL\Collect\Support\Enumerable|array $keys * @return static */ public function except($keys); @@ -262,64 +292,76 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Run a filter over each of the items. * - * @param callable|null $callback + * @param (callable(TValue): bool)|null $callback * @return static */ public function filter(callable $callback = null); /** - * Apply the callback if the value is truthy. + * Apply the callback if the given "value" is (or resolves to) truthy. + * + * @template TWhenReturnType as null * * @param bool $value - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @param (callable($this): TWhenReturnType)|null $callback + * @param (callable($this): TWhenReturnType)|null $default + * @return $this|TWhenReturnType */ - public function when($value, callable $callback, callable $default = null); + public function when($value, callable $callback = null, callable $default = null); /** * Apply the callback if the collection is empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TWhenEmptyReturnType + * + * @param (callable($this): TWhenEmptyReturnType) $callback + * @param (callable($this): TWhenEmptyReturnType)|null $default + * @return $this|TWhenEmptyReturnType */ public function whenEmpty(callable $callback, callable $default = null); /** * Apply the callback if the collection is not empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TWhenNotEmptyReturnType + * + * @param callable($this): TWhenNotEmptyReturnType $callback + * @param (callable($this): TWhenNotEmptyReturnType)|null $default + * @return $this|TWhenNotEmptyReturnType */ public function whenNotEmpty(callable $callback, callable $default = null); /** - * Apply the callback if the value is falsy. + * Apply the callback if the given "value" is (or resolves to) truthy. + * + * @template TUnlessReturnType * * @param bool $value - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @param (callable($this): TUnlessReturnType) $callback + * @param (callable($this): TUnlessReturnType)|null $default + * @return $this|TUnlessReturnType */ public function unless($value, callable $callback, callable $default = null); /** * Apply the callback unless the collection is empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TUnlessEmptyReturnType + * + * @param callable($this): TUnlessEmptyReturnType $callback + * @param (callable($this): TUnlessEmptyReturnType)|null $default + * @return $this|TUnlessEmptyReturnType */ public function unlessEmpty(callable $callback, callable $default = null); /** * Apply the callback unless the collection is not empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TUnlessNotEmptyReturnType + * + * @param callable($this): TUnlessNotEmptyReturnType $callback + * @param (callable($this): TUnlessNotEmptyReturnType)|null $default + * @return $this|TUnlessNotEmptyReturnType */ public function unlessNotEmpty(callable $callback, callable $default = null); @@ -362,7 +404,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Filter items by the given key value pair. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @param bool $strict * @return static */ @@ -372,7 +414,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Filter items by the given key value pair using strict comparison. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereInStrict($key, $values); @@ -381,7 +423,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Filter items such that the value of the given key is between the given values. * * @param string $key - * @param array $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereBetween($key, $values); @@ -390,7 +432,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Filter items such that the value of the given key is not between the given values. * * @param string $key - * @param array $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereNotBetween($key, $values); @@ -399,7 +441,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Filter items by the given key value pair. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @param bool $strict * @return static */ @@ -409,7 +451,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Filter items by the given key value pair using strict comparison. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereNotInStrict($key, $values); @@ -417,17 +459,21 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Filter the items, removing any items that don't match the given type(s). * - * @param string|string[] $type - * @return static + * @template TWhereInstanceOf + * + * @param class-string|array> $type + * @return static */ public function whereInstanceOf($type); /** * Get the first item from the enumerable passing the given truth test. * - * @param callable|null $callback - * @param mixed $default - * @return mixed + * @template TFirstDefault + * + * @param (callable(TValue,TKey): bool)|null $callback + * @param TFirstDefault|(\Closure(): TFirstDefault) $default + * @return TValue|TFirstDefault */ public function first(callable $callback = null, $default = null); @@ -437,7 +483,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * @param string $key * @param mixed $operator * @param mixed $value - * @return mixed + * @return TValue|null */ public function firstWhere($key, $operator = null, $value = null); @@ -452,44 +498,54 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Flip the values with their keys. * - * @return static + * @return static */ public function flip(); /** * Get an item from the collection by key. * - * @param mixed $key - * @param mixed $default - * @return mixed + * @template TGetDefault + * + * @param TKey $key + * @param TGetDefault|(\Closure(): TGetDefault) $default + * @return TValue|TGetDefault */ public function get($key, $default = null); /** * Group an associative array by a field or using a callback. * - * @param array|callable|string $groupBy + * @param (callable(TValue, TKey): array-key)|array|string $groupBy * @param bool $preserveKeys - * @return static + * @return static> */ public function groupBy($groupBy, $preserveKeys = false); /** * Key an associative array by a field or using a callback. * - * @param callable|string $keyBy - * @return static + * @param (callable(TValue, TKey): array-key)|array|string $keyBy + * @return static */ public function keyBy($keyBy); /** * Determine if an item exists in the collection by key. * - * @param mixed $key + * @param TKey|array $key * @return bool */ public function has($key); + /** + * Determine if any of the keys exist in the collection. + * + * @param mixed $key + * @return bool + */ + public function hasAny($key); + /** * Concatenate values of a given key as a string. * @@ -502,7 +558,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Intersect the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function intersect($items); @@ -510,7 +566,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Intersect the collection with the given items by key. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function intersectByKeys($items); @@ -529,6 +585,13 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, */ public function isNotEmpty(); + /** + * Determine if the collection contains a single item. + * + * @return bool + */ + public function containsOneItem(); + /** * Join all items from the collection using a string. The final items can use a separate glue string. * @@ -541,24 +604,28 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the keys of the collection items. * - * @return static + * @return static */ public function keys(); /** * Get the last item from the collection. * - * @param callable|null $callback - * @param mixed $default - * @return mixed + * @template TLastDefault + * + * @param (callable(TValue, TKey): bool)|null $callback + * @param TLastDefault|(\Closure(): TLastDefault) $default + * @return TValue|TLastDefault */ public function last(callable $callback = null, $default = null); /** * Run a map over each of the items. * - * @param callable $callback - * @return static + * @template TMapValue + * + * @param callable(TValue, TKey): TMapValue $callback + * @return static */ public function map(callable $callback); @@ -575,8 +642,11 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapToDictionaryKey of array-key + * @template TMapToDictionaryValue + * + * @param callable(TValue, TKey): array $callback + * @return static> */ public function mapToDictionary(callable $callback); @@ -585,8 +655,11 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapToGroupsKey of array-key + * @template TMapToGroupsValue + * + * @param callable(TValue, TKey): array $callback + * @return static> */ public function mapToGroups(callable $callback); @@ -595,31 +668,39 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapWithKeysKey of array-key + * @template TMapWithKeysValue + * + * @param callable(TValue, TKey): array $callback + * @return static */ public function mapWithKeys(callable $callback); /** * Map a collection and flatten the result by a single level. * - * @param callable $callback - * @return static + * @template TFlatMapKey of array-key + * @template TFlatMapValue + * + * @param callable(TValue, TKey): (\QL\Collect\Support\Collection|array) $callback + * @return static */ public function flatMap(callable $callback); /** * Map the values into a new class. * - * @param string $class - * @return static + * @template TMapIntoValue + * + * @param class-string $class + * @return static */ public function mapInto($class); /** * Merge the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function merge($items); @@ -627,23 +708,27 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Recursively merge the collection with the given items. * - * @param mixed $items - * @return static + * @template TMergeRecursiveValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @return static */ public function mergeRecursive($items); /** * Create a collection by using this collection for keys and another for its values. * - * @param mixed $values - * @return static + * @template TCombineValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values + * @return static */ public function combine($values); /** * Union the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function union($items); @@ -651,7 +736,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the min value of a given key. * - * @param callable|string|null $callback + * @param (callable(TValue):mixed)|string|null $callback * @return mixed */ public function min($callback = null); @@ -659,7 +744,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the max value of a given key. * - * @param callable|string|null $callback + * @param (callable(TValue):mixed)|string|null $callback * @return mixed */ public function max($callback = null); @@ -676,7 +761,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Get the items with the specified keys. * - * @param mixed $keys + * @param \QL\Collect\Support\Enumerable|array|string $keys * @return static */ public function only($keys); @@ -693,17 +778,17 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Partition the collection into two arrays using the given callback or key. * - * @param callable|string $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value - * @return static + * @return static, static> */ public function partition($key, $operator = null, $value = null); /** * Push all of the given items onto the collection. * - * @param iterable $source + * @param iterable $source * @return static */ public function concat($source); @@ -712,7 +797,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Get one or a specified number of items randomly from the collection. * * @param int|null $number - * @return static|mixed + * @return static|TValue * * @throws \InvalidArgumentException */ @@ -721,16 +806,30 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Reduce the collection to a single value. * - * @param callable $callback - * @param mixed $initial - * @return mixed + * @template TReduceInitial + * @template TReduceReturnType + * + * @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback + * @param TReduceInitial $initial + * @return TReduceReturnType */ public function reduce(callable $callback, $initial = null); + /** + * Reduce the collection to multiple aggregate values. + * + * @param callable $callback + * @param mixed ...$initial + * @return array + * + * @throws \UnexpectedValueException + */ + public function reduceSpread(callable $callback, ...$initial); + /** * Replace the collection items with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function replace($items); @@ -738,7 +837,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Recursively replace the collection items with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function replaceRecursive($items); @@ -753,9 +852,9 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Search the collection for a given value and return the corresponding key if successful. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @param bool $strict - * @return mixed + * @return TKey|bool */ public function search($value, $strict = false); @@ -767,6 +866,15 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, */ public function shuffle($seed = null); + /** + * Create chunks representing a "sliding window" view of the items in the collection. + * + * @param int $size + * @param int $step + * @return static + */ + public function sliding($size = 2, $step = 1); + /** * Skip the first {$count} items. * @@ -778,7 +886,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Skip items in the collection until the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function skipUntil($value); @@ -786,7 +894,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Skip items in the collection while the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function skipWhile($value); @@ -804,30 +912,63 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * Split a collection into a certain number of groups. * * @param int $numberOfGroups - * @return static + * @return static */ public function split($numberOfGroups); + /** + * Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception. + * + * @param (callable(TValue, TKey): bool)|string $key + * @param mixed $operator + * @param mixed $value + * @return TValue + * + * @throws \QL\Collect\Support\ItemNotFoundException + * @throws \QL\Collect\Support\MultipleItemsFoundException + */ + public function sole($key = null, $operator = null, $value = null); + + /** + * Get the first item in the collection but throw an exception if no matching items exist. + * + * @param (callable(TValue, TKey): bool)|string $key + * @param mixed $operator + * @param mixed $value + * @return TValue + * + * @throws \QL\Collect\Support\ItemNotFoundException + */ + public function firstOrFail($key = null, $operator = null, $value = null); + /** * Chunk the collection into chunks of the given size. * * @param int $size - * @return static + * @return static */ public function chunk($size); /** * Chunk the collection into chunks with a callback. * - * @param callable $callback - * @return static + * @param callable(TValue, TKey, static): bool $callback + * @return static> */ public function chunkWhile(callable $callback); + /** + * Split a collection into a certain number of groups, and fill the first groups completely. + * + * @param int $numberOfGroups + * @return static + */ + public function splitIn($numberOfGroups); + /** * Sort through each item with a callback. * - * @param callable|null|int $callback + * @param (callable(TValue, TValue): int)|null|int $callback * @return static */ public function sort($callback = null); @@ -843,7 +984,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Sort the collection using the given callback. * - * @param callable|string $callback + * @param array|(callable(TValue, TKey): mixed)|string $callback * @param int $options * @param bool $descending * @return static @@ -853,7 +994,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Sort the collection in descending order using the given callback. * - * @param callable|string $callback + * @param array|(callable(TValue, TKey): mixed)|string $callback * @param int $options * @return static */ @@ -876,10 +1017,18 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, */ public function sortKeysDesc($options = SORT_REGULAR); + /** + * Sort the collection keys using a callback. + * + * @param callable(TKey, TKey): int $callback + * @return static + */ + public function sortKeysUsing(callable $callback); + /** * Get the sum of the given values. * - * @param callable|string|null $callback + * @param (callable(TValue): mixed)|string|null $callback * @return mixed */ public function sum($callback = null); @@ -895,7 +1044,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Take items in the collection until the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function takeUntil($value); @@ -903,7 +1052,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Take items in the collection while the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function takeWhile($value); @@ -911,7 +1060,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Pass the collection to the given callback and then return it. * - * @param callable $callback + * @param callable(TValue): mixed $callback * @return $this */ public function tap(callable $callback); @@ -919,32 +1068,57 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Pass the enumerable to the given callback and return the result. * - * @param callable $callback - * @return mixed + * @template TPipeReturnType + * + * @param callable($this): TPipeReturnType $callback + * @return TPipeReturnType */ public function pipe(callable $callback); + /** + * Pass the collection into a new class. + * + * @param class-string $class + * @return mixed + */ + public function pipeInto($class); + + /** + * Pass the collection through a series of callable pipes and return the result. + * + * @param array $pipes + * @return mixed + */ + public function pipeThrough($pipes); + /** * Get the values of a given key. * - * @param string|array $value + * @param string|array $value * @param string|null $key - * @return static + * @return static */ public function pluck($value, $key = null); /** * Create a collection of all elements that do not pass a given truth test. * - * @param callable|mixed $callback + * @param (callable(TValue, TKey): bool)|bool|TValue $callback * @return static */ public function reject($callback = true); + /** + * Convert a flatten "dot" notation array into an expanded array. + * + * @return static + */ + public function undot(); + /** * Return only unique items from the collection array. * - * @param string|callable|null $key + * @param (callable(TValue, TKey): mixed)|string|null $key * @param bool $strict * @return static */ @@ -953,7 +1127,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Return only unique items from the collection array using strict comparison. * - * @param string|callable|null $key + * @param (callable(TValue, TKey): mixed)|string|null $key * @return static */ public function uniqueStrict($key = null); @@ -961,26 +1135,42 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, /** * Reset the keys on the underlying array. * - * @return static + * @return static */ public function values(); /** * Pad collection to the specified length with a value. * + * @template TPadValue + * * @param int $size - * @param mixed $value - * @return static + * @param TPadValue $value + * @return static */ public function pad($size, $value); /** - * Count the number of items in the collection using a given truth test. + * Get the values iterator. * - * @param callable|null $callback - * @return static + * @return \Traversable */ - public function countBy($callback = null); + public function getIterator(): Traversable; + + /** + * Count the number of items in the collection. + * + * @return int + */ + public function count(): int; + + /** + * Count the number of items in the collection by a field or using a callback. + * + * @param (callable(TValue, TKey): array-key)|string|null $countBy + * @return static + */ + public function countBy($countBy = null); /** * Zip the collection together with one or more arrays. @@ -988,18 +1178,50 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); * => [[1, 4], [2, 5], [3, 6]] * - * @param mixed ...$items - * @return static + * @template TZipValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable ...$items + * @return static> */ public function zip($items); /** * Collect the values into a collection. * - * @return \Tightenco\Collect\Support\Collection + * @return \QL\Collect\Support\Collection */ public function collect(); + /** + * Get the collection of items as a plain array. + * + * @return array + */ + public function toArray(); + + /** + * Convert the object into something JSON serializable. + * + * @return mixed + */ + public function jsonSerialize(): mixed; + + /** + * Get the collection of items as JSON. + * + * @param int $options + * @return string + */ + public function toJson($options = 0); + + /** + * Get a CachingIterator instance. + * + * @param int $flags + * @return \CachingIterator + */ + public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING); + /** * Convert the collection to its string representation. * @@ -1007,6 +1229,14 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, */ public function __toString(); + /** + * Indicate that the model's string representation should be escaped when __toString is invoked. + * + * @param bool $escape + * @return $this + */ + public function escapeWhenCastingToString($escape = true); + /** * Add a method to the list of proxied methods. * diff --git a/vendor/tightenco/collect/src/Collect/Support/HigherOrderCollectionProxy.php b/vendor/jaeger/querylist/src/Collect/Support/HigherOrderCollectionProxy.php similarity index 86% rename from vendor/tightenco/collect/src/Collect/Support/HigherOrderCollectionProxy.php rename to vendor/jaeger/querylist/src/Collect/Support/HigherOrderCollectionProxy.php index 01ac43f..c18f44f 100644 --- a/vendor/tightenco/collect/src/Collect/Support/HigherOrderCollectionProxy.php +++ b/vendor/jaeger/querylist/src/Collect/Support/HigherOrderCollectionProxy.php @@ -1,16 +1,16 @@ + */ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable { + /** + * @use \QL\Collect\Support\Traits\EnumeratesValues + */ use EnumeratesValues, Macroable; /** * The source from which to generate items. * - * @var callable|static + * @var (Closure(): \Generator)|static|array */ public $source; /** * Create a new lazy collection instance. * - * @param mixed $source + * @param \QL\Collect\Contracts\Support\Arrayable|iterable|(Closure(): \Generator)|self|array|null $source * @return void */ public function __construct($source = null) @@ -34,17 +46,35 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable $this->source = $source; } elseif (is_null($source)) { $this->source = static::empty(); + } elseif ($source instanceof Generator) { + throw new InvalidArgumentException( + 'Generators should not be passed directly to LazyCollection. Instead, pass a generator function.' + ); } else { $this->source = $this->getArrayableItems($source); } } + /** + * Create a new collection instance if the value isn't one already. + * + * @template TMakeKey of array-key + * @template TMakeValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable|(Closure(): \Generator)|self|array|null $items + * @return static + */ + public static function make($items = []) + { + return new static($items); + } + /** * Create a collection with the given range. * * @param int $from * @param int $to - * @return static + * @return static */ public static function range($from, $to) { @@ -64,7 +94,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get all items in the enumerable. * - * @return array + * @return array */ public function all() { @@ -126,8 +156,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the average value of a given key. * - * @param callable|string|null $callback - * @return mixed + * @param (callable(TValue): float|int)|string|null $callback + * @return float|int|null */ public function avg($callback = null) { @@ -137,8 +167,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the median of a given key. * - * @param string|array|null $key - * @return mixed + * @param string|array|null $key + * @return float|int|null */ public function median($key = null) { @@ -148,8 +178,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the mode of a given key. * - * @param string|array|null $key - * @return array|null + * @param string|array|null $key + * @return array|null */ public function mode($key = null) { @@ -159,7 +189,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Collapse the collection of items into a single array. * - * @return static + * @return static */ public function collapse() { @@ -177,7 +207,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Determine if an item exists in the enumerable. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value * @return bool @@ -187,6 +217,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable if (func_num_args() === 1 && $this->useAsCallable($key)) { $placeholder = new stdClass; + /** @var callable $key */ return $this->first($key, $placeholder) !== $placeholder; } @@ -205,6 +236,32 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable return $this->contains($this->operatorForWhere(...func_get_args())); } + /** + * Determine if an item exists, using strict comparison. + * + * @param (callable(TValue): bool)|TValue|array-key $key + * @param TValue|null $value + * @return bool + */ + public function containsStrict($key, $value = null) + { + if (func_num_args() === 2) { + return $this->contains(fn ($item) => data_get($item, $key) === $value); + } + + if ($this->useAsCallable($key)) { + return ! is_null($this->first($key)); + } + + foreach ($this as $item) { + if ($item === $key) { + return true; + } + } + + return false; + } + /** * Determine if an item is not contained in the enumerable. * @@ -221,8 +278,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Cross join the given iterables, returning all possible permutations. * - * @param array ...$arrays - * @return static + * @template TCrossJoinKey + * @template TCrossJoinValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable ...$arrays + * @return static> */ public function crossJoin(...$arrays) { @@ -232,8 +292,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Count the number of items in the collection by a field or using a callback. * - * @param callable|string $countBy - * @return static + * @param (callable(TValue, TKey): array-key)|string|null $countBy + * @return static */ public function countBy($countBy = null) { @@ -261,7 +321,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the items that are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diff($items) @@ -272,8 +332,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the items that are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TValue, TValue): int $callback * @return static */ public function diffUsing($items, callable $callback) @@ -284,7 +344,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the items whose keys and values are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diffAssoc($items) @@ -295,8 +355,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the items whose keys and values are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TKey, TKey): int $callback * @return static */ public function diffAssocUsing($items, callable $callback) @@ -307,7 +367,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the items whose keys are not present in the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function diffKeys($items) @@ -318,8 +378,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the items whose keys are not present in the given items, using the callback. * - * @param mixed $items - * @param callable $callback + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TKey, TKey): int $callback * @return static */ public function diffKeysUsing($items, callable $callback) @@ -330,7 +390,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Retrieve duplicate items. * - * @param callable|string|null $callback + * @param (callable(TValue): bool)|string|null $callback * @param bool $strict * @return static */ @@ -342,7 +402,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Retrieve duplicate items using strict comparison. * - * @param callable|string|null $callback + * @param (callable(TValue): bool)|string|null $callback * @return static */ public function duplicatesStrict($callback = null) @@ -353,7 +413,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get all items except for those with the specified keys. * - * @param mixed $keys + * @param \QL\Collect\Support\Enumerable|array $keys * @return static */ public function except($keys) @@ -364,15 +424,13 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Run a filter over each of the items. * - * @param callable|null $callback + * @param (callable(TValue, TKey): bool)|null $callback * @return static */ public function filter(callable $callback = null) { if (is_null($callback)) { - $callback = function ($value) { - return (bool) $value; - }; + $callback = fn ($value) => (bool) $value; } return new static(function () use ($callback) { @@ -387,9 +445,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the first item from the enumerable passing the given truth test. * - * @param callable|null $callback - * @param mixed $default - * @return mixed + * @template TFirstDefault + * + * @param (callable(TValue): bool)|null $callback + * @param TFirstDefault|(\Closure(): TFirstDefault) $default + * @return TValue|TFirstDefault */ public function first(callable $callback = null, $default = null) { @@ -416,7 +476,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * Get a flattened list of the items in the collection. * * @param int $depth - * @return static + * @return static */ public function flatten($depth = INF) { @@ -438,7 +498,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Flip the items in the collection. * - * @return static + * @return static */ public function flip() { @@ -452,9 +512,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get an item by key. * - * @param mixed $key - * @param mixed $default - * @return mixed + * @template TGetDefault + * + * @param TKey|null $key + * @param TGetDefault|(\Closure(): TGetDefault) $default + * @return TValue|TGetDefault */ public function get($key, $default = null) { @@ -474,9 +536,9 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Group an associative array by a field or using a callback. * - * @param array|callable|string $groupBy + * @param (callable(TValue, TKey): array-key)|array|string $groupBy * @param bool $preserveKeys - * @return static + * @return static> */ public function groupBy($groupBy, $preserveKeys = false) { @@ -486,8 +548,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Key an associative array by a field or using a callback. * - * @param callable|string $keyBy - * @return static + * @param (callable(TValue, TKey): array-key)|array|string $keyBy + * @return static */ public function keyBy($keyBy) { @@ -548,7 +610,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Concatenate values of a given key as a string. * - * @param string $value + * @param callable|string $value * @param string|null $glue * @return string */ @@ -560,7 +622,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Intersect the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function intersect($items) @@ -568,10 +630,45 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable return $this->passthru('intersect', func_get_args()); } + /** + * Intersect the collection with the given items, using the callback. + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TValue, TValue): int $callback + * @return static + */ + public function intersectUsing() + { + return $this->passthru('intersectUsing', func_get_args()); + } + + /** + * Intersect the collection with the given items with additional index check. + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @return static + */ + public function intersectAssoc($items) + { + return $this->passthru('intersectAssoc', func_get_args()); + } + + /** + * Intersect the collection with the given items with additional index check, using the callback. + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @param callable(TValue, TValue): int $callback + * @return static + */ + public function intersectAssocUsing($items, callable $callback) + { + return $this->passthru('intersectAssocUsing', func_get_args()); + } + /** * Intersect the collection with the given items by key. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function intersectByKeys($items) @@ -614,7 +711,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the keys of the collection items. * - * @return static + * @return static */ public function keys() { @@ -628,9 +725,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the last item from the collection. * - * @param callable|null $callback - * @param mixed $default - * @return mixed + * @template TLastDefault + * + * @param (callable(TValue, TKey): bool)|null $callback + * @param TLastDefault|(\Closure(): TLastDefault) $default + * @return TValue|TLastDefault */ public function last(callable $callback = null, $default = null) { @@ -648,9 +747,9 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the values of a given key. * - * @param string|array $value + * @param string|array $value * @param string|null $key - * @return static + * @return static */ public function pluck($value, $key = null) { @@ -678,8 +777,10 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Run a map over each of the items. * - * @param callable $callback - * @return static + * @template TMapValue + * + * @param callable(TValue, TKey): TMapValue $callback + * @return static */ public function map(callable $callback) { @@ -695,8 +796,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapToDictionaryKey of array-key + * @template TMapToDictionaryValue + * + * @param callable(TValue, TKey): array $callback + * @return static> */ public function mapToDictionary(callable $callback) { @@ -708,8 +812,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapWithKeysKey of array-key + * @template TMapWithKeysValue + * + * @param callable(TValue, TKey): array $callback + * @return static */ public function mapWithKeys(callable $callback) { @@ -723,7 +830,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Merge the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function merge($items) @@ -734,8 +841,10 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Recursively merge the collection with the given items. * - * @param mixed $items - * @return static + * @template TMergeRecursiveValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items + * @return static */ public function mergeRecursive($items) { @@ -745,8 +854,10 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Create a collection by using this collection for keys and another for its values. * - * @param mixed $values - * @return static + * @template TCombineValue + * + * @param \IteratorAggregate|array|(callable(): \Generator) $values + * @return static */ public function combine($values) { @@ -776,7 +887,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Union the collection with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function union($items) @@ -809,7 +920,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the items with the specified keys. * - * @param mixed $keys + * @param \QL\Collect\Support\Enumerable|array|string $keys * @return static */ public function only($keys) @@ -844,7 +955,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Push all of the given items onto the collection. * - * @param iterable $source + * @param iterable $source * @return static */ public function concat($source) @@ -859,7 +970,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * Get one or a specified number of items randomly from the collection. * * @param int|null $number - * @return static|mixed + * @return static|TValue * * @throws \InvalidArgumentException */ @@ -873,7 +984,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Replace the collection items with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function replace($items) @@ -900,7 +1011,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Recursively replace the collection items with the given items. * - * @param mixed $items + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $items * @return static */ public function replaceRecursive($items) @@ -921,12 +1032,13 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Search the collection for a given value and return the corresponding key if successful. * - * @param mixed $value + * @param TValue|(callable(TValue,TKey): bool) $value * @param bool $strict - * @return mixed + * @return TKey|bool */ public function search($value, $strict = false) { + /** @var (callable(TValue,TKey): bool) $predicate */ $predicate = $this->useAsCallable($value) ? $value : function ($item) use ($value, $strict) { @@ -958,7 +1070,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * * @param int $size * @param int $step - * @return static + * @return static */ public function sliding($size = 2, $step = 1) { @@ -971,7 +1083,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable $chunk[$iterator->key()] = $iterator->current(); if (count($chunk) == $size) { - yield tap(new static($chunk), function () use (&$chunk, $step) { + yield (new static($chunk))->tap(function () use (&$chunk, $step) { $chunk = array_slice($chunk, $step, null, true); }); @@ -1018,7 +1130,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Skip items in the collection until the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function skipUntil($value) @@ -1031,7 +1143,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Skip items in the collection while the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function skipWhile($value) @@ -1075,7 +1187,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * Split a collection into a certain number of groups. * * @param int $numberOfGroups - * @return static + * @return static */ public function split($numberOfGroups) { @@ -1085,13 +1197,13 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|string $key * @param mixed $operator * @param mixed $value - * @return mixed + * @return TValue * - * @throws \Tightenco\Collect\Support\ItemNotFoundException - * @throws \Tightenco\Collect\Support\MultipleItemsFoundException + * @throws \QL\Collect\Support\ItemNotFoundException + * @throws \QL\Collect\Support\MultipleItemsFoundException */ public function sole($key = null, $operator = null, $value = null) { @@ -1100,7 +1212,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable : $key; return $this - ->when($filter) + ->unless($filter == null) ->filter($filter) ->take(2) ->collect() @@ -1110,12 +1222,12 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the first item in the collection but throw an exception if no matching items exist. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|string $key * @param mixed $operator * @param mixed $value - * @return mixed + * @return TValue * - * @throws \Tightenco\Collect\Support\ItemNotFoundException + * @throws \QL\Collect\Support\ItemNotFoundException */ public function firstOrFail($key = null, $operator = null, $value = null) { @@ -1124,7 +1236,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable : $key; return $this - ->when($filter) + ->unless($filter == null) ->filter($filter) ->take(1) ->collect() @@ -1135,7 +1247,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * Chunk the collection into chunks of the given size. * * @param int $size - * @return static + * @return static */ public function chunk($size) { @@ -1174,7 +1286,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * Split a collection into a certain number of groups, and fill the first groups completely. * * @param int $numberOfGroups - * @return static + * @return static */ public function splitIn($numberOfGroups) { @@ -1184,8 +1296,8 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Chunk the collection into chunks with a callback. * - * @param callable $callback - * @return static + * @param callable(TValue, TKey, Collection): bool $callback + * @return static> */ public function chunkWhile(callable $callback) { @@ -1221,7 +1333,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Sort through each item with a callback. * - * @param callable|null|int $callback + * @param (callable(TValue, TValue): int)|null|int $callback * @return static */ public function sort($callback = null) @@ -1243,7 +1355,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Sort the collection using the given callback. * - * @param callable|string $callback + * @param array|(callable(TValue, TKey): mixed)|string $callback * @param int $options * @param bool $descending * @return static @@ -1256,7 +1368,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Sort the collection in descending order using the given callback. * - * @param callable|string $callback + * @param array|(callable(TValue, TKey): mixed)|string $callback * @param int $options * @return static */ @@ -1291,7 +1403,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Sort the collection keys using a callback. * - * @param callable $callback + * @param callable(TKey, TKey): int $callback * @return static */ public function sortKeysUsing(callable $callback) @@ -1331,11 +1443,12 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Take items in the collection until the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function takeUntil($value) { + /** @var callable(TValue, TKey): bool $callback */ $callback = $this->useAsCallable($value) ? $value : $this->equality($value); return new static(function () use ($callback) { @@ -1359,30 +1472,39 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable { $timeout = $timeout->getTimestamp(); - return $this->takeWhile(function () use ($timeout) { - return $this->now() < $timeout; + return new static(function () use ($timeout) { + if ($this->now() >= $timeout) { + return; + } + + foreach ($this as $key => $value) { + yield $key => $value; + + if ($this->now() >= $timeout) { + break; + } + } }); } /** * Take items in the collection while the given condition is met. * - * @param mixed $value + * @param TValue|callable(TValue,TKey): bool $value * @return static */ public function takeWhile($value) { + /** @var callable(TValue, TKey): bool $callback */ $callback = $this->useAsCallable($value) ? $value : $this->equality($value); - return $this->takeUntil(function ($item, $key) use ($callback) { - return ! $callback($item, $key); - }); + return $this->takeUntil(fn ($item, $key) => ! $callback($item, $key)); } /** * Pass each item in the collection to the given callback, lazily. * - * @param callable $callback + * @param callable(TValue, TKey): mixed $callback * @return static */ public function tapEach(callable $callback) @@ -1409,7 +1531,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Return only unique items from the collection array. * - * @param string|callable|null $key + * @param (callable(TValue, TKey): mixed)|string|null $key * @param bool $strict * @return static */ @@ -1433,7 +1555,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Reset the keys on the underlying array. * - * @return static + * @return static */ public function values() { @@ -1450,8 +1572,10 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * e.g. new LazyCollection([1, 2, 3])->zip([4, 5, 6]); * => [[1, 4], [2, 5], [3, 6]] * - * @param mixed ...$items - * @return static + * @template TZipValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable ...$items + * @return static> */ public function zip($items) { @@ -1473,9 +1597,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Pad collection to the specified length with a value. * + * @template TPadValue + * * @param int $size - * @param mixed $value - * @return static + * @param TPadValue $value + * @return static */ public function pad($size, $value) { @@ -1501,10 +1627,9 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Get the values iterator. * - * @return \Traversable + * @return \Traversable */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { return $this->makeIterator($this->source); } @@ -1514,8 +1639,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * * @return int */ - #[\ReturnTypeWillChange] - public function count() + public function count(): int { if (is_array($this->source)) { return count($this->source); @@ -1527,8 +1651,11 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable /** * Make an iterator from the given source. * - * @param mixed $source - * @return \Traversable + * @template TIteratorKey of array-key + * @template TIteratorValue + * + * @param \IteratorAggregate|array|(callable(): \Generator) $source + * @return \Traversable */ protected function makeIterator($source) { @@ -1540,15 +1667,23 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable return new ArrayIterator($source); } - return $source(); + if (is_callable($source)) { + $maybeTraversable = $source(); + + return $maybeTraversable instanceof Traversable + ? $maybeTraversable + : new ArrayIterator(Arr::wrap($maybeTraversable)); + } + + return new ArrayIterator((array) $source); } /** * Explode the "value" and "key" arguments passed to "pluck". * - * @param string|array $value - * @param string|array|null $key - * @return array + * @param string|string[] $value + * @param string|string[]|null $key + * @return array{string[],string[]|null} */ protected function explodePluckParameters($value, $key) { @@ -1563,7 +1698,7 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable * Pass this lazy collection through a method on the collection class. * * @param string $method - * @param array $params + * @param array $params * @return static */ protected function passthru($method, array $params) diff --git a/vendor/jaeger/querylist/src/Collect/Support/Str.php b/vendor/jaeger/querylist/src/Collect/Support/Str.php new file mode 100644 index 0000000..04fcef3 --- /dev/null +++ b/vendor/jaeger/querylist/src/Collect/Support/Str.php @@ -0,0 +1,1367 @@ + $needles + * @param bool $ignoreCase + * @return bool + */ + public static function contains($haystack, $needles, $ignoreCase = false) + { + if ($ignoreCase) { + $haystack = mb_strtolower($haystack); + } + + if (! is_iterable($needles)) { + $needles = (array) $needles; + } + + foreach ($needles as $needle) { + if ($ignoreCase) { + $needle = mb_strtolower($needle); + } + + if ($needle !== '' && str_contains($haystack, $needle)) { + return true; + } + } + + return false; + } + + /** + * Determine if a given string contains all array values. + * + * @param string $haystack + * @param iterable $needles + * @param bool $ignoreCase + * @return bool + */ + public static function containsAll($haystack, $needles, $ignoreCase = false) + { + foreach ($needles as $needle) { + if (! static::contains($haystack, $needle, $ignoreCase)) { + return false; + } + } + + return true; + } + + /** + * Determine if a given string ends with a given substring. + * + * @param string $haystack + * @param string|iterable $needles + * @return bool + */ + public static function endsWith($haystack, $needles) + { + if (! is_iterable($needles)) { + $needles = (array) $needles; + } + + foreach ($needles as $needle) { + if ((string) $needle !== '' && str_ends_with($haystack, $needle)) { + return true; + } + } + + return false; + } + + /** + * Extracts an excerpt from text that matches the first instance of a phrase. + * + * @param string $text + * @param string $phrase + * @param array $options + * @return string|null + */ + public static function excerpt($text, $phrase = '', $options = []) + { + $radius = $options['radius'] ?? 100; + $omission = $options['omission'] ?? '...'; + + preg_match('/^(.*?)('.preg_quote((string) $phrase).')(.*)$/iu', (string) $text, $matches); + + if (empty($matches)) { + return null; + } + + $start = ltrim($matches[1]); + + $start = str(mb_substr($start, max(mb_strlen($start, 'UTF-8') - $radius, 0), $radius, 'UTF-8'))->ltrim()->unless( + fn ($startWithRadius) => $startWithRadius->exactly($start), + fn ($startWithRadius) => $startWithRadius->prepend($omission), + ); + + $end = rtrim($matches[3]); + + $end = str(mb_substr($end, 0, $radius, 'UTF-8'))->rtrim()->unless( + fn ($endWithRadius) => $endWithRadius->exactly($end), + fn ($endWithRadius) => $endWithRadius->append($omission), + ); + + return $start->append($matches[2], $end)->toString(); + } + + /** + * Cap a string with a single instance of a given value. + * + * @param string $value + * @param string $cap + * @return string + */ + public static function finish($value, $cap) + { + $quoted = preg_quote($cap, '/'); + + return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; + } + + /** + * Wrap the string with the given strings. + * + * @param string $value + * @param string $before + * @param string|null $after + * @return string + */ + public static function wrap($value, $before, $after = null) + { + return $before.$value.($after ??= $before); + } + + /** + * Determine if a given string matches a given pattern. + * + * @param string|iterable $pattern + * @param string $value + * @return bool + */ + public static function is($pattern, $value) + { + $value = (string) $value; + + if (! is_iterable($pattern)) { + $pattern = [$pattern]; + } + + foreach ($pattern as $pattern) { + $pattern = (string) $pattern; + + // If the given value is an exact match we can of course return true right + // from the beginning. Otherwise, we will translate asterisks and do an + // actual pattern match against the two strings to see if they match. + if ($pattern === $value) { + return true; + } + + $pattern = preg_quote($pattern, '#'); + + // Asterisks are translated into zero-or-more regular expression wildcards + // to make it convenient to check if the strings starts with the given + // pattern such as "library/*", making any string check convenient. + $pattern = str_replace('\*', '.*', $pattern); + + if (preg_match('#^'.$pattern.'\z#u', $value) === 1) { + return true; + } + } + + return false; + } + + /** + * Determine if a given string is 7 bit ASCII. + * + * @param string $value + * @return bool + */ + public static function isAscii($value) + { + return ASCII::is_ascii((string) $value); + } + + /** + * Determine if a given string is valid JSON. + * + * @param string $value + * @return bool + */ + public static function isJson($value) + { + if (! is_string($value)) { + return false; + } + + try { + json_decode($value, true, 512, JSON_THROW_ON_ERROR); + } catch (JsonException) { + return false; + } + + return true; + } + + /** + * Determine if a given string is a valid UUID. + * + * @param string $value + * @return bool + */ + public static function isUuid($value) + { + if (! is_string($value)) { + return false; + } + + return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0; + } + + /** + * Determine if a given string is a valid ULID. + * + * @param string $value + * @return bool + */ + public static function isUlid($value) + { + if (! is_string($value)) { + return false; + } + + return Ulid::isValid($value); + } + + /** + * Convert a string to kebab case. + * + * @param string $value + * @return string + */ + public static function kebab($value) + { + return static::snake($value, '-'); + } + + /** + * Return the length of the given string. + * + * @param string $value + * @param string|null $encoding + * @return int + */ + public static function length($value, $encoding = null) + { + if ($encoding) { + return mb_strlen($value, $encoding); + } + + return mb_strlen($value); + } + + /** + * Limit the number of characters in a string. + * + * @param string $value + * @param int $limit + * @param string $end + * @return string + */ + public static function limit($value, $limit = 100, $end = '...') + { + if (mb_strwidth($value, 'UTF-8') <= $limit) { + return $value; + } + + return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; + } + + /** + * Convert the given string to lower-case. + * + * @param string $value + * @return string + */ + public static function lower($value) + { + return mb_strtolower($value, 'UTF-8'); + } + + /** + * Limit the number of words in a string. + * + * @param string $value + * @param int $words + * @param string $end + * @return string + */ + public static function words($value, $words = 100, $end = '...') + { + preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); + + if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { + return $value; + } + + return rtrim($matches[0]).$end; + } + + /** + * Converts GitHub flavored Markdown into HTML. + * + * @param string $string + * @param array $options + * @return string + */ + public static function markdown($string, array $options = []) + { + $converter = new GithubFlavoredMarkdownConverter($options); + + return (string) $converter->convert($string); + } + + /** + * Converts inline Markdown into HTML. + * + * @param string $string + * @param array $options + * @return string + */ + public static function inlineMarkdown($string, array $options = []) + { + $environment = new Environment($options); + + $environment->addExtension(new GithubFlavoredMarkdownExtension()); + $environment->addExtension(new InlinesOnlyExtension()); + + $converter = new MarkdownConverter($environment); + + return (string) $converter->convert($string); + } + + /** + * Masks a portion of a string with a repeated character. + * + * @param string $string + * @param string $character + * @param int $index + * @param int|null $length + * @param string $encoding + * @return string + */ + public static function mask($string, $character, $index, $length = null, $encoding = 'UTF-8') + { + if ($character === '') { + return $string; + } + + $segment = mb_substr($string, $index, $length, $encoding); + + if ($segment === '') { + return $string; + } + + $strlen = mb_strlen($string, $encoding); + $startIndex = $index; + + if ($index < 0) { + $startIndex = $index < -$strlen ? 0 : $strlen + $index; + } + + $start = mb_substr($string, 0, $startIndex, $encoding); + $segmentLen = mb_strlen($segment, $encoding); + $end = mb_substr($string, $startIndex + $segmentLen); + + return $start.str_repeat(mb_substr($character, 0, 1, $encoding), $segmentLen).$end; + } + + /** + * Get the string matching the given pattern. + * + * @param string $pattern + * @param string $subject + * @return string + */ + public static function match($pattern, $subject) + { + preg_match($pattern, $subject, $matches); + + if (! $matches) { + return ''; + } + + return $matches[1] ?? $matches[0]; + } + + /** + * Get the string matching the given pattern. + * + * @param string $pattern + * @param string $subject + * @return \QL\Collect\Support\Collection + */ + public static function matchAll($pattern, $subject) + { + preg_match_all($pattern, $subject, $matches); + + if (empty($matches[0])) { + return collect(); + } + + return collect($matches[1] ?? $matches[0]); + } + + /** + * Pad both sides of a string with another. + * + * @param string $value + * @param int $length + * @param string $pad + * @return string + */ + public static function padBoth($value, $length, $pad = ' ') + { + $short = max(0, $length - mb_strlen($value)); + $shortLeft = floor($short / 2); + $shortRight = ceil($short / 2); + + return mb_substr(str_repeat($pad, $shortLeft), 0, $shortLeft). + $value. + mb_substr(str_repeat($pad, $shortRight), 0, $shortRight); + } + + /** + * Pad the left side of a string with another. + * + * @param string $value + * @param int $length + * @param string $pad + * @return string + */ + public static function padLeft($value, $length, $pad = ' ') + { + $short = max(0, $length - mb_strlen($value)); + + return mb_substr(str_repeat($pad, $short), 0, $short).$value; + } + + /** + * Pad the right side of a string with another. + * + * @param string $value + * @param int $length + * @param string $pad + * @return string + */ + public static function padRight($value, $length, $pad = ' ') + { + $short = max(0, $length - mb_strlen($value)); + + return $value.mb_substr(str_repeat($pad, $short), 0, $short); + } + + /** + * Parse a Class[@]method style callback into class and method. + * + * @param string $callback + * @param string|null $default + * @return array + */ + public static function parseCallback($callback, $default = null) + { + return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; + } + + /** + * Get the plural form of an English word. + * + * @param string $value + * @param int|array|\Countable $count + * @return string + */ + public static function plural($value, $count = 2) + { + return Pluralizer::plural($value, $count); + } + + /** + * Pluralize the last word of an English, studly caps case string. + * + * @param string $value + * @param int|array|\Countable $count + * @return string + */ + public static function pluralStudly($value, $count = 2) + { + $parts = preg_split('/(.)(?=[A-Z])/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE); + + $lastWord = array_pop($parts); + + return implode('', $parts).self::plural($lastWord, $count); + } + + /** + * Generate a more truly "random" alpha-numeric string. + * + * @param int $length + * @return string + */ + public static function random($length = 16) + { + return (static::$randomStringFactory ?? function ($length) { + $string = ''; + + while (($len = strlen($string)) < $length) { + $size = $length - $len; + + $bytesSize = (int) ceil($size / 3) * 3; + + $bytes = random_bytes($bytesSize); + + $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); + } + + return $string; + })($length); + } + + /** + * Set the callable that will be used to generate random strings. + * + * @param callable|null $factory + * @return void + */ + public static function createRandomStringsUsing(callable $factory = null) + { + static::$randomStringFactory = $factory; + } + + /** + * Set the sequence that will be used to generate random strings. + * + * @param array $sequence + * @param callable|null $whenMissing + * @return void + */ + public static function createRandomStringsUsingSequence(array $sequence, $whenMissing = null) + { + $next = 0; + + $whenMissing ??= function ($length) use (&$next) { + $factoryCache = static::$randomStringFactory; + + static::$randomStringFactory = null; + + $randomString = static::random($length); + + static::$randomStringFactory = $factoryCache; + + $next++; + + return $randomString; + }; + + static::createRandomStringsUsing(function ($length) use (&$next, $sequence, $whenMissing) { + if (array_key_exists($next, $sequence)) { + return $sequence[$next++]; + } + + return $whenMissing($length); + }); + } + + /** + * Indicate that random strings should be created normally and not using a custom factory. + * + * @return void + */ + public static function createRandomStringsNormally() + { + static::$randomStringFactory = null; + } + + /** + * Repeat the given string. + * + * @param string $string + * @param int $times + * @return string + */ + public static function repeat(string $string, int $times) + { + return str_repeat($string, $times); + } + + /** + * Replace a given value in the string sequentially with an array. + * + * @param string $search + * @param iterable $replace + * @param string $subject + * @return string + */ + public static function replaceArray($search, $replace, $subject) + { + if ($replace instanceof Traversable) { + $replace = collect($replace)->all(); + } + + $segments = explode($search, $subject); + + $result = array_shift($segments); + + foreach ($segments as $segment) { + $result .= (array_shift($replace) ?? $search).$segment; + } + + return $result; + } + + /** + * Replace the given value in the given string. + * + * @param string|iterable $search + * @param string|iterable $replace + * @param string|iterable $subject + * @return string + */ + public static function replace($search, $replace, $subject) + { + if ($search instanceof Traversable) { + $search = collect($search)->all(); + } + + if ($replace instanceof Traversable) { + $replace = collect($replace)->all(); + } + + if ($subject instanceof Traversable) { + $subject = collect($subject)->all(); + } + + return str_replace($search, $replace, $subject); + } + + /** + * Replace the first occurrence of a given value in the string. + * + * @param string $search + * @param string $replace + * @param string $subject + * @return string + */ + public static function replaceFirst($search, $replace, $subject) + { + $search = (string) $search; + + if ($search === '') { + return $subject; + } + + $position = strpos($subject, $search); + + if ($position !== false) { + return substr_replace($subject, $replace, $position, strlen($search)); + } + + return $subject; + } + + /** + * Replace the last occurrence of a given value in the string. + * + * @param string $search + * @param string $replace + * @param string $subject + * @return string + */ + public static function replaceLast($search, $replace, $subject) + { + if ($search === '') { + return $subject; + } + + $position = strrpos($subject, $search); + + if ($position !== false) { + return substr_replace($subject, $replace, $position, strlen($search)); + } + + return $subject; + } + + /** + * Remove any occurrence of the given string in the subject. + * + * @param string|iterable $search + * @param string $subject + * @param bool $caseSensitive + * @return string + */ + public static function remove($search, $subject, $caseSensitive = true) + { + if ($search instanceof Traversable) { + $search = collect($search)->all(); + } + + $subject = $caseSensitive + ? str_replace($search, '', $subject) + : str_ireplace($search, '', $subject); + + return $subject; + } + + /** + * Reverse the given string. + * + * @param string $value + * @return string + */ + public static function reverse(string $value) + { + return implode(array_reverse(mb_str_split($value))); + } + + /** + * Begin a string with a single instance of a given value. + * + * @param string $value + * @param string $prefix + * @return string + */ + public static function start($value, $prefix) + { + $quoted = preg_quote($prefix, '/'); + + return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value); + } + + /** + * Convert the given string to upper-case. + * + * @param string $value + * @return string + */ + public static function upper($value) + { + return mb_strtoupper($value, 'UTF-8'); + } + + /** + * Convert the given string to title case. + * + * @param string $value + * @return string + */ + public static function title($value) + { + return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); + } + + /** + * Convert the given string to title case for each word. + * + * @param string $value + * @return string + */ + public static function headline($value) + { + $parts = explode(' ', $value); + + $parts = count($parts) > 1 + ? array_map([static::class, 'title'], $parts) + : array_map([static::class, 'title'], static::ucsplit(implode('_', $parts))); + + $collapsed = static::replace(['-', '_', ' '], '_', implode('_', $parts)); + + return implode(' ', array_filter(explode('_', $collapsed))); + } + + /** + * Get the singular form of an English word. + * + * @param string $value + * @return string + */ + public static function singular($value) + { + return Pluralizer::singular($value); + } + + /** + * Generate a URL friendly "slug" from a given string. + * + * @param string $title + * @param string $separator + * @param string|null $language + * @param array $dictionary + * @return string + */ + public static function slug($title, $separator = '-', $language = 'en', $dictionary = ['@' => 'at']) + { + $title = $language ? static::ascii($title, $language) : $title; + + // Convert all dashes/underscores into separator + $flip = $separator === '-' ? '_' : '-'; + + $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); + + // Replace dictionary words + foreach ($dictionary as $key => $value) { + $dictionary[$key] = $separator.$value.$separator; + } + + $title = str_replace(array_keys($dictionary), array_values($dictionary), $title); + + // Remove all characters that are not the separator, letters, numbers, or whitespace + $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', static::lower($title)); + + // Replace all separator characters and whitespace by a single separator + $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); + + return trim($title, $separator); + } + + /** + * Convert a string to snake case. + * + * @param string $value + * @param string $delimiter + * @return string + */ + public static function snake($value, $delimiter = '_') + { + $key = $value; + + if (isset(static::$snakeCache[$key][$delimiter])) { + return static::$snakeCache[$key][$delimiter]; + } + + if (! ctype_lower($value)) { + $value = preg_replace('/\s+/u', '', ucwords($value)); + + $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); + } + + return static::$snakeCache[$key][$delimiter] = $value; + } + + /** + * Remove all "extra" blank space from the given string. + * + * @param string $value + * @return string + */ + public static function squish($value) + { + return preg_replace('~(\s|\x{3164})+~u', ' ', preg_replace('~^[\s\x{FEFF}]+|[\s\x{FEFF}]+$~u', '', $value)); + } + + /** + * Determine if a given string starts with a given substring. + * + * @param string $haystack + * @param string|iterable $needles + * @return bool + */ + public static function startsWith($haystack, $needles) + { + if (! is_iterable($needles)) { + $needles = [$needles]; + } + + foreach ($needles as $needle) { + if ((string) $needle !== '' && str_starts_with($haystack, $needle)) { + return true; + } + } + + return false; + } + + /** + * Convert a value to studly caps case. + * + * @param string $value + * @return string + */ + public static function studly($value) + { + $key = $value; + + if (isset(static::$studlyCache[$key])) { + return static::$studlyCache[$key]; + } + + $words = explode(' ', static::replace(['-', '_'], ' ', $value)); + + $studlyWords = array_map(fn ($word) => static::ucfirst($word), $words); + + return static::$studlyCache[$key] = implode($studlyWords); + } + + /** + * Returns the portion of the string specified by the start and length parameters. + * + * @param string $string + * @param int $start + * @param int|null $length + * @param string $encoding + * @return string + */ + public static function substr($string, $start, $length = null, $encoding = 'UTF-8') + { + return mb_substr($string, $start, $length, $encoding); + } + + /** + * Returns the number of substring occurrences. + * + * @param string $haystack + * @param string $needle + * @param int $offset + * @param int|null $length + * @return int + */ + public static function substrCount($haystack, $needle, $offset = 0, $length = null) + { + if (! is_null($length)) { + return substr_count($haystack, $needle, $offset, $length); + } + + return substr_count($haystack, $needle, $offset); + } + + /** + * Replace text within a portion of a string. + * + * @param string|string[] $string + * @param string|string[] $replace + * @param int|int[] $offset + * @param int|int[]|null $length + * @return string|string[] + */ + public static function substrReplace($string, $replace, $offset = 0, $length = null) + { + if ($length === null) { + $length = strlen($string); + } + + return substr_replace($string, $replace, $offset, $length); + } + + /** + * Swap multiple keywords in a string with other keywords. + * + * @param array $map + * @param string $subject + * @return string + */ + public static function swap(array $map, $subject) + { + return strtr($subject, $map); + } + + /** + * Make a string's first character lowercase. + * + * @param string $string + * @return string + */ + public static function lcfirst($string) + { + return static::lower(static::substr($string, 0, 1)).static::substr($string, 1); + } + + /** + * Make a string's first character uppercase. + * + * @param string $string + * @return string + */ + public static function ucfirst($string) + { + return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); + } + + /** + * Split a string into pieces by uppercase characters. + * + * @param string $string + * @return string[] + */ + public static function ucsplit($string) + { + return preg_split('/(?=\p{Lu})/u', $string, -1, PREG_SPLIT_NO_EMPTY); + } + + /** + * Get the number of words a string contains. + * + * @param string $string + * @param string|null $characters + * @return int + */ + public static function wordCount($string, $characters = null) + { + return str_word_count($string, 0, $characters); + } + + /** + * Generate a UUID (version 4). + * + * @return \Ramsey\Uuid\UuidInterface + */ + public static function uuid() + { + return static::$uuidFactory + ? call_user_func(static::$uuidFactory) + : Uuid::uuid4(); + } + + /** + * Generate a time-ordered UUID (version 4). + * + * @return \Ramsey\Uuid\UuidInterface + */ + public static function orderedUuid() + { + if (static::$uuidFactory) { + return call_user_func(static::$uuidFactory); + } + + $factory = new UuidFactory; + + $factory->setRandomGenerator(new CombGenerator( + $factory->getRandomGenerator(), + $factory->getNumberConverter() + )); + + $factory->setCodec(new TimestampFirstCombCodec( + $factory->getUuidBuilder() + )); + + return $factory->uuid4(); + } + + /** + * Set the callable that will be used to generate UUIDs. + * + * @param callable|null $factory + * @return void + */ + public static function createUuidsUsing(callable $factory = null) + { + static::$uuidFactory = $factory; + } + + /** + * Set the sequence that will be used to generate UUIDs. + * + * @param array $sequence + * @param callable|null $whenMissing + * @return void + */ + public static function createUuidsUsingSequence(array $sequence, $whenMissing = null) + { + $next = 0; + + $whenMissing ??= function () use (&$next) { + $factoryCache = static::$uuidFactory; + + static::$uuidFactory = null; + + $uuid = static::uuid(); + + static::$uuidFactory = $factoryCache; + + $next++; + + return $uuid; + }; + + static::createUuidsUsing(function () use (&$next, $sequence, $whenMissing) { + if (array_key_exists($next, $sequence)) { + return $sequence[$next++]; + } + + return $whenMissing(); + }); + } + + /** + * Always return the same UUID when generating new UUIDs. + * + * @param \Closure|null $callback + * @return \Ramsey\Uuid\UuidInterface + */ + public static function freezeUuids(Closure $callback = null) + { + $uuid = Str::uuid(); + + Str::createUuidsUsing(fn () => $uuid); + + if ($callback !== null) { + try { + $callback($uuid); + } finally { + Str::createUuidsNormally(); + } + } + + return $uuid; + } + + /** + * Indicate that UUIDs should be created normally and not using a custom factory. + * + * @return void + */ + public static function createUuidsNormally() + { + static::$uuidFactory = null; + } + + /** + * Generate a ULID. + * + * @return \Symfony\Component\Uid\Ulid + */ + public static function ulid() + { + return new Ulid(); + } + + /** + * Remove all strings from the casing caches. + * + * @return void + */ + public static function flushCache() + { + static::$snakeCache = []; + static::$camelCache = []; + static::$studlyCache = []; + } +} diff --git a/vendor/jaeger/querylist/src/Collect/Support/Traits/Conditionable.php b/vendor/jaeger/querylist/src/Collect/Support/Traits/Conditionable.php new file mode 100644 index 0000000..ee246d4 --- /dev/null +++ b/vendor/jaeger/querylist/src/Collect/Support/Traits/Conditionable.php @@ -0,0 +1,73 @@ +condition($value); + } + + if ($value) { + return $callback($this, $value) ?? $this; + } elseif ($default) { + return $default($this, $value) ?? $this; + } + + return $this; + } + + /** + * Apply the callback if the given "value" is (or resolves to) falsy. + * + * @template TUnlessParameter + * @template TUnlessReturnType + * + * @param (\Closure($this): TUnlessParameter)|TUnlessParameter|null $value + * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $callback + * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $default + * @return $this|TUnlessReturnType + */ + public function unless($value = null, callable $callback = null, callable $default = null) + { + $value = $value instanceof Closure ? $value($this) : $value; + + if (func_num_args() === 0) { + return (new HigherOrderWhenProxy($this))->negateConditionOnCapture(); + } + + if (func_num_args() === 1) { + return (new HigherOrderWhenProxy($this))->condition(! $value); + } + + if (! $value) { + return $callback($this, $value) ?? $this; + } elseif ($default) { + return $default($this, $value) ?? $this; + } + + return $this; + } +} diff --git a/vendor/tightenco/collect/src/Collect/Support/Traits/EnumeratesValues.php b/vendor/jaeger/querylist/src/Collect/Support/Traits/EnumeratesValues.php similarity index 73% rename from vendor/tightenco/collect/src/Collect/Support/Traits/EnumeratesValues.php rename to vendor/jaeger/querylist/src/Collect/Support/Traits/EnumeratesValues.php index 2f1187f..4fe41f7 100644 --- a/vendor/tightenco/collect/src/Collect/Support/Traits/EnumeratesValues.php +++ b/vendor/jaeger/querylist/src/Collect/Support/Traits/EnumeratesValues.php @@ -1,17 +1,16 @@ */ protected static $proxies = [ 'average', @@ -86,14 +92,19 @@ trait EnumeratesValues 'takeUntil', 'takeWhile', 'unique', + 'unless', 'until', + 'when', ]; /** * Create a new collection instance if the value isn't one already. * - * @param mixed $items - * @return static + * @template TMakeKey of array-key + * @template TMakeValue + * + * @param \QL\Collect\Contracts\Support\Arrayable|iterable|null $items + * @return static */ public static function make($items = []) { @@ -103,8 +114,10 @@ trait EnumeratesValues /** * Wrap the given value in a collection if applicable. * - * @param mixed $value - * @return static + * @template TWrapValue + * + * @param iterable|TWrapValue $value + * @return static */ public static function wrap($value) { @@ -116,8 +129,11 @@ trait EnumeratesValues /** * Get the underlying items from the given collection if applicable. * - * @param array|static $value - * @return array + * @template TUnwrapKey of array-key + * @template TUnwrapValue + * + * @param array|static $value + * @return array */ public static function unwrap($value) { @@ -137,9 +153,11 @@ trait EnumeratesValues /** * Create a new collection by invoking the callback a given amount of times. * + * @template TTimesValue + * * @param int $number - * @param callable|null $callback - * @return static + * @param (callable(int): TTimesValue)|null $callback + * @return static */ public static function times($number, callable $callback = null) { @@ -148,15 +166,15 @@ trait EnumeratesValues } return static::range(1, $number) - ->when($callback) + ->unless($callback == null) ->map($callback); } /** * Alias for the "avg" method. * - * @param callable|string|null $callback - * @return mixed + * @param (callable(TValue): float|int)|string|null $callback + * @return float|int|null */ public function average($callback = null) { @@ -166,7 +184,7 @@ trait EnumeratesValues /** * Alias for the "contains" method. * - * @param mixed $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value * @return bool @@ -176,39 +194,11 @@ trait EnumeratesValues return $this->contains(...func_get_args()); } - /** - * Determine if an item exists, using strict comparison. - * - * @param mixed $key - * @param mixed $value - * @return bool - */ - public function containsStrict($key, $value = null) - { - if (func_num_args() === 2) { - return $this->contains(function ($item) use ($key, $value) { - return data_get($item, $key) === $value; - }); - } - - if ($this->useAsCallable($key)) { - return ! is_null($this->first($key)); - } - - foreach ($this as $item) { - if ($item === $key) { - return true; - } - } - - return false; - } - /** * Dump the items and end the script. * * @param mixed ...$args - * @return void + * @return never */ public function dd(...$args) { @@ -236,7 +226,7 @@ trait EnumeratesValues /** * Execute a callback over each item. * - * @param callable $callback + * @param callable(TValue, TKey): mixed $callback * @return $this */ public function each(callable $callback) @@ -253,7 +243,7 @@ trait EnumeratesValues /** * Execute a callback over each nested chunk of items. * - * @param callable $callback + * @param callable(...mixed): mixed $callback * @return static */ public function eachSpread(callable $callback) @@ -268,7 +258,7 @@ trait EnumeratesValues /** * Determine if all items pass the given truth test. * - * @param string|callable $key + * @param (callable(TValue, TKey): bool)|TValue|string $key * @param mixed $operator * @param mixed $value * @return bool @@ -293,16 +283,32 @@ trait EnumeratesValues /** * Get the first item by the given key value pair. * - * @param string $key + * @param callable|string $key * @param mixed $operator * @param mixed $value - * @return mixed + * @return TValue|null */ public function firstWhere($key, $operator = null, $value = null) { return $this->first($this->operatorForWhere(...func_get_args())); } + /** + * Get a single key's value from the first matching item in the collection. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function value($key, $default = null) + { + if ($value = $this->firstWhere($key)) { + return data_get($value, $key, $default); + } + + return value($default); + } + /** * Determine if the collection is not empty. * @@ -316,8 +322,10 @@ trait EnumeratesValues /** * Run a map over each nested chunk of items. * - * @param callable $callback - * @return static + * @template TMapSpreadValue + * + * @param callable(mixed): TMapSpreadValue $callback + * @return static */ public function mapSpread(callable $callback) { @@ -333,8 +341,11 @@ trait EnumeratesValues * * The callback should return an associative array with a single key/value pair. * - * @param callable $callback - * @return static + * @template TMapToGroupsKey of array-key + * @template TMapToGroupsValue + * + * @param callable(TValue, TKey): array $callback + * @return static> */ public function mapToGroups(callable $callback) { @@ -346,8 +357,11 @@ trait EnumeratesValues /** * Map a collection and flatten the result by a single level. * - * @param callable $callback - * @return static + * @template TFlatMapKey of array-key + * @template TFlatMapValue + * + * @param callable(TValue, TKey): (\QL\Collect\Support\Collection|array) $callback + * @return static */ public function flatMap(callable $callback) { @@ -357,48 +371,42 @@ trait EnumeratesValues /** * Map the values into a new class. * - * @param string $class - * @return static + * @template TMapIntoValue + * + * @param class-string $class + * @return static */ public function mapInto($class) { - return $this->map(function ($value, $key) use ($class) { - return new $class($value, $key); - }); + return $this->map(fn ($value, $key) => new $class($value, $key)); } /** * Get the min value of a given key. * - * @param callable|string|null $callback + * @param (callable(TValue):mixed)|string|null $callback * @return mixed */ public function min($callback = null) { $callback = $this->valueRetriever($callback); - return $this->map(function ($value) use ($callback) { - return $callback($value); - })->filter(function ($value) { - return ! is_null($value); - })->reduce(function ($result, $value) { - return is_null($result) || $value < $result ? $value : $result; - }); + return $this->map(fn ($value) => $callback($value)) + ->filter(fn ($value) => ! is_null($value)) + ->reduce(fn ($result, $value) => is_null($result) || $value < $result ? $value : $result); } /** * Get the max value of a given key. * - * @param callable|string|null $callback + * @param (callable(TValue):mixed)|string|null $callback * @return mixed */ public function max($callback = null) { $callback = $this->valueRetriever($callback); - return $this->filter(function ($value) { - return ! is_null($value); - })->reduce(function ($result, $item) use ($callback) { + return $this->filter(fn ($value) => ! is_null($value))->reduce(function ($result, $item) use ($callback) { $value = $callback($item); return is_null($result) || $value > $result ? $value : $result; @@ -422,10 +430,10 @@ trait EnumeratesValues /** * Partition the collection into two arrays using the given callback or key. * - * @param callable|string $key - * @param mixed $operator - * @param mixed $value - * @return static + * @param (callable(TValue, TKey): bool)|TValue|string $key + * @param TValue|string|null $operator + * @param TValue|null $value + * @return static, static> */ public function partition($key, $operator = null, $value = null) { @@ -450,7 +458,7 @@ trait EnumeratesValues /** * Get the sum of the given values. * - * @param callable|string|null $callback + * @param (callable(TValue): mixed)|string|null $callback * @return mixed */ public function sum($callback = null) @@ -459,40 +467,17 @@ trait EnumeratesValues ? $this->identity() : $this->valueRetriever($callback); - return $this->reduce(function ($result, $item) use ($callback) { - return $result + $callback($item); - }, 0); - } - - /** - * Apply the callback if the value is truthy. - * - * @param bool|mixed $value - * @param callable|null $callback - * @param callable|null $default - * @return static|mixed - */ - public function when($value, callable $callback = null, callable $default = null) - { - if (! $callback) { - return new HigherOrderWhenProxy($this, $value); - } - - if ($value) { - return $callback($this, $value); - } elseif ($default) { - return $default($this, $value); - } - - return $this; + return $this->reduce(fn ($result, $item) => $result + $callback($item), 0); } /** * Apply the callback if the collection is empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TWhenEmptyReturnType + * + * @param (callable($this): TWhenEmptyReturnType) $callback + * @param (callable($this): TWhenEmptyReturnType)|null $default + * @return $this|TWhenEmptyReturnType */ public function whenEmpty(callable $callback, callable $default = null) { @@ -502,34 +487,25 @@ trait EnumeratesValues /** * Apply the callback if the collection is not empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TWhenNotEmptyReturnType + * + * @param callable($this): TWhenNotEmptyReturnType $callback + * @param (callable($this): TWhenNotEmptyReturnType)|null $default + * @return $this|TWhenNotEmptyReturnType */ public function whenNotEmpty(callable $callback, callable $default = null) { return $this->when($this->isNotEmpty(), $callback, $default); } - /** - * Apply the callback if the value is falsy. - * - * @param bool $value - * @param callable $callback - * @param callable|null $default - * @return static|mixed - */ - public function unless($value, callable $callback, callable $default = null) - { - return $this->when(! $value, $callback, $default); - } - /** * Apply the callback unless the collection is empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TUnlessEmptyReturnType + * + * @param callable($this): TUnlessEmptyReturnType $callback + * @param (callable($this): TUnlessEmptyReturnType)|null $default + * @return $this|TUnlessEmptyReturnType */ public function unlessEmpty(callable $callback, callable $default = null) { @@ -539,9 +515,11 @@ trait EnumeratesValues /** * Apply the callback unless the collection is not empty. * - * @param callable $callback - * @param callable|null $default - * @return static|mixed + * @template TUnlessNotEmptyReturnType + * + * @param callable($this): TUnlessNotEmptyReturnType $callback + * @param (callable($this): TUnlessNotEmptyReturnType)|null $default + * @return $this|TUnlessNotEmptyReturnType */ public function unlessNotEmpty(callable $callback, callable $default = null) { @@ -551,7 +529,7 @@ trait EnumeratesValues /** * Filter items by the given key value pair. * - * @param string $key + * @param callable|string $key * @param mixed $operator * @param mixed $value * @return static @@ -599,7 +577,7 @@ trait EnumeratesValues * Filter items by the given key value pair. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @param bool $strict * @return static */ @@ -607,16 +585,14 @@ trait EnumeratesValues { $values = $this->getArrayableItems($values); - return $this->filter(function ($item) use ($key, $values, $strict) { - return in_array(data_get($item, $key), $values, $strict); - }); + return $this->filter(fn ($item) => in_array(data_get($item, $key), $values, $strict)); } /** * Filter items by the given key value pair using strict comparison. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereInStrict($key, $values) @@ -628,7 +604,7 @@ trait EnumeratesValues * Filter items such that the value of the given key is between the given values. * * @param string $key - * @param array $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereBetween($key, $values) @@ -640,21 +616,21 @@ trait EnumeratesValues * Filter items such that the value of the given key is not between the given values. * * @param string $key - * @param array $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereNotBetween($key, $values) { - return $this->filter(function ($item) use ($key, $values) { - return data_get($item, $key) < reset($values) || data_get($item, $key) > end($values); - }); + return $this->filter( + fn ($item) => data_get($item, $key) < reset($values) || data_get($item, $key) > end($values) + ); } /** * Filter items by the given key value pair. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @param bool $strict * @return static */ @@ -662,16 +638,14 @@ trait EnumeratesValues { $values = $this->getArrayableItems($values); - return $this->reject(function ($item) use ($key, $values, $strict) { - return in_array(data_get($item, $key), $values, $strict); - }); + return $this->reject(fn ($item) => in_array(data_get($item, $key), $values, $strict)); } /** * Filter items by the given key value pair using strict comparison. * * @param string $key - * @param mixed $values + * @param \QL\Collect\Contracts\Support\Arrayable|iterable $values * @return static */ public function whereNotInStrict($key, $values) @@ -682,8 +656,10 @@ trait EnumeratesValues /** * Filter the items, removing any items that don't match the given type(s). * - * @param string|string[] $type - * @return static + * @template TWhereInstanceOf + * + * @param class-string|array> $type + * @return static */ public function whereInstanceOf($type) { @@ -705,8 +681,10 @@ trait EnumeratesValues /** * Pass the collection to the given callback and return the result. * - * @param callable $callback - * @return mixed + * @template TPipeReturnType + * + * @param callable($this): TPipeReturnType $callback + * @return TPipeReturnType */ public function pipe(callable $callback) { @@ -716,7 +694,7 @@ trait EnumeratesValues /** * Pass the collection into a new class. * - * @param string $class + * @param class-string $class * @return mixed */ public function pipeInto($class) @@ -727,38 +705,26 @@ trait EnumeratesValues /** * Pass the collection through a series of callable pipes and return the result. * - * @param array $pipes + * @param array $callbacks * @return mixed */ - public function pipeThrough($pipes) + public function pipeThrough($callbacks) { - return static::make($pipes)->reduce( - function ($carry, $pipe) { - return $pipe($carry); - }, + return Collection::make($callbacks)->reduce( + fn ($carry, $callback) => $callback($carry), $this, ); } - /** - * Pass the collection to the given callback and then return it. - * - * @param callable $callback - * @return $this - */ - public function tap(callable $callback) - { - $callback(clone $this); - - return $this; - } - /** * Reduce the collection to a single value. * - * @param callable $callback - * @param mixed $initial - * @return mixed + * @template TReduceInitial + * @template TReduceReturnType + * + * @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback + * @param TReduceInitial $initial + * @return TReduceReturnType */ public function reduce(callable $callback, $initial = null) { @@ -771,22 +737,6 @@ trait EnumeratesValues return $result; } - /** - * Reduce the collection to multiple aggregate values. - * - * @param callable $callback - * @param mixed ...$initial - * @return array - * - * @deprecated Use "reduceSpread" instead - * - * @throws \UnexpectedValueException - */ - public function reduceMany(callable $callback, ...$initial) - { - return $this->reduceSpread($callback, ...$initial); - } - /** * Reduce the collection to multiple aggregate values. * @@ -805,7 +755,7 @@ trait EnumeratesValues if (! is_array($result)) { throw new UnexpectedValueException(sprintf( - "%s::reduceMany expects reducer to return an array, but got a '%s' instead.", + "%s::reduceSpread expects reducer to return an array, but got a '%s' instead.", class_basename(static::class), gettype($result) )); } @@ -814,22 +764,10 @@ trait EnumeratesValues return $result; } - /** - * Reduce an associative collection to a single value. - * - * @param callable $callback - * @param mixed $initial - * @return mixed - */ - public function reduceWithKeys(callable $callback, $initial = null) - { - return $this->reduce($callback, $initial); - } - /** * Create a collection of all elements that do not pass a given truth test. * - * @param callable|mixed $callback + * @param (callable(TValue, TKey): bool)|bool|TValue $callback * @return static */ public function reject($callback = true) @@ -843,10 +781,45 @@ trait EnumeratesValues }); } + /** + * Pass the collection to the given callback and then return it. + * + * @param callable($this): mixed $callback + * @return $this + */ + public function tap(callable $callback) + { + $callback($this); + + return $this; + } + + /** + * Return only unique items from the collection array. + * + * @param (callable(TValue, TKey): mixed)|string|null $key + * @param bool $strict + * @return static + */ + public function unique($key = null, $strict = false) + { + $callback = $this->valueRetriever($key); + + $exists = []; + + return $this->reject(function ($item, $key) use ($callback, $strict, &$exists) { + if (in_array($id = $callback($item, $key), $exists, $strict)) { + return true; + } + + $exists[] = $id; + }); + } + /** * Return only unique items from the collection array using strict comparison. * - * @param string|callable|null $key + * @param (callable(TValue, TKey): mixed)|string|null $key * @return static */ public function uniqueStrict($key = null) @@ -857,7 +830,7 @@ trait EnumeratesValues /** * Collect the values into a collection. * - * @return \Tightenco\Collect\Support\Collection + * @return \QL\Collect\Support\Collection */ public function collect() { @@ -867,22 +840,19 @@ trait EnumeratesValues /** * Get the collection of items as a plain array. * - * @return array + * @return array */ public function toArray() { - return $this->map(function ($value) { - return $value instanceof Arrayable ? $value->toArray() : $value; - })->all(); + return $this->map(fn ($value) => $value instanceof Arrayable ? $value->toArray() : $value)->all(); } /** * Convert the object into something JSON serializable. * - * @return array + * @return array */ - #[\ReturnTypeWillChange] - public function jsonSerialize() + public function jsonSerialize(): array { return array_map(function ($value) { if ($value instanceof JsonSerializable) { @@ -976,7 +946,7 @@ trait EnumeratesValues * Results array of items from Collection or Arrayable. * * @param mixed $items - * @return array + * @return array */ protected function getArrayableItems($items) { @@ -986,12 +956,12 @@ trait EnumeratesValues return $items->all(); } elseif ($items instanceof Arrayable) { return $items->toArray(); + } elseif ($items instanceof Traversable) { + return iterator_to_array($items); } elseif ($items instanceof Jsonable) { return json_decode($items->toJson(), true); } elseif ($items instanceof JsonSerializable) { return (array) $items->jsonSerialize(); - } elseif ($items instanceof Traversable) { - return iterator_to_array($items); } elseif ($items instanceof UnitEnum) { return [$items]; } @@ -1002,13 +972,17 @@ trait EnumeratesValues /** * Get an operator checker callback. * - * @param string $key + * @param callable|string $key * @param string|null $operator * @param mixed $value * @return \Closure */ protected function operatorForWhere($key, $operator = null, $value = null) { + if ($this->useAsCallable($key)) { + return $key; + } + if (func_num_args() === 1) { $value = true; @@ -1044,6 +1018,7 @@ trait EnumeratesValues case '>=': return $retrieved >= $value; case '===': return $retrieved === $value; case '!==': return $retrieved !== $value; + case '<=>': return $retrieved <=> $value; } }; } @@ -1071,22 +1046,18 @@ trait EnumeratesValues return $value; } - return function ($item) use ($value) { - return data_get($item, $value); - }; + return fn ($item) => data_get($item, $value); } /** * Make a function to check an item's equality. * * @param mixed $value - * @return \Closure + * @return \Closure(mixed): bool */ protected function equality($value) { - return function ($item) use ($value) { - return $item === $value; - }; + return fn ($item) => $item === $value; } /** @@ -1097,20 +1068,16 @@ trait EnumeratesValues */ protected function negate(Closure $callback) { - return function (...$params) use ($callback) { - return ! $callback(...$params); - }; + return fn (...$params) => ! $callback(...$params); } /** * Make a function that returns what's passed to it. * - * @return \Closure + * @return \Closure(TValue): TValue */ protected function identity() { - return function ($value) { - return $value; - }; + return fn ($value) => $value; } } diff --git a/vendor/tightenco/collect/src/Collect/Support/Traits/Macroable.php b/vendor/jaeger/querylist/src/Collect/Support/Traits/Macroable.php similarity index 98% rename from vendor/tightenco/collect/src/Collect/Support/Traits/Macroable.php rename to vendor/jaeger/querylist/src/Collect/Support/Traits/Macroable.php index 7e9fbd5..596b5d8 100644 --- a/vendor/tightenco/collect/src/Collect/Support/Traits/Macroable.php +++ b/vendor/jaeger/querylist/src/Collect/Support/Traits/Macroable.php @@ -1,6 +1,6 @@ Illuminate\Contracts\Support\Arrayable::class, + QL\Collect\Contracts\Support\Jsonable::class => Illuminate\Contracts\Support\Jsonable::class, + QL\Collect\Contracts\Support\Htmlable::class => Illuminate\Contracts\Support\Htmlable::class, + QL\Collect\Contracts\Support\CanBeEscapedWhenCastToString::class => Illuminate\Contracts\Support\CanBeEscapedWhenCastToString::class, + QL\Collect\Support\Arr::class => Illuminate\Support\Arr::class, + QL\Collect\Support\Collection::class => Illuminate\Support\Collection::class, + QL\Collect\Support\Enumerable::class => Illuminate\Support\Enumerable::class, + QL\Collect\Support\HigherOrderCollectionProxy::class => Illuminate\Support\HigherOrderCollectionProxy::class, + QL\Collect\Support\LazyCollection::class => Illuminate\Support\LazyCollection::class, + QL\Collect\Support\Traits\EnumeratesValues::class => Illuminate\Support\Traits\EnumeratesValues::class, +]; + +# echo "\n\n-- Aliasing....\n---------------------------------------------\n\n"; + +foreach ($aliases as $tighten => $illuminate) { + if (! class_exists($illuminate) && ! interface_exists($illuminate) && ! trait_exists($illuminate)) { + # echo "Aliasing {$tighten} to {$illuminate}.\n"; + class_alias($tighten, $illuminate); + } +} diff --git a/vendor/tightenco/collect/src/Collect/Support/helpers.php b/vendor/jaeger/querylist/src/Collect/Support/helpers.php similarity index 94% rename from vendor/tightenco/collect/src/Collect/Support/helpers.php rename to vendor/jaeger/querylist/src/Collect/Support/helpers.php index 886a141..377adc1 100644 --- a/vendor/tightenco/collect/src/Collect/Support/helpers.php +++ b/vendor/jaeger/querylist/src/Collect/Support/helpers.php @@ -1,8 +1,8 @@ |).+<\/head>/is', '', $this->html); - $this->setHtml($html); + $html = preg_replace('/(|).+?<\/head>/is', '', $this->html); + $html && $this->setHtml($html); return $this->ql; } diff --git a/vendor/jaeger/querylist/src/Kernel.php b/vendor/jaeger/querylist/src/Kernel.php index 085c21d..adbc20c 100644 --- a/vendor/jaeger/querylist/src/Kernel.php +++ b/vendor/jaeger/querylist/src/Kernel.php @@ -14,7 +14,7 @@ use Closure; use QL\Providers\HttpServiceProvider; use QL\Providers\PluginServiceProvider; use QL\Providers\SystemServiceProvider; -use Tightenco\Collect\Support\Collection; +use QL\Collect\Support\Collection; class Kernel { diff --git a/vendor/jaeger/querylist/src/QueryList.php b/vendor/jaeger/querylist/src/QueryList.php index 4fc1c6c..8cf4fb3 100644 --- a/vendor/jaeger/querylist/src/QueryList.php +++ b/vendor/jaeger/querylist/src/QueryList.php @@ -14,7 +14,7 @@ namespace QL; use phpQuery; use QL\Dom\Query; -use Tightenco\Collect\Support\Collection; +use QL\Collect\Support\Collection; use Closure; use QL\Services\MultiRequestService; diff --git a/vendor/jaeger/querylist/src/Services/MultiRequestService.php b/vendor/jaeger/querylist/src/Services/MultiRequestService.php index 803ee80..0b3eeab 100644 --- a/vendor/jaeger/querylist/src/Services/MultiRequestService.php +++ b/vendor/jaeger/querylist/src/Services/MultiRequestService.php @@ -13,7 +13,6 @@ use Jaeger\GHttp; use Closure; use GuzzleHttp\Psr7\Response; use QL\QueryList; -use GuzzleHttp\Exception\RequestException; /** * Class MultiRequestService @@ -53,7 +52,7 @@ class MultiRequestService public function error(Closure $error) { - $this->multiRequest = $this->multiRequest->error(function(RequestException $reason, $index) use($error){ + $this->multiRequest = $this->multiRequest->error(function($reason, $index) use($error){ $error($this->ql,$reason, $index); }); return $this; diff --git a/vendor/jaeger/querylist/tests/Dom/FindTest.php b/vendor/jaeger/querylist/tests/Dom/FindTest.php deleted file mode 100644 index 024df21..0000000 --- a/vendor/jaeger/querylist/tests/Dom/FindTest.php +++ /dev/null @@ -1,71 +0,0 @@ -html = $this->getSnippet('snippet-1'); - $this->ql = QueryList::html($this->html); - } - - /** - * @test - */ - public function find_first_dom_attr() - { - $img = []; - $img[] = $this->ql->find('img')->attr('src'); - $img[] = $this->ql->find('img')->src; - $img[] = $this->ql->find('img:eq(0)')->src; - $img[] = $this->ql->find('img')->eq(0)->src; - - $alt = $this->ql->find('img')->alt; - $abc = $this->ql->find('img')->abc; - - $this->assertCount(1,array_unique($img)); - $this->assertEquals($alt,'这是图片'); - $this->assertEquals($abc,'这是一个自定义属性'); - - } - - /** - * @test - */ - public function find_second_dom_attr() - { - - $img2 = []; - $img2[] = $this->ql->find('img')->eq(1)->alt; - $img2[] = $this->ql->find('img:eq(1)')->alt; - $img2[] = $this->ql->find('.second_pic')->alt; - - $this->assertCount(1,array_unique($img2)); - - } - - /** - * @test - */ - public function find_dom_all_attr() - { - $imgAttr = $this->ql->find('img:eq(0)')->attr('*'); - $linkAttr = $this->ql->find('a:eq(1)')->attr('*'); - $this->assertCount(3,$imgAttr); - $this->assertCount(1,$linkAttr); - } -} \ No newline at end of file diff --git a/vendor/jaeger/querylist/tests/Dom/RulesTest.php b/vendor/jaeger/querylist/tests/Dom/RulesTest.php deleted file mode 100644 index 7c555ca..0000000 --- a/vendor/jaeger/querylist/tests/Dom/RulesTest.php +++ /dev/null @@ -1,43 +0,0 @@ - - * Date: 18/12/12 - * Time: 下午12:25 - */ - -namespace Tests\Dom; - - -use QL\QueryList; -use Tests\TestCaseBase; -use Tightenco\Collect\Support\Collection; - -class RulesTest extends TestCaseBase -{ - protected $html; - protected $ql; - - protected function setUp(): void - { - $this->html = $this->getSnippet('snippet-2'); - $this->ql = QueryList::html($this->html); - } - - /** - * @test - */ - public function get_data_by_rules() - { - $rules = [ - 'a' => ['a','text'], - 'img_src' => ['img','src'], - 'img_alt' => ['img','alt'] - ]; - $range = 'ul>li'; - $data = QueryList::rules($rules)->range($range)->html($this->html)->query()->getData(); - $this->assertInstanceOf(Collection::class,$data); - $this->assertCount(3,$data); - $this->assertEquals('http://querylist.com/2.jpg',$data[1]['img_src']); - } -} \ No newline at end of file diff --git a/vendor/jaeger/querylist/tests/Feature/HttpTest.php b/vendor/jaeger/querylist/tests/Feature/HttpTest.php deleted file mode 100644 index 0d723ed..0000000 --- a/vendor/jaeger/querylist/tests/Feature/HttpTest.php +++ /dev/null @@ -1,103 +0,0 @@ -urls = [ - 'http://httpbin.org/get?name=php', - 'http://httpbin.org/get?name=golang', - 'http://httpbin.org/get?name=c++', - 'http://httpbin.org/get?name=java' - ]; - } - - /** - * @test - */ - public function can_post_json_data() - { - $mock = new MockHandler([new Response()]); - $data = [ - 'name' => 'foo' - ]; - QueryList::postJson('http://foo.com',$data,[ - 'handler' => $mock - ]); - $this->assertEquals((string)$mock->getLastRequest()->getBody(),json_encode($data)); - } - - /** - * @test - */ - public function concurrent_requests_base_use() - { - $urls = $this->urls; - QueryList::getInstance() - ->multiGet($urls) - ->success(function(QueryList $ql,Response $response, $index) use($urls){ - $body = json_decode((string)$response->getBody(),true); - $this->assertEquals($urls[$index],$body['url']); - })->send(); - } - - /** - * @test - */ - public function concurrent_requests_advanced_use() - { - $ua = 'QueryList/4.0'; - - $errorUrl = 'http://web-site-not-exist.com'; - $urls = array_merge($this->urls,[$errorUrl]); - - QueryList::rules([]) - ->multiGet($urls) - ->concurrency(2) - ->withOptions([ - 'timeout' => 60 - ]) - ->withHeaders([ - 'User-Agent' => $ua - ]) - ->success(function (QueryList $ql, Response $response, $index) use($ua){ - $body = json_decode((string)$response->getBody(),true); - $this->assertEquals($ua,$body['headers']['User-Agent']); - }) - ->error(function (QueryList $ql, $reason, $index) use($urls,$errorUrl){ - $this->assertEquals($urls[$index],$errorUrl); - }) - ->send(); - } - - /** - * @test - */ - public function request_with_cache() - { - $url = $this->urls[0]; - $data = QueryList::get($url,null,[ - 'cache' => sys_get_temp_dir(), - 'cache_ttl' => 600 - ])->getHtml(); - $data = json_decode($data,true); - $this->assertEquals($url,$data['url']); - - } -} \ No newline at end of file diff --git a/vendor/jaeger/querylist/tests/Feature/InstanceTest.php b/vendor/jaeger/querylist/tests/Feature/InstanceTest.php deleted file mode 100644 index a659060..0000000 --- a/vendor/jaeger/querylist/tests/Feature/InstanceTest.php +++ /dev/null @@ -1,48 +0,0 @@ -html = $this->getSnippet('snippet-1'); - } - /** - * @test - */ - public function singleton_instance_mode() - { - $ql = QueryList::getInstance()->html($this->html); - $ql2 = QueryList::getInstance(); - $this->assertEquals($ql->getHtml(),$ql2->getHtml()); - - - } - - /** - * @test - */ - public function get_new_object() - { - $ql = (new QueryList())->html($this->html); - $ql2 = (new QueryList())->html(''); - $this->assertNotEquals($ql->getHtml(),$ql2->getHtml()); - - $ql = QueryList::range('')->html($this->html); - $ql2 = QueryList::range('')->html(''); - $this->assertNotEquals($ql->getHtml(),$ql2->getHtml()); - } -} \ No newline at end of file diff --git a/vendor/jaeger/querylist/tests/Feature/MethodTest.php b/vendor/jaeger/querylist/tests/Feature/MethodTest.php deleted file mode 100644 index ca10cf9..0000000 --- a/vendor/jaeger/querylist/tests/Feature/MethodTest.php +++ /dev/null @@ -1,36 +0,0 @@ -html = $this->getSnippet('snippet-1'); - } - - /** - * @test - */ - public function pipe() - { - $html = $this->html; - $qlHtml = QueryList::pipe(function(QueryList $ql) use($html){ - $ql->setHtml($html); - return $ql; - })->getHtml(false); - $this->assertEquals($html,$qlHtml); - } -} \ No newline at end of file diff --git a/vendor/jaeger/querylist/tests/TestCaseBase.php b/vendor/jaeger/querylist/tests/TestCaseBase.php deleted file mode 100644 index c88d73e..0000000 --- a/vendor/jaeger/querylist/tests/TestCaseBase.php +++ /dev/null @@ -1,20 +0,0 @@ - - - 其它的一些文本 - \ No newline at end of file diff --git a/vendor/jaeger/querylist/tests/assets/snippet-2.html b/vendor/jaeger/querylist/tests/assets/snippet-2.html deleted file mode 100644 index 88ae3f0..0000000 --- a/vendor/jaeger/querylist/tests/assets/snippet-2.html +++ /dev/null @@ -1,16 +0,0 @@ - \ No newline at end of file diff --git a/vendor/jaeger/querylist/tests/bootstrap.php b/vendor/jaeger/querylist/tests/bootstrap.php deleted file mode 100644 index eace7af..0000000 --- a/vendor/jaeger/querylist/tests/bootstrap.php +++ /dev/null @@ -1,5 +0,0 @@ - 'taoser\\addons\\Service', diff --git a/vendor/tightenco/collect/.github/workflows/run-tests.yml b/vendor/tightenco/collect/.github/workflows/run-tests.yml deleted file mode 100644 index 2a0d42f..0000000 --- a/vendor/tightenco/collect/.github/workflows/run-tests.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Run tests - -on: - push: - branches: [laravel-9-ongoing, laravel-8-ongoing] - pull_request: - -jobs: - tests: - strategy: - matrix: - os: [Ubuntu, macOS] - php: [7.3, 7.4, 8.0, 8.1] - - include: - - os: Ubuntu - os-version: ubuntu-latest - - - os: macOS - os-version: macos-latest - - name: ${{ matrix.os }} - PHP ${{ matrix.php }} - - runs-on: ${{ matrix.os-version }} - - steps: - - name: Checkout code - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: posix, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Install dependencies - run: composer update --prefer-stable --prefer-dist --no-interaction - - - name: Run tests - run: bash upgrade.sh diff --git a/vendor/tightenco/collect/branch-commit-push.sh b/vendor/tightenco/collect/branch-commit-push.sh deleted file mode 100644 index 124e583..0000000 --- a/vendor/tightenco/collect/branch-commit-push.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - - -GREEN='\033[0;32m' -RED='\033[0;31m' -WHITE='\033[0;37m' -RESET='\033[0m' - -function validateVersion() -{ - echo "" - passedVersion=$1 - echo -e "${WHITE}-- Validating tag '$passedVersion'...${RESET}" - - # Todo: validate the version here using a regex; if fail, just exit - # ... expect 8.75.0, with no v in front of it - - if [[ $passedVersion == '' ]]; then - echo -e "\n-- Invalid tag. Tags should be structured without v; e.g. 8.57.0" - exit - fi - - echo -e "${WHITE}-- Tag valid.${RESET}" - echo "" -} - -# Exit script if any command fails (e.g. phpunit) -set -e - - -# Require confirmation it's set up corrctly -echo -echo -e "${WHITE}-- This script is meant to be run after running upgrade.sh, BEFORE committing to Git.${RESET}" - -while true; do - echo -e "${GREEN}-- Is that the current state of your local project?${RESET}" - read -p "-- (y/n) " yn - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) echo "Please answer y or n.";; - esac -done - -# Get the version and exit if not valid -validateVersion $1 - -# Create official v prefaced version -version="v$1" - -# Run tests (and bail if they fail) -phpunit -echo -e "\n${WHITE}-- Tests succeeded.${RESET}" - -# Branch -echo -e "\n${WHITE}-- Creating a Git branch '$version-changes'...${RESET}\n" -git checkout -b $version-changes - -# Add and commit, with "v8.57.0 changes" as the commit name -git add -A -git commit -m "$version changes" - -echo -echo -e "${WHITE}-- Git committed.${RESET}" - -# Push -git push -u origin $version-changes diff --git a/vendor/tightenco/collect/composer.json b/vendor/tightenco/collect/composer.json deleted file mode 100644 index 88ebb77..0000000 --- a/vendor/tightenco/collect/composer.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "tightenco/collect", - "description": "Collect - Illuminate Collections as a separate package.", - "keywords": ["laravel", "collection"], - "license": "MIT", - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" - } - ], - "require": { - "php": "^7.3|^8.0", - "symfony/var-dumper": "^3.4 || ^4.0 || ^5.0 || ^6.0" - }, - "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^8.3", - "nesbot/carbon": "^2.23.0" - }, - "autoload": { - "files": [ - "src/Collect/Support/helpers.php", - "src/Collect/Support/alias.php" - ], - "psr-4": { - "Tightenco\\Collect\\": "src/Collect" - } - }, - "autoload-dev": { - "files": [ - "tests/files/Support/Carbon.php", - "tests/files/Support/HtmlString.php", - "tests/files/Support/HigherOrderTapProxy.php", - "tests/files/Support/Str.php", - "tests/files/Support/Traits/Conditionable.php", - "tests/files/Support/Stringable.php", - "tests/files/Support/ItemNotFoundException.php", - "tests/files/Support/MultipleItemsFoundException.php", - "tests/Support/Concerns/CountsEnumerations.php" - ] - }, - "scripts": { - "test": [ - "@composer install", - "phpunit" - ] - }, - "minimum-stability": "dev", - "prefer-stable": true -} diff --git a/vendor/tightenco/collect/framework-.zip b/vendor/tightenco/collect/framework-.zip deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/tightenco/collect/src/Collect/Contracts/Support/Arrayable.php b/vendor/tightenco/collect/src/Collect/Contracts/Support/Arrayable.php deleted file mode 100644 index a205804..0000000 --- a/vendor/tightenco/collect/src/Collect/Contracts/Support/Arrayable.php +++ /dev/null @@ -1,13 +0,0 @@ -condition = $condition; - $this->collection = $collection; - } - - /** - * Proxy accessing an attribute onto the collection. - * - * @param string $key - * @return mixed - */ - public function __get($key) - { - return $this->condition - ? $this->collection->{$key} - : $this->collection; - } - - /** - * Proxy a method call onto the collection. - * - * @param string $method - * @param array $parameters - * @return mixed - */ - public function __call($method, $parameters) - { - return $this->condition - ? $this->collection->{$method}(...$parameters) - : $this->collection; - } -} diff --git a/vendor/tightenco/collect/src/Collect/Support/alias.php b/vendor/tightenco/collect/src/Collect/Support/alias.php deleted file mode 100644 index a9c0406..0000000 --- a/vendor/tightenco/collect/src/Collect/Support/alias.php +++ /dev/null @@ -1,24 +0,0 @@ - Illuminate\Contracts\Support\Arrayable::class, - Tightenco\Collect\Contracts\Support\Jsonable::class => Illuminate\Contracts\Support\Jsonable::class, - Tightenco\Collect\Contracts\Support\Htmlable::class => Illuminate\Contracts\Support\Htmlable::class, - Tightenco\Collect\Contracts\Support\CanBeEscapedWhenCastToString::class => Illuminate\Contracts\Support\CanBeEscapedWhenCastToString::class, - Tightenco\Collect\Support\Arr::class => Illuminate\Support\Arr::class, - Tightenco\Collect\Support\Collection::class => Illuminate\Support\Collection::class, - Tightenco\Collect\Support\Enumerable::class => Illuminate\Support\Enumerable::class, - Tightenco\Collect\Support\HigherOrderCollectionProxy::class => Illuminate\Support\HigherOrderCollectionProxy::class, - Tightenco\Collect\Support\HigherOrderWhenProxy::class => Illuminate\Support\HigherOrderWhenProxy::class, - Tightenco\Collect\Support\LazyCollection::class => Illuminate\Support\LazyCollection::class, - Tightenco\Collect\Support\Traits\EnumeratesValues::class => Illuminate\Support\Traits\EnumeratesValues::class, -]; - -# echo "\n\n-- Aliasing....\n---------------------------------------------\n\n"; - -foreach ($aliases as $tighten => $illuminate) { - if (! class_exists($illuminate) && ! interface_exists($illuminate) && ! trait_exists($illuminate)) { - # echo "Aliasing {$tighten} to {$illuminate}.\n"; - class_alias($tighten, $illuminate); - } -} diff --git a/view/taoler/index/article/ask/cate.html b/view/taoler/index/article/ask/cate.html index 8ebbd7e..8b5b208 100644 --- a/view/taoler/index/article/ask/cate.html +++ b/view/taoler/index/article/ask/cate.html @@ -18,7 +18,7 @@
    -
    +
    • {:lang('all')}
    • {:lang('end')}
    • diff --git a/view/taoler/index/article/ask/detail.html b/view/taoler/index/article/ask/detail.html index 45d94b9..c3be8d3 100644 --- a/view/taoler/index/article/ask/detail.html +++ b/view/taoler/index/article/ask/detail.html @@ -229,7 +229,6 @@
      diff --git a/view/taoler/index/article/posts/cate.html b/view/taoler/index/article/posts/cate.html index 4aaed07..7636f40 100644 --- a/view/taoler/index/article/posts/cate.html +++ b/view/taoler/index/article/posts/cate.html @@ -24,7 +24,7 @@ {$art.user.name}

      - {$art.title} + {$art.title}

      diff --git a/view/taoler/index/article/posts/detail.html b/view/taoler/index/article/posts/detail.html index de4ff98..1de4863 100644 --- a/view/taoler/index/article/posts/detail.html +++ b/view/taoler/index/article/posts/detail.html @@ -245,7 +245,6 @@
      diff --git a/view/taoler/index/index/index.html b/view/taoler/index/index/index.html index 354c96b..16af138 100644 --- a/view/taoler/index/index/index.html +++ b/view/taoler/index/index/index.html @@ -25,7 +25,9 @@
      {:lang('top')} + {if hook('signstatushook') == 1} {:lang('go sign')} + {/if}
        {if config('taoler.config.top_show') == 1} diff --git a/view/taoler/index/user/index.html b/view/taoler/index/user/index.html index 8fa1c2a..913660f 100644 --- a/view/taoler/index/user/index.html +++ b/view/taoler/index/user/index.html @@ -13,12 +13,14 @@
        Hi,{:session('user_name')},你已是我们的正式社员。
        -
        +
        +{if hook('signstatushook') == 1}
        - -
        +{/if}
        我的会员信息