Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/Sites/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class Site implements Augmentable
protected $handle;
protected $config;
protected $rawConfig;
protected $isDefault;

public function __construct($handle, $config)
public function __construct($handle, $config, $isDefault = false)
{
$this->handle = $handle;
$this->config = $this->resolveAntlers($config);
$this->rawConfig = $config;
$this->isDefault = $isDefault;
}

public function handle()
Expand Down Expand Up @@ -95,6 +97,11 @@ public function relativePath($url)
return $path === '' ? '/' : $path;
}

public function isDefault()
{
return $this->isDefault;
}

public function set($key, $value)
{
$this->config[$key] = $this->resolveAntlersValue($value);
Expand Down
4 changes: 3 additions & 1 deletion src/Sites/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ public function config(): array

protected function hydrateConfig($config): Collection
{
return collect($config)->map(fn ($site, $handle) => new Site($handle, $site));
$defaultSiteHandle = collect($config)->keys()->first();

return collect($config)->map(fn ($site, $handle) => new Site($handle, $site, $handle === $defaultSiteHandle));
}

protected function getNewSites(): Collection
Expand Down
10 changes: 10 additions & 0 deletions tests/Sites/SiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public function gets_lang()
$this->assertEquals('en-US', (new Site('en', ['locale' => 'en-US', 'lang' => 'en-US']))->lang());
}

#[Test]
public function gets_is_default()
{
$withoutDefault = new Site('en', ['locale' => 'en_US']);
$withDefault = new Site('en', ['locale' => 'en_US'], true);

$this->assertFalse($withoutDefault->isDefault());
$this->assertTrue($withDefault->isDefault());
}

#[Test]
public function gets_url_when_given_a_trailing_slash()
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Sites/SitesConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public function it_gets_sites_from_yaml()
$this->assertSame('/', Site::default()->url());
$this->assertSame('en_US', Site::default()->locale());
$this->assertSame('en', Site::default()->lang());
$this->assertTrue(Site::default()->isDefault());

$this->assertSame('french', Site::get('french')->handle());
$this->assertSame('French', Site::get('french')->name());
$this->assertSame('/fr', Site::get('french')->url());
$this->assertSame('fr_FR', Site::get('french')->locale());
$this->assertSame('fr', Site::get('french')->lang());
$this->assertFalse(Site::get('french')->isDefault());
}

#[Test]
Expand All @@ -78,6 +80,7 @@ public function it_gets_default_site_without_yaml()
$this->assertSame('/', Site::default()->url());
$this->assertSame(config('app.locale'), Site::default()->locale());
$this->assertSame(config('app.locale'), Site::default()->lang());
$this->assertTrue(Site::default()->isDefault());
}

#[Test]
Expand Down
Loading