Skip to content

Commit d8dff6d

Browse files
Make Illuminate\Support\Uri Macroable (#55260)
* Make Illuminate\Support\Uri Macroable * Simplify test * update test --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 6a08dbd commit d8dff6d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Illuminate/Support/Uri.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Http\RedirectResponse;
1010
use Illuminate\Support\Traits\Conditionable;
1111
use Illuminate\Support\Traits\Dumpable;
12+
use Illuminate\Support\Traits\Macroable;
1213
use Illuminate\Support\Traits\Tappable;
1314
use League\Uri\Contracts\UriInterface;
1415
use League\Uri\Uri as LeagueUri;
@@ -17,7 +18,7 @@
1718

1819
class Uri implements Htmlable, Responsable, Stringable
1920
{
20-
use Conditionable, Dumpable, Tappable;
21+
use Conditionable, Dumpable, Macroable, Tappable;
2122

2223
/**
2324
* The URI instance.

tests/Support/SupportUriTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,15 @@ public function test_path_segments()
220220

221221
$this->assertEquals(3, $uri->pathSegments()->count());
222222
}
223+
224+
public function test_macroable()
225+
{
226+
Uri::macro('myMacro', function () {
227+
return $this->withPath('foobar');
228+
});
229+
230+
$uri = new Uri('https://laravel.com/');
231+
232+
$this->assertSame('https://laravel.com/foobar', (string) $uri->myMacro());
233+
}
223234
}

0 commit comments

Comments
 (0)