Skip to content

Commit f8c53e0

Browse files
committed
Add a simple helper to get an array from an array/Arrayable
1 parent 215ed19 commit f8c53e0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/framework/src/helpers.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function unslash(string $string): string
2828

2929
namespace Hyde {
3030
use Hyde\Foundation\HydeKernel;
31+
use Illuminate\Contracts\Support\Arrayable;
3132

3233
if (! function_exists('\Hyde\hyde')) {
3334
/**
@@ -76,4 +77,11 @@ function trim_slashes(string $string): string
7677
return hyde()->trimSlashes($string);
7778
}
7879
}
80+
81+
if (! function_exists('\Hyde\evaluate_arrayable')) {
82+
function evaluate_arrayable(array|Arrayable $array): array
83+
{
84+
return $array instanceof Arrayable ? $array->toArray() : $array;
85+
}
86+
}
7987
}

packages/framework/tests/Feature/HelpersTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,11 @@ public function test_hyde_trim_slashes_function()
105105
{
106106
$this->assertSame(Hyde::trimSlashes('foo'), \Hyde\trim_slashes('foo'));
107107
}
108+
109+
/** @covers ::\Hyde\evaluate_arrayable */
110+
public function test_hyde_evaluate_arrayable_function()
111+
{
112+
$this->assertSame(['foo'], \Hyde\evaluate_arrayable(['foo']));
113+
$this->assertSame(['foo'], \Hyde\evaluate_arrayable(collect(['foo'])));
114+
}
108115
}

0 commit comments

Comments
 (0)