Skip to content

Commit 55af5d6

Browse files
authored
[5.x] Add ability to get raw array directly from Values object (#13318)
1 parent 716125d commit 55af5d6

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Fields/Values.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public function raw($key)
7979
return $value instanceof Value ? $value->raw() : $value;
8080
}
8181

82+
public function toRawArray(): array
83+
{
84+
return
85+
$this->getIterator()
86+
->mapWithKeys(fn ($value, $key) => [$key => $value instanceof Value ? $value->raw() : $value])
87+
->toArray();
88+
}
89+
8290
public function __isset($key)
8391
{
8492
return $this->offsetExists($key);

tests/Fields/ValuesTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ public function raw_values()
186186
$this->assertNull($values->raw('missing'));
187187
}
188188

189+
#[Test]
190+
public function to_raw_array()
191+
{
192+
$values = new Values([
193+
'alfa' => 'bravo',
194+
'charlie' => $value = new Value('delta', null, $this->fieldtype),
195+
]);
196+
197+
$this->assertEquals([
198+
'alfa' => 'bravo',
199+
'charlie' => 'delta',
200+
], $values->toRawArray());
201+
}
202+
189203
#[Test]
190204
#[DataProvider('queryBuilderProvider')]
191205
public function it_gets_a_query($builder)

0 commit comments

Comments
 (0)