Skip to content

Commit

Permalink
Optimize Router::fullBaseUrl().
Browse files Browse the repository at this point in the history
With this change setting App.fullBaseUrl after Router::fullBaseUrl()
is called will have no effect.
  • Loading branch information
ADmad committed Sep 23, 2019
1 parent f6d6522 commit 534fa6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,18 @@ public static function routeExists($url = null, bool $full = false): bool
*/
public static function fullBaseUrl(?string $base = null): string
{
if ($base === null && static::$_fullBaseUrl !== null) {
return static::$_fullBaseUrl;
}

if ($base !== null) {
static::$_fullBaseUrl = $base;
Configure::write('App.fullBaseUrl', $base);
}
if (!static::$_fullBaseUrl) {
} else {
static::$_fullBaseUrl = Configure::read('App.fullBaseUrl');
}

return (string)static::$_fullBaseUrl;
return static::$_fullBaseUrl;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase/Routing/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function setUp(): void
{
parent::setUp();
Configure::write('Routing', ['admin' => null, 'prefixes' => []]);
Router::fullBaseUrl('');
Configure::write('App.fullBaseUrl', 'http://localhost');
Router::reload();
}

/**
Expand All @@ -53,7 +52,6 @@ public function tearDown(): void
{
parent::tearDown();
$this->clearPlugins();
Router::reload();
Router::defaultRouteClass('Cake\Routing\Route\Route');
}

Expand Down

0 comments on commit 534fa6d

Please sign in to comment.