提交 388d49f1 编写于 作者: ModStart's avatar ModStart

develop

上级 a855d466
- 新增:IDManager增强随机ID管理
- 优化:安装引导程序检测目录是否真实可写
<?php
namespace Module\Vendor\Provider\IDManager;
use Illuminate\Support\Facades\Cache;
abstract class AbstractDbCacheIDManager extends AbstractIDManager
{
abstract public function dbCacheAll();
private function clearCache()
{
Cache::forget($this->name() . '_All');
}
public function all()
{
return Cache::rememberForever($this->name() . '_All', function () {
return $this->dbCacheAll();
});
}
public function add($ids)
{
$this->clearCache();
}
public function remove($ids)
{
$this->clearCache();
}
public function total()
{
return count($this->all());
}
private function idsPaginate(&$ids, $page, $pageSize)
{
$page = max($page, 1);
$offset = max($page - 1, 0) * $pageSize;
if (!isset($ids[$offset])) {
return [];
}
$results = [];
for ($i = $offset; $i < $offset + $pageSize; $i++) {
if (!isset($ids[$i])) {
break;
}
$results[] = $ids[$i];
}
return $results;
}
public function paginate($page, $pageSize)
{
$ids = $this->all();
return $this->idsPaginate($ids, $page, $pageSize);
}
public function paginateRandom($page, $pageSize, $cacheKey = 'all', $cacheMinutes = 60)
{
$ids = Cache::remember($this->name() . '_Random_' . $cacheKey, $cacheMinutes, function () {
$ids = $this->all();
shuffle($ids);
return $ids;
});
return $this->idsPaginate($ids, $page, $pageSize);
}
}
\ No newline at end of file
<?php
namespace Module\Vendor\Provider\IDManager;
abstract class AbstractIDManager
{
abstract public function name();
abstract public function all();
abstract public function add($ids);
abstract public function remove($ids);
abstract public function total();
abstract public function paginate($page, $pageSize);
abstract public function paginateRandom($page, $pageSize, $cacheKey = 'all', $cacheMinutes = 60);
}
\ No newline at end of file
<?php
namespace Module\Vendor\Provider\IDManager;
class IDManager
{
private static $instances = [];
public static function register($provider)
{
self::$instances[] = $provider;
}
public static function all()
{
foreach (self::$instances as $k => $v) {
if ($v instanceof \Closure) {
self::$instances[$k] = call_user_func($v);
} else if (is_string($v)) {
self::$instances[$k] = app($v);
}
}
return self::$instances;
}
public static function get($name)
{
$name = modstart_config($name, $name);
foreach (self::all() as $manager) {
if ($manager->name() == $name) {
return $manager;
}
}
return null;
}
}
\ No newline at end of file
......@@ -257,7 +257,7 @@ class ModelUtil
return ArrayUtil::fetchSpecifiedKeyToArray($records, $idKey);
}
public static function values($model, $field, $where = [])
public static function values($model, $field, $where = [], $order = null)
{
$flat = false;
if (!is_array($field)) {
......@@ -266,7 +266,11 @@ class ModelUtil
} else {
$fields = $field;
}
$ms = self::model($model)->where($where)->get($fields)->toArray();
$ms = self::model($model)->where($where);
if (!empty($order)) {
$ms = $ms->orderBy($order[0], $order[1]);
}
$ms = $ms->get($fields)->toArray();
if ($flat) {
return array_map(function ($item) use ($field) {
return $item[$field];
......
......@@ -38,7 +38,7 @@ class ReUtil
{
$wild = str_replace('*', '__x__star__', $wild);
$regex = '/^' . preg_quote($wild, '/') . '$/';
$regex = str_replace('__x__star__', '[a-zA-Z0-9_]+', $regex);
$regex = str_replace('__x__star__', '.*', $regex);
// echo "isWildMatch ==> $regex <-> $text\n";
return preg_match($regex, $text);
}
......
......@@ -147,7 +147,7 @@
curr: data.page,
count: data.total,
limit: data.pageSize,
limits: [10,20,50,100,500,1000],
limits: [10,20,50,100],
layout: [ 'limit', 'prev', 'page', 'next','count',],
jump: function (obj, first) {
if (!first) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册