Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Illuminate/Support/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public static function of(UriInterface|Stringable|string $uri = ''): static
return new static($uri);
}

/**
* Get a URI instance of the URL for the current request.
*/
public static function current(): static
{
return new static(call_user_func(static::$urlGeneratorResolver)->current());
}

/**
* Get a URI instance of an absolute URL for the given path.
*/
Expand Down
76 changes: 76 additions & 0 deletions tests/Support/SupportUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

namespace Illuminate\Tests\Support;

use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Support\Uri;
use PHPUnit\Framework\TestCase;

class SupportUriTest extends TestCase
{
public function test_can_build_special_urls()
{
Uri::setUrlGeneratorResolver(fn () => new CustomUrlGeneratorResolver);

$this->assertEquals('https://laravel.com/current', Uri::current()->value());
$this->assertEquals('https://laravel.com/to', Uri::to('')->value());
$this->assertEquals('https://laravel.com/route', Uri::route('')->value());
$this->assertEquals('https://laravel.com/signed-route', Uri::signedRoute('')->value());
$this->assertEquals('https://laravel.com/signed-route', Uri::temporarySignedRoute('', '')->value());
$this->assertEquals('https://laravel.com/action', Uri::action('')->value());
}

public function test_basic_uri_interactions()
{
$uri = Uri::of($originalUri = 'https://laravel.com/docs/installation');
Expand Down Expand Up @@ -232,3 +245,66 @@ public function test_macroable()
$this->assertSame('https://laravel.com/foobar', (string) $uri->myMacro());
}
}

class CustomUrlGeneratorResolver implements UrlGenerator
{
public function current()
{
return 'https://laravel.com/current';
}

public function previous($fallback = false)
{
// TODO: Implement previous() method.
}

public function to($path, $extra = [], $secure = null)
{
return 'https://laravel.com/to';
}

public function secure($path, $parameters = [])
{
// TODO: Implement secure() method.
}

public function asset($path, $secure = null)
{
// TODO: Implement asset() method.
}

public function route($name, $parameters = [], $absolute = true)
{
return 'https://laravel.com/route';
}

public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true)
{
return 'https://laravel.com/signed-route';
}

public function temporarySignedRoute($name, $expiration, $parameters = [], $absolute = true)
{
return 'https://laravel.com/temporary-signed-route';
}

public function query($path, $query = [], $extra = [], $secure = null)
{
// TODO: Implement query() method.
}

public function action($action, $parameters = [], $absolute = true)
{
return 'https://laravel.com/action';
}

public function getRootControllerNamespace()
{
// TODO: Implement getRootControllerNamespace() method.
}

public function setRootControllerNamespace($rootNamespace)
{
// TODO: Implement setRootControllerNamespace() method.
}
}
Loading