Skip to content

Commit

Permalink
Support for Laravel 11, switch to static
Browse files Browse the repository at this point in the history
  • Loading branch information
the-pulli committed Mar 12, 2024
1 parent fc23df0 commit 7fedf2f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"require": {
"php": ">=8.2",
"illuminate/collections": "^10.0"
"illuminate/collections": "^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^8.17",
Expand Down
4 changes: 2 additions & 2 deletions src/Macros/MapToCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class MapToCollection
public function __invoke(): Closure
{
return function (array $ary = [], bool $deep = false): Collection {
$ary = Collection::mapToCollectionFrom($ary, $deep);
$data = Collection::mapToCollectionFrom($this->all(), $deep);
$ary = static::mapToCollectionFrom($ary, $deep);
$data = static::mapToCollectionFrom($this->all(), $deep);

if ($ary->isNotEmpty()) {
return $data->merge([$ary]);
Expand Down
6 changes: 3 additions & 3 deletions src/Macros/MapToCollectionFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public function __invoke(): Closure
return function (array $ary, bool $deep = false): Collection {
$closure = function (&$ary) use ($deep) {
if (is_array($ary)) {
$ary = Collection::mapToCollectionFrom($ary, $deep);
$ary = static::mapToCollectionFrom($ary, $deep);
}

if ($deep && is_object($ary) && method_exists($ary, 'toArray')) {
$ary = Collection::mapToCollectionFrom($ary->toArray(), $deep);
$ary = static::mapToCollectionFrom($ary->toArray(), $deep);
}
};

array_walk($ary, $closure);

return new Collection($ary);
return static::make($ary);
};
}
}
5 changes: 2 additions & 3 deletions src/Macros/RecursiveToArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace Pulli\CollectionMacros\Macros;

use Closure;
use Illuminate\Support\Collection;

class RecursiveToArray
{
public function __invoke(): Closure
{
return function (array $ary = []): array {
return array_merge(
Collection::recursiveToArrayFrom($this->all()),
Collection::recursiveToArrayFrom($ary)
static::recursiveToArrayFrom($this->all()),
static::recursiveToArrayFrom($ary)
);
};
}
Expand Down
5 changes: 2 additions & 3 deletions src/Macros/RecursiveToArrayFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Pulli\CollectionMacros\Macros;

use Closure;
use Illuminate\Support\Collection;

class RecursiveToArrayFrom
{
Expand All @@ -12,11 +11,11 @@ public function __invoke(): Closure
return function (array $ary): array {
$closure = function (&$ary) {
if (is_array($ary)) {
$ary = Collection::recursiveToArrayFrom($ary);
$ary = static::recursiveToArrayFrom($ary);
}

if (is_object($ary) && method_exists($ary, 'toArray')) {
$ary = Collection::recursiveToArrayFrom($ary->toArray());
$ary = static::recursiveToArrayFrom($ary->toArray());
}
};

Expand Down

0 comments on commit 7fedf2f

Please sign in to comment.