feat: 同步下新环境

This commit is contained in:
笔记本里的永平
2025-07-07 11:31:25 +08:00
parent 3d1050db3d
commit 86c261ba70
196 changed files with 13146 additions and 29319 deletions

View File

@@ -20,52 +20,28 @@ use Traversable;
abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
{
/**
* 是否简洁模式
* @var bool
*/
/** @var bool 是否为简洁模式 */
protected $simple = false;
/**
* 数据集
* @var Collection
*/
/** @var Collection 数据集 */
protected $items;
/**
* 当前页
* @var integer
*/
/** @var integer 当前页 */
protected $currentPage;
/**
* 最后一页
* @var integer
*/
/** @var integer 最后一页 */
protected $lastPage;
/**
* 数据总数
* @var integer|null
*/
/** @var integer|null 数据总数 */
protected $total;
/**
* 每页数量
* @var integer
*/
/** @var integer 每页的数量 */
protected $listRows;
/**
* 是否有下一页
* @var bool
*/
/** @var bool 是否有下一页 */
protected $hasMore;
/**
* 分页配置
* @var array
*/
/** @var array 一些配置 */
protected $options = [
'var_page' => 'page',
'path' => '/',
@@ -73,6 +49,9 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
'fragment' => '',
];
/** @var mixed simple模式下的下个元素 */
protected $nextItem;
public function __construct($items, $listRows, $currentPage = null, $total = null, $simple = false, $options = [])
{
$this->options = array_merge($this->options, $options);
@@ -89,7 +68,10 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
if ($simple) {
$this->currentPage = $this->setCurrentPage($currentPage);
$this->hasMore = count($items) > ($this->listRows);
$items = $items->slice(0, $this->listRows);
if ($this->hasMore) {
$this->nextItem = $items->slice($this->listRows, 1);
}
$items = $items->slice(0, $this->listRows);
} else {
$this->total = $total;
$this->lastPage = (int) ceil($total / $listRows);
@@ -100,12 +82,11 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
}
/**
* @access public
* @param $items
* @param $listRows
* @param null $currentPage
* @param null $total
* @param bool $simple
* @param null $total
* @param array $options
* @return Paginator
*/
@@ -126,8 +107,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* 获取页码对应的链接
*
* @access protected
* @param $page
* @param $page
* @return string
*/
protected function url($page)
@@ -143,31 +123,27 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
$parameters = [];
$path = str_replace('[PAGE]', $page, $this->options['path']);
}
if (count($this->options['query']) > 0) {
$parameters = array_merge($this->options['query'], $parameters);
}
$url = $path;
if (!empty($parameters)) {
$url .= '?' . http_build_query($parameters, null, '&');
}
return $url . $this->buildFragment();
}
/**
* 自动获取当前页码
* @access public
* @param string $varPage
* @param int $default
* @param string $varPage
* @param int $default
* @return int
*/
public static function getCurrentPage($varPage = 'page', $default = 1)
{
$page = Container::get('request')->param($varPage);
$page = (int) Request::instance()->param($varPage);
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
if (filter_var($page, FILTER_VALIDATE_INT) !== false && $page >= 1) {
return $page;
}
@@ -176,12 +152,11 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* 自动获取当前的path
* @access public
* @return string
*/
public static function getCurrentPath()
{
return Container::get('request')->baseUrl();
return Request::instance()->baseUrl();
}
public function total()
@@ -189,7 +164,6 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
if ($this->simple) {
throw new \DomainException('not support total');
}
return $this->total;
}
@@ -208,13 +182,11 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
if ($this->simple) {
throw new \DomainException('not support last');
}
return $this->lastPage;
}
/**
* 数据是否足够分页
* @access public
* @return boolean
*/
public function hasPages()
@@ -225,7 +197,6 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* 创建一组分页链接
*
* @access public
* @param int $start
* @param int $end
* @return array
@@ -244,21 +215,18 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* 设置URL锚点
*
* @access public
* @param string|null $fragment
* @return $this
*/
public function fragment($fragment)
{
$this->options['fragment'] = $fragment;
return $this;
}
/**
* 添加URL参数
*
* @access public
* @param array|string $key
* @param string|null $value
* @return $this
@@ -283,7 +251,6 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* 构造锚点字符串
*
* @access public
* @return string
*/
protected function buildFragment()
@@ -293,7 +260,6 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* 渲染分页html
* @access public
* @return mixed
*/
abstract public function render();
@@ -316,7 +282,6 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* 给每个元素执行个回调
*
* @access public
* @param callable $callback
* @return $this
*/
@@ -324,7 +289,6 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
{
foreach ($this->items as $key => $item) {
$result = $callback($item, $key);
if (false === $result) {
break;
} elseif (!is_object($item)) {
@@ -337,7 +301,6 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* Retrieve an external iterator
* @access public
* @return Traversable An instance of an object implementing <b>Iterator</b> or
* <b>Traversable</b>
*/
@@ -348,8 +311,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* Whether a offset exists
* @access public
* @param mixed $offset
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
@@ -359,8 +321,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* Offset to retrieve
* @access public
* @param mixed $offset
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
@@ -370,9 +331,8 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* Offset to set
* @access public
* @param mixed $offset
* @param mixed $value
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
@@ -381,10 +341,9 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* Offset to unset
* @access public
* @param mixed $offset
* @param mixed $offset
* @return void
* @since 5.0.0
* @since 5.0.0
*/
public function offsetUnset($offset)
{
@@ -406,19 +365,24 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
public function toArray()
{
try {
$total = $this->total();
} catch (\DomainException $e) {
$total = null;
if ($this->simple) {
return [
'per_page' => $this->listRows,
'current_page' => $this->currentPage,
'has_more' => $this->hasMore,
'next_item' => $this->nextItem,
'data' => $this->items->toArray(),
];
} else {
return [
'total' => $this->total,
'per_page' => $this->listRows,
'current_page' => $this->currentPage,
'last_page' => $this->lastPage,
'data' => $this->items->toArray(),
];
}
return [
'total' => $total,
'per_page' => $this->listRows(),
'current_page' => $this->currentPage(),
'last_page' => $this->lastPage,
'data' => $this->items->toArray(),
];
}
/**