From ad73e659b8fca86902858381abef89453db33163 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 23 Apr 2020 10:46:39 +0200 Subject: [PATCH] Move contract on Enumerable It doesn't really makes sense that Enumerable is also array accesible or has anything to do with JSON manipulations. These interfaces should be defined on the implementing class. It does makes sense however to keep Countable and IteratorAggregate as we're still talking about collections here. But we shouldn't force people to also implement ArrayAccess or also any JSON contracts. --- src/Illuminate/Collections/Collection.php | 5 ++++- src/Illuminate/Collections/Enumerable.php | 5 +---- src/Illuminate/Collections/LazyCollection.php | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index ea77aab47e5c..9b8ba4322c1c 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -4,10 +4,13 @@ use ArrayAccess; use ArrayIterator; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Contracts\Support\Jsonable; use Illuminate\Macroable\Macroable; +use JsonSerializable; use stdClass; -class Collection implements ArrayAccess, Enumerable +class Collection implements Arrayable, ArrayAccess, Enumerable, Jsonable, JsonSerializable { use EnumeratesValues, Macroable; diff --git a/src/Illuminate/Collections/Enumerable.php b/src/Illuminate/Collections/Enumerable.php index 6de4a3bc8b9c..c1c6c1e57dc2 100644 --- a/src/Illuminate/Collections/Enumerable.php +++ b/src/Illuminate/Collections/Enumerable.php @@ -3,12 +3,9 @@ namespace Illuminate\Collections; use Countable; -use Illuminate\Contracts\Support\Arrayable; -use Illuminate\Contracts\Support\Jsonable; use IteratorAggregate; -use JsonSerializable; -interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable +interface Enumerable extends Countable, IteratorAggregate { /** * Create a new collection instance if the value isn't one already. diff --git a/src/Illuminate/Collections/LazyCollection.php b/src/Illuminate/Collections/LazyCollection.php index abe028d4c777..a7105235047b 100644 --- a/src/Illuminate/Collections/LazyCollection.php +++ b/src/Illuminate/Collections/LazyCollection.php @@ -4,11 +4,14 @@ use ArrayIterator; use Closure; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Contracts\Support\Jsonable; use Illuminate\Macroable\Macroable; use IteratorAggregate; +use JsonSerializable; use stdClass; -class LazyCollection implements Enumerable +class LazyCollection implements Arrayable, Enumerable, Jsonable, JsonSerializable { use EnumeratesValues, Macroable;