!3 php8 兼容

Merge pull request !3 from F4nniu (FastAdmin开源框架)/php8_compatibility
This commit is contained in:
F4nniu (FastAdmin开源框架)
2023-12-26 11:11:27 +00:00
committed by Gitee
8 changed files with 27 additions and 7 deletions

View File

@@ -360,6 +360,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @param mixed $offset 键名
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return array_key_exists($offset, $this->items);
@@ -371,6 +372,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @param mixed $offset 键名
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->items[$offset];
@@ -383,6 +385,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @param mixed $value 值
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
@@ -398,6 +401,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @param mixed $offset 键名
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->items[$offset]);
@@ -408,6 +412,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @access public
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->items);
@@ -418,6 +423,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @access public
* @return ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->items);
@@ -428,6 +434,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @access public
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();

View File

@@ -613,7 +613,7 @@ class Loader
if ($type) {
$name = preg_replace_callback('/_([a-zA-Z])/', function ($match) {
return strtoupper($match[1]);
}, $name);
}, $name ?? '');
return $ucfirst ? ucfirst($name) : lcfirst($name);
}

View File

@@ -2268,27 +2268,32 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
}
// JsonSerializable
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
}
// ArrayAccess
#[\ReturnTypeWillChange]
public function offsetSet($name, $value)
{
$this->setAttr($name, $value);
}
#[\ReturnTypeWillChange]
public function offsetExists($name)
{
return $this->__isset($name);
}
#[\ReturnTypeWillChange]
public function offsetUnset($name)
{
$this->__unset($name);
}
#[\ReturnTypeWillChange]
public function offsetGet($name)
{
return $this->getAttr($name);

View File

@@ -128,7 +128,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
}
$url = $path;
if (!empty($parameters)) {
$url .= '?' . http_build_query($parameters, null, '&');
$url .= '?' . http_build_query($parameters, '', '&');
}
return $url . $this->buildFragment();
}
@@ -304,6 +304,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
* @return Traversable An instance of an object implementing <b>Iterator</b> or
* <b>Traversable</b>
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->items->all());
@@ -314,6 +315,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
* @param mixed $offset
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->items->offsetExists($offset);
@@ -324,6 +326,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
* @param mixed $offset
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->items->offsetGet($offset);
@@ -334,6 +337,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
* @param mixed $offset
* @param mixed $value
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->items->offsetSet($offset, $value);
@@ -345,6 +349,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
* @return void
* @since 5.0.0
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->items->offsetUnset($offset);
@@ -353,6 +358,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* Count elements of an object
*/
#[\ReturnTypeWillChange]
public function count()
{
return $this->items->count();
@@ -388,6 +394,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
/**
* Specify data which should be serialized to JSON
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();

View File

@@ -1091,7 +1091,7 @@ class Request
foreach ($filters as $filter) {
if (is_callable($filter)) {
// 调用函数或者方法过滤
$value = call_user_func($filter, $value);
$value = call_user_func($filter, $value ?? '');
} elseif (is_scalar($value)) {
if (false !== strpos($filter, '/')) {
// 正则过滤

View File

@@ -931,10 +931,10 @@ class Validate
if (is_string($rule) && strpos($rule, ',')) {
list($rule, $param) = explode(',', $rule);
} elseif (is_array($rule)) {
$param = isset($rule[1]) ? $rule[1] : null;
$param = $rule[1] ?? 0;
$rule = $rule[0];
} else {
$param = null;
$param = 0;
}
return false !== filter_var($value, is_int($rule) ? $rule : filter_id($rule), $param);
}

View File

@@ -480,6 +480,7 @@ class Query
$result = Cache::get($guid);
}
if (false === $result) {
$result = [];
if (isset($this->options['field'])) {
unset($this->options['field']);
}

View File

@@ -38,8 +38,8 @@ trait Jump
{
if (is_null($url) && !is_null(Request::instance()->server('HTTP_REFERER'))) {
$url = Request::instance()->server('HTTP_REFERER');
} elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
$url = Url::build($url);
} elseif ('' !== $url && !strpos($url ?? '', '://') && 0 !== strpos($url ?? '', '/')) {
$url = Url::build($url ?? '');
}
$type = $this->getResponseType();