Skip to content

Commit 7298326

Browse files
authored
Add ordered option to ArrayMerge (#1048)
1 parent 65462d9 commit 7298326

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
- Enh #1031: Optimize SQL generation for `Not` condition (@vjik)
137137
- Chg #1037: Change result type of `QueryBuilderInterface::getExpressionBuilder()` and
138138
`DQLQueryBuilderInterface::getExpressionBuilder()` methods to `ExpressionBuilderInterface` (@vjik)
139-
- New #1029: Add functions as expressions (@Tigrov)
139+
- New #1029, #1048: Add functions as expressions (@Tigrov)
140140
- Enh #1042: Refactor `AbstractDMLQueryBuilder` class to `upsert()` method (@Tigrov)
141141
- New #1040, #1043: Add `DateTimeValue` class (@vjik, @Tigrov)
142142

src/Expression/Function/ArrayMerge.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@
2323
*/
2424
final class ArrayMerge extends MultiOperandFunction
2525
{
26+
private bool $ordered = false;
2627
private string|ColumnInterface $type = '';
2728

29+
/**
30+
* Returns whether the result array should be ordered.
31+
*/
32+
public function getOrdered(): bool
33+
{
34+
return $this->ordered;
35+
}
36+
2837
/**
2938
* Returns the type of the operands. Empty string if not set.
3039
*/
@@ -33,6 +42,15 @@ public function getType(): string|ColumnInterface
3342
return $this->type;
3443
}
3544

45+
/**
46+
* Sets whether the result array should be ordered.
47+
*/
48+
public function ordered(bool $ordered = true): self
49+
{
50+
$this->ordered = $ordered;
51+
return $this;
52+
}
53+
3654
/**
3755
* Sets the type of the operands.
3856
*/

tests/Db/Expression/Function/ArrayMergeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ public function testType(): void
2525
$this->assertSame($expression, $expression->type($intColumn));
2626
$this->assertSame($intColumn, $expression->getType());
2727
}
28+
29+
public function testOrdered(): void
30+
{
31+
$expression = new ArrayMerge();
32+
33+
$this->assertFalse($expression->getOrdered());
34+
$this->assertSame($expression, $expression->ordered());
35+
$this->assertTrue($expression->getOrdered());
36+
$this->assertSame($expression, $expression->ordered(false));
37+
$this->assertFalse($expression->getOrdered());
38+
}
2839
}

0 commit comments

Comments
 (0)