Skip to content

Commit

Permalink
Fixed bug that paginator was incompatibility with php 8.1. (#4615)
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo authored Mar 18, 2022
1 parent 8f52c9a commit 685f2c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
33 changes: 10 additions & 23 deletions src/AbstractPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
namespace Hyperf\Paginator;

use ArrayAccess;
use ArrayIterator;
use Closure;
use Hyperf\Contract\PaginatorInterface;
Expand All @@ -19,7 +20,7 @@
use Hyperf\Utils\Str;
use Hyperf\Utils\Traits\ForwardsCalls;

abstract class AbstractPaginator implements PaginatorInterface
abstract class AbstractPaginator implements PaginatorInterface, ArrayAccess
{
use ForwardsCalls;

Expand Down Expand Up @@ -370,41 +371,27 @@ public function setCollection(Collection $collection): self
return $this;
}

/**
* Determine if the given item exists.
* @param mixed $key
*/
public function offsetExists($key): bool
public function offsetExists(mixed $offset): bool
{
return $this->items->has($key);
return $this->items->has($offset);
}

/**
* Get the item at the given offset.
* @param mixed $key
*/
public function offsetGet($key)
public function offsetGet(mixed $offset): mixed
{
return $this->items->get($key);
return $this->items->get($offset);
}

/**
* Set the item at the given offset.
* @param mixed $key
* @param mixed $value
*/
public function offsetSet($key, $value): void
public function offsetSet(mixed $offset, mixed $value): void
{
$this->items->put($key, $value);
$this->items->put($offset, $value);
}

/**
* Unset the item at the given key.
* @param mixed $key
*/
public function offsetUnset($key): void
public function offsetUnset(mixed $offset): void
{
$this->items->forget($key);
$this->items->forget($offset);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/LengthAwarePaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
namespace Hyperf\Paginator;

use ArrayAccess;
use Countable;
use Hyperf\Contract\Arrayable;
use Hyperf\Contract\LengthAwarePaginatorInterface;
Expand All @@ -20,7 +19,7 @@
use IteratorAggregate;
use JsonSerializable;

class LengthAwarePaginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable, LengthAwarePaginatorInterface
class LengthAwarePaginator extends AbstractPaginator implements Arrayable, Countable, IteratorAggregate, JsonSerializable, Jsonable, LengthAwarePaginatorInterface
{
/**
* The total number of items before slicing.
Expand Down
3 changes: 1 addition & 2 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
*/
namespace Hyperf\Paginator;

use ArrayAccess;
use Countable;
use Hyperf\Contract\Arrayable;
use Hyperf\Utils\Collection;
use Hyperf\Utils\Contracts\Jsonable;
use IteratorAggregate;
use JsonSerializable;

class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable
class Paginator extends AbstractPaginator implements Arrayable, Countable, IteratorAggregate, JsonSerializable, Jsonable
{
/**
* Determine if there are more items in the data source.
Expand Down

0 comments on commit 685f2c6

Please sign in to comment.