Skip to content
7 changes: 2 additions & 5 deletions src/BunnyCDNAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,14 @@ public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config

// extract elements from our path
$parts = parse_url($path);
$path = $parts['path'];
$path = str_starts_with($parts['path'], '/') ? $path : '/'.$path;

// extract our query params
parse_str($parts['query'] ?? '', $params);
ksort($params);

// concatenate all of our data
return $path
return $this->pullzone_url.$path
.(str_contains($path, '?') ? '&' : '?')
.'token='.$this->buildSigningKey($path, $expiration, $params)
.'&expires='.$expiration
Expand All @@ -598,9 +598,6 @@ public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config

private function buildSigningKey($path, int $expiration, array $params): string
{
// prefix our path
$path = str_starts_with($path, '/') ? $path : '/'.$path;

// process our query params
$query = implode('&', array_map(fn ($k, $v) => $k.'='.$v, array_keys($params), $params));

Expand Down
4 changes: 2 additions & 2 deletions tests/TemporaryUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function test_temporary_url_throws_exception_if_not_configured()
public function test_it_can_generate_signing_key()
{
$client = new BunnyCDNClient('test', 'test');
$adapter = new BunnyCDNAdapter($client, 'pz-key');
$adapter = new BunnyCDNAdapter($client, 'https://pz-url.co.uk');
$adapter->setTokenAuthKey('test-auth-key');

$expiresAt = new \DateTimeImmutable('+1 hour');
$url = $adapter->temporaryUrl('testing.txt', $expiresAt, new Config());

$this->assertStringContainsString('testing.txt?token=', $url);
$this->assertStringContainsString('https://pz-url.co.uk/testing.txt?token=', $url);
$this->assertStringContainsString('expires='.$expiresAt->getTimestamp(), $url);
}
}