22
33namespace Dreamonkey \CloudFrontUrlSigner ;
44
5- use Aws \CloudFront \CloudFrontClient ;
65use DateTime ;
76use Dreamonkey \CloudFrontUrlSigner \Exceptions \InvalidExpiration ;
8- use Dreamonkey \CloudFrontUrlSigner \Exceptions \InvalidKeyPairId ;
9- use Dreamonkey \CloudFrontUrlSigner \Exceptions \InvalidPrivateKeyPath ;
107use League \Uri \Http ;
118
129class CloudFrontUrlSigner implements UrlSigner
1310{
1411 /**
1512 * CloudFront client object.
1613 *
17- * @var \Aws\CloudFront\CloudFrontClient
14+ * @var \Aws\CloudFront\UrlSigner
1815 */
19- private $ cloudFrontClient ;
16+ private $ urlSigner ;
2017
2118 /**
22- * Path where to find the private key of the trusted signer.
23- *
24- * @var string
19+ * @param \Aws\CloudFront\UrlSigner $urlSigner
2520 */
26- private $ privateKeyPath ;
27-
28- /**
29- * Identifier of the CloudFront Key Pair associated to the trusted signer.
30- *
31- * @var string
32- */
33- private $ keyPairId ;
34-
35- /**
36- * @param \Aws\CloudFront\CloudFrontClient $cloudFrontClient
37- * @param string $privateKeyPath
38- * @param string $keyPairId
39- *
40- * @throws \Dreamonkey\CloudFrontUrlSigner\Exceptions\InvalidPrivateKeyPath
41- * @throws \Dreamonkey\CloudFrontUrlSigner\Exceptions\InvalidKeyPairId
42- */
43- public function __construct (CloudFrontClient $ cloudFrontClient , string $ privateKeyPath , string $ keyPairId )
21+ public function __construct (\Aws \CloudFront \UrlSigner $ urlSigner )
4422 {
45- if ($ privateKeyPath == '' ) {
46- throw new InvalidPrivateKeyPath ('Private key path cannot be empty ' );
47- }
48-
49- if ($ keyPairId == '' ) {
50- throw new InvalidKeyPairId ('Key pair id cannot be empty ' );
51- }
52-
53- $ this ->cloudFrontClient = $ cloudFrontClient ;
54- $ this ->privateKeyPath = $ privateKeyPath ;
55- $ this ->keyPairId = $ keyPairId ;
23+ $ this ->urlSigner = $ urlSigner ;
5624 }
5725
5826 /**
@@ -71,12 +39,7 @@ public function sign(string $url, $expiration = null): string
7139 $ expiration = $ this ->getExpirationTimestamp ($ expiration ??
7240 config ('cloudfront-url-signer.default_expiration_time_in_days ' ));
7341
74- return $ this ->cloudFrontClient ->getSignedUrl ([
75- 'url ' => $ resourceKey ,
76- 'expires ' => $ expiration ,
77- 'private_key ' => $ this ->privateKeyPath ,
78- 'key_pair_id ' => $ this ->keyPairId ,
79- ]);
42+ return $ this ->urlSigner ->getSignedUrl ($ resourceKey , $ expiration );
8043 }
8144
8245 /**
0 commit comments