Skip to content

Commit 36c3966

Browse files
committed
Merge branch '8.x' into 9.x
2 parents 93e5ea6 + 277d590 commit 36c3966

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,7 @@ public function cursorPaginate($perPage = null, $columns = ['*'], $cursorName =
872872
*/
873873
protected function ensureOrderForCursorPagination($shouldReverse = false)
874874
{
875-
$orders = collect($this->query->orders);
876-
877-
if ($orders->count() === 0) {
875+
if (empty($this->query->orders) && empty($this->query->unionOrders)) {
878876
$this->enforceOrderBy();
879877
}
880878

@@ -886,6 +884,10 @@ protected function ensureOrderForCursorPagination($shouldReverse = false)
886884
})->toArray();
887885
}
888886

887+
if ($this->query->unionOrders) {
888+
return collect($this->query->unionOrders);
889+
}
890+
889891
return collect($this->query->orders);
890892
}
891893

src/Illuminate/Support/Str.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,18 @@ public static function substrReplace($string, $replace, $offset = 0, $length = n
922922
return substr_replace($string, $replace, $offset, $length);
923923
}
924924

925+
/**
926+
* Swap multiple keywords in a string with other keywords.
927+
*
928+
* @param array $map
929+
* @param string $subject
930+
* @return string
931+
*/
932+
public static function swap(array $map, $subject)
933+
{
934+
return strtr($subject, $map);
935+
}
936+
925937
/**
926938
* Make a string's first character uppercase.
927939
*

src/Illuminate/Support/Stringable.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,24 @@ public function substrCount($needle, $offset = null, $length = null)
726726
* @param string|array $replace
727727
* @param array|int $offset
728728
* @param array|int|null $length
729-
* @return string|array
729+
* @return static
730730
*/
731731
public function substrReplace($replace, $offset = 0, $length = null)
732732
{
733733
return new static(Str::substrReplace($this->value, $replace, $offset, $length));
734734
}
735735

736+
/**
737+
* Swap multiple keywords in a string with other keywords.
738+
*
739+
* @param array $map
740+
* @return static
741+
*/
742+
public function swap(array $map)
743+
{
744+
return new static(strtr($this->value, $map));
745+
}
746+
736747
/**
737748
* Trim the string of the given characters.
738749
*

tests/Integration/Database/EloquentCursorPaginateTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ public function testCursorPaginationOnTopOfColumns()
3636
$this->assertCount(15, TestPost::cursorPaginate(15, ['id', 'title']));
3737
}
3838

39+
public function testPaginationWithUnion()
40+
{
41+
TestPost::create(['title' => 'Hello world', 'user_id' => 1]);
42+
TestPost::create(['title' => 'Goodbye world', 'user_id' => 2]);
43+
TestPost::create(['title' => 'Howdy', 'user_id' => 3]);
44+
TestPost::create(['title' => '4th', 'user_id' => 4]);
45+
46+
$table1 = TestPost::query()->whereIn('user_id', [1, 2]);
47+
$table2 = TestPost::query()->whereIn('user_id', [3, 4]);
48+
49+
$result = $table1->unionAll($table2)
50+
->orderBy('user_id', 'desc')
51+
->cursorPaginate(1);
52+
53+
self::assertSame(['user_id'], $result->getOptions()['parameters']);
54+
}
55+
3956
public function testPaginationWithDistinct()
4057
{
4158
for ($i = 1; $i <= 3; $i++) {

tests/Support/SupportStrTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,24 @@ public function testPadRight()
621621
$this->assertSame('Alien ', Str::padRight('Alien', 10));
622622
}
623623

624+
public function testSwapKeywords(): void
625+
{
626+
$this->assertSame(
627+
'PHP 8 is fantastic',
628+
Str::swap([
629+
'PHP' => 'PHP 8',
630+
'awesome' => 'fantastic',
631+
], 'PHP is awesome')
632+
);
633+
634+
$this->assertSame(
635+
'foo bar baz',
636+
Str::swap([
637+
'ⓐⓑ' => 'baz',
638+
], 'foo bar ⓐⓑ')
639+
);
640+
}
641+
624642
public function testWordCount()
625643
{
626644
$this->assertEquals(2, Str::wordCount('Hello, world!'));

tests/Support/SupportStringableTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,14 @@ public function testSubstr()
795795
$this->assertSame('', (string) $this->stringable('Б')->substr(2));
796796
}
797797

798+
public function testSwap()
799+
{
800+
$this->assertSame('PHP 8 is fantastic', (string) $this->stringable('PHP is awesome')->swap([
801+
'PHP' => 'PHP 8',
802+
'awesome' => 'fantastic',
803+
]));
804+
}
805+
798806
public function testSubstrCount()
799807
{
800808
$this->assertSame(3, $this->stringable('laravelPHPFramework')->substrCount('a'));

0 commit comments

Comments
 (0)