Skip to content

Commit dfc747a

Browse files
sifexchrispage1
andauthored
Merge to v3 (#94)
* Updated testing Rolled back on adding an additional constructor to ensure backwards compatibility * Updated README * Attempt at passing tests * feat: update PHPUnit version and add temporary URL generation tests * feat: update PHP versions in workflow configuration * feat: enhance temporary URL generation tests for BunnyCDN adapter * Added pullzone URL to temporaryUrl generation (#93) --------- Co-authored-by: Chris Page <[email protected]>
1 parent 9404f9c commit dfc747a

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/BunnyCDNAdapter.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,14 @@ public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config
582582

583583
// extract elements from our path
584584
$parts = parse_url($path);
585-
$path = $parts['path'];
585+
$path = str_starts_with($parts['path'], '/') ? $path : '/'.$path;
586586

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

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

599599
private function buildSigningKey($path, int $expiration, array $params): string
600600
{
601-
// prefix our path
602-
$path = str_starts_with($path, '/') ? $path : '/'.$path;
603-
604601
// process our query params
605602
$query = implode('&', array_map(fn ($k, $v) => $k.'='.$v, array_keys($params), $params));
606603

tests/TemporaryUrlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function test_temporary_url_throws_exception_if_not_configured()
2525
public function test_it_can_generate_signing_key()
2626
{
2727
$client = new BunnyCDNClient('test', 'test');
28-
$adapter = new BunnyCDNAdapter($client, 'pz-key');
28+
$adapter = new BunnyCDNAdapter($client, 'https://pz-url.co.uk');
2929
$adapter->setTokenAuthKey('test-auth-key');
3030

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

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

0 commit comments

Comments
 (0)