Skip to content

Commit

Permalink
Merge pull request #1058 from hydephp/refactor-hydefront-versioning
Browse files Browse the repository at this point in the history
Add feature to allow custom HydeFront CDN link to be set in config
  • Loading branch information
caendesilva committed Feb 16, 2023
2 parents a5206c5 + 728d95a commit 45ed06e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/framework/src/Framework/Services/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ class AssetService
*/
public string $version = 'v2.0';

protected ?string $hydefrontUrl = null;

public function __construct()
{
if (config('hyde.hydefront_version')) {
$this->version = config('hyde.hydefront_version');
}

if (config('hyde.hydefront_url')) {
$this->hydefrontUrl = config('hyde.hydefront_url');
}
}

public function version(): string
Expand All @@ -38,7 +44,7 @@ public function version(): string

public function constructCdnPath(string $file): string
{
return 'https://cdn.jsdelivr.net/npm/hydefront@'.$this->version().'/dist/'.$file;
return $this->hydefrontUrl ?? 'https://cdn.jsdelivr.net/npm/hydefront@'.$this->version().'/dist/'.$file;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/framework/tests/Feature/AssetServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public function test_cdn_path_constructor_returns_cdn_uri()
$this->assertStringContainsString('styles.css', $path);
}

public function test_can_set_custom_cdn_uri_in_config()
{
config(['hyde.hydefront_url' => 'https://example.com']);
$service = new AssetService();
$this->assertSame('https://example.com', $service->constructCdnPath('styles.css'));
$this->assertSame('https://example.com', $service->cdnLink('styles.css'));
}

public function test_media_link_returns_media_path_with_cache_key()
{
$service = new AssetService();
Expand Down

0 comments on commit 45ed06e

Please sign in to comment.