修复华为云存储报错

This commit is contained in:
2025-05-11 10:02:08 +08:00
parent 4ff29bed97
commit 7934afeb04
4 changed files with 93 additions and 93 deletions

View File

@@ -27,51 +27,51 @@ namespace Obs\Internal\Common;
class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInterface
{
protected $data;
public function __construct(array $data = [])
public function __construct(?array $data = [])
{
$this->data = $data;
}
public function count()
public function count(): int
{
return count($this->data);
}
public function getIterator()
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->data);
}
public function toArray()
{
return $this->data;
}
public function clear()
{
$this->data = [];
return $this;
}
public function getAll(array $keys = null)
public function getAll(?array $keys = null)
{
return $keys ? array_intersect_key($this->data, array_flip($keys)) : $this->data;
}
public function get($key)
{
return isset($this->data[$key]) ? $this->data[$key] : null;
}
public function set($key, $value)
{
$this->data[$key] = $value;
return $this;
}
public function add($key, $value)
{
if (!array_key_exists($key, $this->data)) {
@@ -81,27 +81,27 @@ class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInte
} else {
$this->data[$key] = [$this->data[$key], $value];
}
return $this;
}
public function remove($key)
{
unset($this->data[$key]);
return $this;
}
public function getKeys()
{
return array_keys($this->data);
}
public function hasKey($key)
{
return array_key_exists($key, $this->data);
}
public function keySearch($key)
{
foreach (array_keys($this->data) as $k) {
@@ -109,32 +109,32 @@ class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInte
return $k;
}
}
return false;
}
public function hasValue($value)
{
return array_search($value, $this->data);
}
public function replace(array $data)
public function replace(?array $data)
{
$this->data = $data;
return $this;
}
public function merge($data)
{
foreach ($data as $key => $value) {
$this->add($key, $value);
}
return $this;
}
public function overwriteWith($data)
{
if (is_array($data)) {
@@ -144,20 +144,20 @@ class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInte
$this->data[$key] = $value;
}
}
return $this;
}
public function map(\Closure $closure, array $context = [], $static = true)
public function map(\Closure $closure, ?array $context = [], $static = true)
{
$collection = $static ? new static() : new self();
foreach ($this as $key => $value) {
$collection->add($key, $closure($key, $value, $context));
}
return $collection;
}
public function filter(\Closure $closure, $static = true)
{
$collection = ($static) ? new static() : new self();
@@ -166,33 +166,33 @@ class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInte
$collection->add($key, $value);
}
}
return $collection;
}
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return isset($this->data[$offset]) ? $this->data[$offset] : null;
}
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->data[$offset] = $value;
}
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
public function setPath($path, $value)
{
$current =& $this->data;
$current = &$this->data;
$queue = explode('/', $path);
while (null !== ($key = array_shift($queue))) {
if (!is_array($current)) {
@@ -200,28 +200,28 @@ class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInte
} elseif (!$queue) {
$current[$key] = $value;
} elseif (isset($current[$key])) {
$current =& $current[$key];
$current = &$current[$key];
} else {
$current[$key] = [];
$current =& $current[$key];
$current = &$current[$key];
}
}
return $this;
}
public function getPath($path, $separator = '/', $data = null)
{
if ($data === null) {
$data =& $this->data;
$data = &$this->data;
}
$path = is_array($path) ? $path : explode($separator, $path);
while (null !== ($part = array_shift($path))) {
if (!is_array($data)) {
return null;
} elseif (isset($data[$part])) {
$data =& $data[$part];
$data = &$data[$part];
} elseif ($part != '*') {
return null;
} else {
@@ -237,10 +237,10 @@ class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInte
return $result;
}
}
return $data;
}
public function __toString()
{
$output = 'Debug output of ';
@@ -248,10 +248,10 @@ class Model implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInte
$output = str_repeat('=', strlen($output)) . "\n" . $output . "\n" . str_repeat('=', strlen($output)) . "\n\n";
$output .= "Model data\n-----------\n\n";
$output .= "This data can be retrieved from the model object using the get() method of the model "
. "(e.g. \$model->get(\$key)) or accessing the model like an associative array (e.g. \$model['key']).\n\n";
. "(e.g. \$model->get(\$key)) or accessing the model like an associative array (e.g. \$model['key']).\n\n";
$lines = array_slice(explode("\n", trim(print_r($this->toArray(), true))), 2, -1);
$output .= implode("\n", $lines);
return $output . "\n";
}
}